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

		<div class="mui-content vongi-zctj">
			<div class="vongi-bagfff">
				<div class="vongi-xzdw-search">
					<input v-model="listForm.name" @keyup.enter="reloadSearchList" type="search" placeholder="搜索姓名或编号">
					<span class="mui-icon mui-icon-search"></span>
				</div>
			</div>
			<div id="slider" class="mui-slider mui-fullscreen vongi-ygjkma">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a v-for="(item,index) in statList" :style="'color:'+getGreenCodeColor(item.healthyCode)" @click="reloadStatusList(item.healthyCode)"
						 :class="'mui-control-item '+(listForm.healthyCode==item.healthyCode?'mui-active':'')">
							{{getCodeStatusName(item.healthyCode)}}<span class="mui-badge" v-text="item.total"></span>
						</a>
					</div>
				</div>
				<div class="mui-slider-group">
					<div class="mui-slider-item mui-control-content">
						<div class="mui-scroll-wrapper">
							<div class="mui-scroll vongi-archives">
								<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"><img :src="item.faceImageUrl+'?x-oss-process=image/resize,h_50,m_lfit'"></div> {{item.name}}
											</div>
											<span class="mui-pull-right" :style="'color:'+getGreenCodeColor(item.healthyCode)">{{getCodeStatusName(item.healthyCode)}}<i
												 class="iconfont icon-erweima1"></i></span>
										</router-link>
									</li>
								</ul>
							</div>
						</div>
					</div>

				</div>
			</div>

		</div>

		<loading :visible="isLoading"></loading>
	</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: 'MasterHealthCodeList',
		components: {
			Common,
			Loading,
			TopHeader
		},
		data() {
			return {
				pageTitle: '员工健康码明细',

				isLoading: false,

				listForm: {
					healthyCode: this.$route.query.healthyCode ? this.$route.query.healthyCode : '00',
					pageIndex: 1,
					pageSize: 20,
					totalPage: 1,
					name: '',
				},
				recordList: [],

				statList: [],
			}
		},
		created() {},
		methods: {
			reloadSearchList() {
				this.listForm.pageIndex = 1;
				this.getList();
			},
			reloadStatusList(status) {
				this.listForm.healthyCode = status;
				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;

					this.getList();
				}).catch(error => {
					this.isLoading = false;
					this.mui.toast(error);
				})
			},
			//获取列表
			getList() {
				this.isLoading = true;
				API_Health.healthyCodeStatList(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();
			//监控下拉加载事件
			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/xpwyfyy.css"></style>
<style src="$project/assets/css/iconfont.css"></style>
<style>
</style>
