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

		<div class="mui-content fyy-date">
			<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>
			<div class="fyydate-out">
				<div class="fyydate-name">
					<div v-for="(item,index) in recordList" class="fyydate-name-list">
						<h5>{{item.name}}</h5>
					</div>
				</div>
				<div class="fyydate-temper">
					<div v-for="(item,index) in recordList" class="fyydate-temper-list">
						<div v-for="(iten,index) in item.list" class="fyydate-temper-num">
							<span>{{iten.recordTime}}</span>
							<span :class="(iten.temperature<=37) ? 'color05c8af':'colorfe616c'">{{iten.temperature}}</span>
						</div>
					</div>
				</div>
			</div>
		</div>

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

<script>
	require('$project/assets/js/mui.picker.min.js');
	import * as API_Health from '@/apis/Master/health'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import isReachBottom from '$project/utils/isReachBottom'
	import TopHeader from '$project/components/TopHeader.vue'
	import NullList from '$project/components/NullList.vue'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	import {
		currentTimeStamp,
		parseUnixTime
	} from '$project/utils'
	export default {
		name: 'MasterHealthAbnormalRecord',
		components: {
			Common,
			Loading,
			TopHeader,NullList
		},
		data() {
			return {
				pageTitle: '异常记录',

				isLoading: false,

				rightLink: {
					show: true,
					icon: 'icon-ziyuan',
					style: 'font-size:14px;color:#000;',
					title: '未测人员'
				},

				listForm: {
					pageIndex: 1,
					pageSize: 20,
					queryDate: '',
					companyId: '',
					totalPage: 1,
					filter: 1
				},
				recordList: [],
			}
		},
		created() {
			if (this.$route.query.queryDate) {
				this.listForm.queryDate = this.$route.query.queryDate;
			} else {
				this.listForm.queryDate = parseUnixTime(currentTimeStamp(), '{y}-{m}-{d}');
			}
		},
		methods: {
			//获取列表
			getList() {
				this.isLoading = true;
				API_Health.getTemperatureList(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;
					}
				}
			},
			//选择日期
			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();
				});
			},
			doRightLink() {
				this.$router.push({
					name: 'MasterHealthNoTemperatureRecord',
					query: {}
				})
			},
			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/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>
