<template>
<div>
    <common @asynCallBack="asynCallBack" ></common>

    <header class="mui-bar mui-bar-nav" >
        <h1 class="mui-title">拜访申请记录</h1>
    </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"  >
                            <div>{{item.unit}}</div>
                        </li>
                        <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.visitDate}}</span>
                        </li>
						<li class="mui-table-view-cell"  >
							<label>拜访事由：</label>
							<span>{{item.visitReasons}}</span>
						</li>


					</ul>

				</div>

			</template>


		</div>
	<NullList :remark="'暂无拜访记录'" v-if="!recordList.length&&openId"></NullList>
    <NullList :remark="'请使用微信扫描二维码'" v-if="!recordList.length&&!openId"></NullList>

	<div class="fyy-footer" v-if="id&&openId">
			<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_Current from '@/apis/Guest/current'
	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,
                id:this.$route.query.id,
				listForm: {
					pageIndex: 1,
					pageSize: 20,
					//	token: '',
					totalPage: 1,
					result: 0,
				},
				recordList: [],
                status: ['待确认', '已通过', '待审核','已过期','未通过'],
                statusColor: ['colorf8b155', 'color55f868','colorf8b155','color999', 'colorfe616c'],routeName: "Master",
			}
		},
		created() {

		},
		methods: {
			//info

			detail(mod) {
 				 this.$router.push({
					name: "GuestCurrentInfo",
					query: {
                        currentId: mod.id,
					}
				})
			},
			save() {
			    if(this.id){
                    this.$router.push({
                        name: 'GuestCurrentInfo',
                        query: {
                            id:this.id
                        }
                    })
                }else{
                    mui.toast("请通过扫描园区二维码，进行访客登记");
                }

			},
			//获取列表
			getList() {

                this.listForm.openId=this.openId;
                API_Current.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() {
                if(!this.openId){
                    this.isLoading = false;
                    mui.toast("请使用微信扫描二维码，关注公众号【小鹏管家】")
                }else if(!this.id){
                    this.isLoading = false;
                    mui.toast("请通过扫描二维码访问本页面")
                }else{
                    this.getList();
                }

			},
		},
		mounted() {
            this.isLoading = true;
			//监控下拉加载事件
			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>