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

		<div class="mui-content vongi-archives">
			<div class="vongi-clasadmin">
				<h4>健康码统计</h4>
				<div class="vongi-clasadmin-list">
					<div v-for="(item,index) in statList" class="vongi-clasadmin-ma mui-col-xs-3">
						<span class="color55f868" :style="'color:'+getGreenCodeColor(item.healthyCode)" v-text="item.total"> </span>
						<div class="mui-media-body" v-text="getCodeStatusName(item.healthyCode)"></div>
					</div>
				</div>
			</div>
			<ul class="mui-table-view">
				<li v-for="(item,index) in recordList" class="mui-table-view-cell">
					<router-link :to="{name: 'CommonHealthCert',query: {personId: item.id}}" class="mui-navigate-right">
						<div class="mui-pull-left flew-items">
							<div class="mui-media-object flew"><img :src="item.faceImageUrl+'?x-oss-process=image/resize,h_100'" width="50" /></div>
							<h4 v-text="item.name"></h4>
							<span class="mui-icon iconfont icon-erweima1 color55f868" :style="'color: '+getGreenCodeColor(item['healthyCode'])+';line-height: 27px'"></span>
						</div>
						<div class="mui-pull-right color55f868">{{item.lastTemperatureLog==null?'未测温':''}} {{item.lastTemperatureLog}}</div>
					</router-link>
				</li>
			</ul>
		</div>
		<div class="vongi-archives-search mui-btn flew">
			<a :class="listForm.sortType=='1'?'mui-active':''" @click="reSort('1')">按序号排序</a>
			<a :class="listForm.sortType=='2'?'mui-active':''" @click="reSort('2')">按拼音排序</a>
		</div>
	</div>
	</div>
</template>

<script>
	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 {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'MasterHealthArchives',
		components: {
			Common,
			Loading,
			TopHeader
		},
		data() {
			return {
				pageTitle: '健康档案',

				isLoading: false,

				listForm: {
					pageIndex: 1,
					pageSize: 20,
					totalPage: 1,
					sortType: '1'
				},
				recordList: [],

				loadAll: false,

				statList: [],
			}
		},
		created() {},
		methods: {
			//重置排序
			reSort(type) {
				this.listForm.sortType = type;
				this.listForm.pageIndex = 1;
				this.getList();
			},

			//获取健康码颜色值
			getGreenCodeColor(healthyCode) {
				var healthyCode = healthyCode || '11';
				var color = {
					"00": '#09ae47',
					"01": '#e5aa37',
					"10": '#fe616c',
					"11": '#C0C0C0'
				}
				return color[healthyCode];
			},

			//判断状态
			getCodeStatusName(code) {
				if (code == '00') {
					return '绿码';
				} else if (code == '01') {
					return '黄码';
				} else if (code == '10') {
					return '红码';
				} else if (code == '11') {
					return '灰码';
				} else {
					return '无码';
				}
			},
			//获取绿码统计数据
			getHealthyCodeStat() {
				this.isLoading = true;
				API_Health.getHealthyCodeStat(this.person_data.companyId).then(response => {
					this.isLoading = false;
					this.statList = response;
				}).catch(error => {
					this.isLoading = false;
					this.mui.toast(error);
				})
			},
			//获取列表
			getList() {
				this.isLoading = true;
				API_Health.getHealthyPersonList(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;
					}
				}
			},
			asynCallBack() {

			},
		},
		mounted() {
			//获取数量统计
			this.getHealthyCodeStat();
			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 scoped>
	.vongi-archives-search {
		position: fixed;
	}

	.vongi-archives {
		margin-bottom: 60px;
	}
</style>
