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

		<div class="mui-content">
			<div class="mui-content-padded">
				<ul class="mui-table-view openfyy-list">
					<li v-for="(item,index) in recordList" @click="goToPage(item.id)" class="mui-table-view-cell mui-media flew-sp">
						<div class="mui-h4">
							<span v-text="item.recordTime"></span>
							<!-- <button>设备测温</button> -->
						</div>
						<span class="mui-navigate-right">
							<p class="color05c8af">
								{{item.fever?'异常':'正常'}}
								<!-- <span v-text="item.temperature"></span> -->
							</p>
						</span>
					</li>
				</ul>
			</div>
		</div>

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

<script>
	import * as API_Health from '@/apis/Common/health'
	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 {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'CommonHealthTemperatureRecord',
		components: {
			Common,
			Loading,
			TopHeader
		},
		data() {
			return {
				pageTitle: '测温记录',

				isLoading: false,

				rightLink: {
					show: true,
					icon: 'icon-baojing',
					style: 'font-size:14px',
					title: '异常记录'
				},

				recordList: [],

				listForm: {
					pageIndex: 1,
					pageSize: 20,
					token: '',
					fever: '',
					totalPage: 1
				},
			}
		},
		created() {

		},
		methods: {
			goToPage(id) {
				this.$router.push({
					name: 'CommonHealthTemperatureInfo',
					query: {
						id: id
					}
				})
			},
			//获取列表
			getList() {
				this.isLoading = true;
				API_Health.getRecordList(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;
					}
				}
			},
			//右上角点击事件
			doRightLink() {
				this.listForm.pageIndex = 1;
				this.listForm.fever = this.listForm.fever == 1 ? '' : 1;
				this.getList();
			},
			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',
				company_data: 'company_data',
			})
		},
		watch: {
			'listForm.fever': function(newValue, oldValue) {
				if (newValue == 1) {
					this.rightLink.title = '全部记录';
				} else {
					this.rightLink.title = '异常记录';
				}
			}
		}
	}
</script>

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