<template>
	<div>
		<common @asynCallBack="asynCallBack"></common>
		<top-header :pageTitle="pageTitle"    ></top-header>

		<div class="mui-content vongi-fklist">

			<div class="mui-content-padded fyy-date mui-clearfix">
				<h5>{{person_data.companyName}}
					<a class="mui-navigate-right mui-pull-right" @click="selectData">{{listForm.queryDate}}</a>
				</h5>
			</div>

			<NullList :remark="'暂无访客记录'" v-if="!recordList.length"></NullList>
			<ul class="mui-table-view openfyy-list" v-if="recordList.length">
				<li class="mui-table-view-cell mui-media" v-for="mod in recordList" >
					<a   class="mui-navigate-right" @click="goto(mod.id)">
						{{mod.unit}}
					</a>
					<div class="mui-ellipsis">
						来访人员：{{mod.name}}
 					</div>
					<div class="mui-ellipsis">

					访问时间：{{sub(mod.comeInTime)}}-{{sub(mod.outTime)}}
					</div>
					<p class="mui-ellipsis">
						同行人员：{{mod.num}}
						<span>总计耗时：{{gethour(mod.comeInTime,mod.outTime)}}</span>
					</p>
				</li>

			</ul>
		</div>
		<loading :visible="isLoading"></loading>

	</div>
</template>


<script>
	import * as API_Guest from '@/apis/Master/guest'
	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 {
		hourDistance,
		currentTimeStamp,
		parseUnixTime
	} from '$project/utils'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'MasterGuestList',
		components: {
			Common,
			Loading,
			TopHeader,NullList
		},
		data() {
			return {
				pageTitle: '访客记录',

				isLoading: false,

				listForm: {
					pageIndex: 1,
					pageSize: 20,
					//	token: '',
					//isToDay:1,//是否只查今天
					queryDate:'',
					totalPage: 1,
					result: 0,
				},
				recordList: [],
				status: ['待确认', '已确认', '已拒绝','已过期'],
				statusColor: ['colorf8b155', 'color55f868', 'colorfe616c','color999'],

			}
		},
		created() {
			this.listForm.queryDate = parseUnixTime(currentTimeStamp(), '{y}-{m}-{d}');
		},
		methods: {
			//选择日期
			selectData() {
				var _this = this;
				var picker = new mui.DtPicker({
					"type": "date",
					"beginYear": 2020,
					"endYear": 2040,
					"endDate": new Date(),
					"value": _this.listForm.queryDate
				});
				picker.show(function(rs) {
					_this.listForm.queryDate = rs.text;
					_this.listForm.pageIndex = 1;
					_this.getList();
					picker.dispose();
				});
			},
			gethour(t1,t2){
				return hourDistance(t1,t2)
			},
			sub(time){
				if(time==null){
					return  '';
				}
				return  String(time).substring(11);
			},
			//info
			goto(id) {

				this.$router.push({
					name: 'MasterGuestInfo',
					query: {
						id: id
					}
				})
			},

			//获取列表
			getList() {
				this.isLoading = true;
				API_Guest.accessRecords(this.listForm).then(res => {
					var response=res.list;
					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',
				person_data: 'person_data',
				person_popedom: 'person_popedom',
			})
		},

	}
</script>

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