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

		<div class="mui-content vongi-fklist">
			<div class="vongi-clasadmin">
				<h4>{{person_popedom.companyName}}</h4>
				<div class="vongi-clasadmin-list">
					<div class="vongi-clasadmin-ma mui-col-xs-6">
						<p class="mui-ellipsis">{{nowTime()}}</p>
						<span class="color05c8af">{{num.num1}}</span>
						<div class="mui-media-body">总预约数</div>
					</div>
					<div class="vongi-clasadmin-ma mui-col-xs-6">
						<p class="mui-ellipsis">企业今日出入情况</p>
						<span class="color05c8af">{{num.num2}}/{{num.num3}}</span>
						<div class="mui-media-body">进厂数 / 出厂数</div>
					</div>
				</div>
				<div class="vongi-btn">
					<button class="mui-btn mui-btn-primary" @click="scan">
						扫码核验<span class="iconfont icon-saoyisao"></span>
					</button>
				</div>
			</div>
			<div class="vongi-smhy-list">
				<div class="vongi-smhy-tit">访客出入记录</div>
				<ul class="mui-table-view mui-content-padded">

					<li class="mui-table-view-cell mui-media" v-for="mod in list">
						<a  class="mui-navigate-right" @click="goto(mod.id)">
							{{mod.unit}}
						</a>
						<div class="mui-ellipsis flew-sp">
							来访人员：{{mod.name}}
							<span>进厂时间：{{sub(mod.comeInTime)}}</span>
						</div>
						<div class="mui-ellipsis flew-sp">
							同行人员：{{mod.num}}
							<span>出厂时间：{{sub(mod.outTime)}}</span>
						</div>
					</li>
					<li class="mui-table-view-cell mui-media" @click="goList()">
						<a class="vongi-smhy-more">查看全部记录</a>
					</li>
				</ul>				
			</div>			
		</div>
	<loading :visible="isLoading"></loading>

</div>
</template>


<script>
	import * as API_Guest from '@/apis/Master/guest'
	import * as WxJsApi from '$project/utils/wxJsApi'

	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	import {
		currentTimeStamp,
		parseUnixTime
	} from '$project/utils'
	import wx from "weixin-js-sdk";
	export default {
		name: 'MasterGuestScan',
		components: {
			Common,
			Loading,
			TopHeader,

		},
		data() {
			return {
				pageTitle: '扫码核验',
				listForm: {
					pageIndex: 1,
					pageSize: 3,
					//	token: ''
					queryDate:'',
					isToDay:1,//是否只查今天
					totalPage: 1,
					result: 0,
				},
				isLoading: false,
				num:{},
				routeName:'Master',
				list:[],
				step:'1'
			}
		},
		created() {
			this.listForm.queryDate = parseUnixTime(currentTimeStamp(), '{y}-{m}-{d}');
		},
		methods: {
			scan(){
				var _this= this;
				wx.scanQRCode({
					needResult: 1,
					scanType: ["qrCode"],
					success: function (res) {
						var url = res.resultStr;
						_this.checkForm(url)
					},faile: function(res) {
						mui.toast("扫码失败");
					},
					complete() {

					}
				})
				//_this.checkForm('http://xpgj.xiaoxinda.com/#/guest/to/info?id=60304478-a8ff-4095-b20b-a66633bd87f7')

			},
			checkForm(url) {
				debugger
				var sz=url.split("#");

				var sz1=sz[1].toLowerCase();
				if(!sz1.indexOf('/guest/to/info?id=')==0){
					mui.toast('非访客二维码');
					return false
				}
				var id=sz1.substring('/guest/to/info?id='.length);
				this.goto(id);
			},
			goList(){
				this.$router.push({
					name: 'MasterGuestGoto',
				})
			},
			goto(id){
				this.$router.push({
					name: 'MasterGuestApproval',
					query: {
						id:id
					}
				})
			},
			sub(time){
				if(time==null){
					return  '-';
				}
				return  String(time).substring(11);
			},
			nowTime(){
				return  parseUnixTime(currentTimeStamp(), '{y}-{m}-{d}');

			},
			asynCallBack() {

			},getList(){
				this.isLoading = true;

				API_Guest.accessRecords(this.listForm).then(response => {
					this.isLoading = false;
					this.list = response.list.data;
					this.num = response.num;

				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
		},
		mounted() {
			//获取微信配置
			this.getList();
			WxJsApi.getWxConfig();
		},
		destroyed() {

		},
		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>
