<template>
<div>
	<common @asynCallBack="asynCallBack"></common>
	<top-header :pageTitle="pageTitle"  :routeName="routeName" ></top-header>
		<div class="mui-content margin60">
			<template v-for="item in recordList">
				<div class="mui-content-padded" >

					<ul class="mui-table-view fyy-view" @click="detail(item)">
						<li class="mui-table-view-cell" >
							<label>受  邀 人：</label>
							<span>{{item.name}}<span class="mui-pull-right " :class="statusColor[item.status]">{{status[item.status]}}</span></span>
						</li>
						<li class="mui-table-view-cell"  >
							<label>受邀单位：</label>
							<span>{{item.unit}}</span>
						</li>
						<li class="mui-table-view-cell"  >
							<label>邀访事由：</label>
							<span>{{item.visitReasons}}</span>
						</li>
						<li class="mui-table-view-cell"  >
							<label>拜访时间：</label>
							<span>{{item.visitDate}}</span>
						</li>

					</ul>

				</div>

			</template>


		</div>
	<NullList :remark="'您尚未邀请访客来访'" v-if="!recordList.length"></NullList>

	<div class="fyy-footer">
			<div class="bindfyy-btn">
				<button type="button" class="mui-btn mui-btn-primary " @click="save">
						邀请访客
					</button>
			</div>
		</div>
	<loading :visible="isLoading"></loading>

</div>
</template>


<script>
	import * as API_From from '@/apis/Guest/from'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import isReachBottom from '$project/utils/isReachBottom'
	import NullList from '$project/components/NullList.vue'

	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'GuestFromList',
		components: {
			Common,
			Loading,
			TopHeader,NullList
		},
		data() {
			return {
				pageTitle: '访客申请列表',

				isLoading: false,

				listForm: {
					pageIndex: 1,
					pageSize: 20,
					//	token: '',
					totalPage: 1,
					result: 0,
				},
				recordList: [],
				status: ['待确认', '已确认', '已拒绝','已过期'],
				statusColor: ['colorf8b155', 'color55f868', 'colorfe616c','color999'],
				routeName: "Master",
			}
		},
		created() {

		},
		methods: {
			//info

			detail(mod) {
				var name=mod.status==0?'GuestToInfo':"GuestFromInfo"
				 this.$router.push({
					name: name,
					query: {
						id: mod.id,
						share:'1'
					}
				})
			},
			save() {
				this.$router.push({
					name: 'GuestFromAdd',
					query: {

					}
				})
			},
			//获取列表
			getList() {
				this.isLoading = true;
				API_From.pageList(this.listForm).then(response => {
					if (response) {
						if (this.listForm.pageIndex == 1) {
							this.recordList = response.data;
							this.listForm.pageIndex = response.pageNumber;
							this.listForm.totalPage = response.totalPage;
						} else {
							this.recordList = [
								...this.recordList,
								...response.data
							];
						}
					}
					this.listForm.pageIndex++;
					this.isLoading = false;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//下拉事件
			handleScrool() {
				if (isReachBottom()) {
					console.log('到达底部')
					if (this.listForm.pageIndex <= this.listForm.totalPage && this.isLoading == false) {
						this.getList();
					} else {
						return;
					}
				}
			},

			asynCallBack() {

			},
		},
		mounted() {
			this.getList();
			//监控下拉加载事件
			var _this = this;
			window.addEventListener('scroll', _this.handleScrool);
		},
		destroyed() {
			//销毁监听事件
			var _this = this;
			window.removeEventListener('scroll', _this.handleScrool);
		},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
			})
		},

	}
</script>

<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style>
</style>