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

		<div class="mui-content vongi-admin-kqtj">
			<div class="fyy-temper-date">
				<a class="mui-col-xs-6" @click="selectData">{{subForm.queryDate}}<span class="mui-icon iconfont icon-xiajiantou"></span></a>
				<a class="mui-col-xs-6" @click="selectTime">{{timeName}}<span class="mui-icon iconfont icon-xiajiantou"></span></a>
			</div>
			<h6>本时段考勤统计: 已打卡<span class="color55f868" v-text="absentCount"></span>人/缺卡<span class="colorfe616c" v-text="workCount"></span>人</h6>
			<ul class="mui-table-view mui-table-view-chevron">
				<li v-for="(item,index) in recordList" class="mui-table-view-cell mui-collapse vongi-work">
					<a class="mui-navigate-right" v-text="item.companyName"></a>
					<ul class="mui-table-view mui-table-view-chevron">
						<li v-for="(iten,inden) in item.personList" class="mui-table-view-cell" @click="goToInfo(iten)">
							{{iten.name}}
							<div class="mui-media-body">
								<button type="button" class="mui-btn  mui-btn-primary mui-btn-outlined" v-show="iten.remark" v-text="iten.remark"></button>
								<span class="color55f868" v-show="iten.result" v-text="iten.result"></span>
							</div>
						</li>
					</ul>
				</li>
			</ul>
		</div>

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

<script>
	require('$project/assets/js/mui.picker.min.js');
	import * as API_Attendance from '@/apis/Master/attendance'
	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'
	export default {
		name: 'MasterAttendanceStatisticList',
		components: {
			Common,
			Loading,
			TopHeader
		},
		data() {
			return {
				pageTitle: '考勤统计',

				isLoading: false,

				subForm: {
					queryDate: '',
					alarmConfigId: ''
				},
				absentCount: 0,
				workCount: 0,
				recordList: [],
				timeList: [],
				timeName: '',
			}
		},
		created() {
			this.subForm.queryDate = parseUnixTime(currentTimeStamp(), '{y}-{m}-{d}');
		},
		methods: {
			//获取列表
			getList() {
				this.isLoading = true;
				API_Attendance.getAttednance(this.subForm).then(response => {
					this.isLoading = false;

					this.recordList = response.groupList;
					this.absentCount = response.absentCount
					this.workCount = response.workCount

				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//选择日期
			selectData() {
				var _this = this;
				var picker = new mui.DtPicker({
					"type": "date",
					"beginYear": 2020,
					"endYear": 2040,
					"endDate": new Date(),
					"value": _this.subForm.queryDate
				});
				picker.show(function(rs) {
					_this.subForm.queryDate = rs.text;
					//获取时段列表
					_this.getTimeList();
					picker.dispose();
				});
			},
			//获取时段列表
			getTimeList() {
				this.isLoading = true;
				API_Attendance.getAttednanceTimeList(this.subForm).then(response => {
					this.isLoading = false;

					let timeList = [];
					if (response.length > 0) {
						for (var i = 0; i < response.length; i++) {
							timeList.push({
								value: response[i]['alarmConfigId'],
								text: response[i]['timeRange']
							})
						}
						this.subForm.alarmConfigId = timeList[0]['value'];
						this.timeName = timeList[0]['text'];
						this.getList();
					} else {
						this.subForm.alarmConfigId = '';
						this.timeName = '';
					}
					this.timeList = timeList;

				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//选择时间段
			selectTime() {
				var picker = new mui.PopPicker();
				picker.setData(this.timeList);
				var _this = this;
				picker.show(function(selectItems) {
					_this.subForm.alarmConfigId = selectItems[0].value;
					_this.timeName = selectItems[0].text;
					_this.getList();
				})
			},
			//跳转到详情页
			goToInfo(iten) {
				if (iten.type) {
					if (iten.type == '0' && iten.personDeviceLogId) {
						//设备打卡
						this.$router.push({
							name: 'MasterAttendanceTemperatureInfo',
							query: {
								id: iten.personDeviceLogId
							}
						})
					} else if (iten.type == '1' && iten.fillAttendanceId) {
						//异地打卡
						this.$router.push({
							name: 'MasterAttendanceInfo',
							query: {
								id: iten.fillAttendanceId
							}
						})
					} else if (iten.type == '2' && iten.fillAttendanceId) {
						//补卡
						this.$router.push({
							name: 'MasterAttendanceInfo',
							query: {
								id: iten.fillAttendanceId
							}
						})
					}
				}
			},
			asynCallBack() {

			},
		},
		mounted() {
			//获取时段列表
			this.getTimeList();
			//获取列表
			this.getList();
		},
		destroyed() {},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
				person_data: 'person_data',
				person_popedom: 'person_popedom',
			})
		}
	}
</script>

<style scoped src="$project/assets/css/sczpfyy.css"></style>
<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style src="$project/assets/css/iconfont.css"></style>
<style src="$project/assets/css/mui.picker.min.css"></style>
<style scoped>
</style>
