<template>
	<div class="review">
		<headNav
		@backPage="backPage"
		:title="'复查'"></headNav>
		
		<!-- 责令改正项目 -->
		<div class="danger">
			<div class="headTip FontColorInfo df jfsb">
				<div>
					责令改正项目
				</div>
				<div class="fz12">
					待复查
					<span class="FontColorWarn fb">{{ resultList.length }}</span>
					项
				</div>
			</div>
			
			<div class="dangerList" v-for="item in resultList">
				<div v-if="item.index === 1" class="index color1">
					1
				</div>
				<div v-else-if="item.index === 2" class="index color2">
					2
				</div>
				<div v-else class="index color3">
					{{ item.index }}
				</div>
				<div class="flex1">
					<div class="dangerIistItem">
						<van-cell :title="item.examineProname" is-link @click="gotoCheckDetail(item)"></van-cell>
					</div>
					<div class="dangerContent">
						<div class="df mb10">
							<div class="flex1">
								历史隐患：
								<span v-if="item.isDanger" class="FontColorError">有</span>
								<span v-else class="FontColorOther">无</span>
							</div>
							<div class="flex1 OPoint">
								检查类型：
								<span v-if="item.examineType === '1'">消防许可及验收备案</span>
								<span v-else-if="item.examineType === '2'">消防安全管理</span>
								<span v-else-if="item.examineType === '3'">建筑防火</span>
								<span v-else-if="item.examineType === '4'">安全疏散</span>
								<span v-else>消防控制室</span>
							</div>
						</div>
						<div class="df mb10">
							<div class="flex1">
								复查情况：
								<span class="FontColorInfo">未复查</span>
							</div>
							<div class="flex1 OPoint">
								检查时间：
								<span>{{ item.createdTime }}</span>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<div class="startBtn">
			<div class="startBtn_container">
				<van-button type="info" @click="reviewComplete">
					完成复查
				</van-button>
			</div>
		</div>
		
		<!-- 遮罩层 -->
		<v-mask :showOverLay="showOverLay" :tipMsg="tipMsg"></v-mask>
	</div>
</template>

<script>
	import headNav from '@/components/headNav.vue'
	import { get, post } from '@/utils/http.js'
	import mask_overLay from '@/components/overLay_xy.vue'
	
	export default {
		name: 'review',
		components: {
			headNav,
			'v-mask': mask_overLay
		},
		data() {
			return {
				resultList: '',
				isStart: false,
				showOverLay: false,
				tipMsg: '加载中',
				totalNum: 0,
			}
		},
		mounted() {
			this.init();
		},
		methods: {
			// 初始化
			async init() {
				this.showOverLay = true;
				this.tipMsg = '加载中';
				await this.getPageListApi();
				this.showOverLay = false;
				
				// vuex
				this.$store.commit('review/setTotalNum', this.totalNum);
				this.$store.commit('review/setList', this.resultList);
				this.$store.commit('review/resetCheckList');
				this.$store.commit('review/resetCheckNum');
			},
			
			// 获取列表 信息
			async getPageListApi() {
				this.resultList = [];
				await get(`/cdsupervisionAnswer/needResCheck/${this.$route.params.taskId}`)
				.then(res => {
					if (res.success) {
						this.totalNum = res.data.defectNum;
						let num = 0;
						res.data.defectList.forEach(item => {
							if (item) {
								num ++;
								item.index = num;
								this.resultList.push(item);
							}
						});
					}
				});
			},
			
			backPage() {
				this.$router.go(-1);
			},
			
			// 打开检查详情
			gotoCheckDetail(item) {
				this.$router.push(`/dangerDetail/${ item.id }/${this.$route.params.taskId}/${ item.index }/review`);
			},
			
			// 完成复查
			reviewComplete() {
				const completeList = this.$store.state.review.hasCheckedList;
				if (completeList.length < this.resultList.length) {
					this.$toast.fail('还未完成全部复查项');
				} else {
					this.showOverLay = true;
					this.tipMsg = '提交中';
					const hasCheckedList = this.$store.state.review.hasCheckedList;
					this.$router.push(`/reviewRecord/${ this.$route.params.ID }/${ this.$route.params.taskId }`);
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	.review  {
		font-size: 14px;
		
		.color1 {
			color: #02A7F0;
		}
		
		.color2 {
			color: #D9001B;
		}
		
		.color3 {
			color: #7F7F7F;
		}
		
		.headTip {
			margin-bottom: 10px;
			padding: 0 15px;
		}
		
		.danger {
			margin-top: 57px;
			padding: 0 10px;
			height: calc(100vh - 130px);
			overflow: hidden;
			overflow-y: auto;
		}
		
		.dangerList {
			display: flex;
			background-color: #fff;
			justify-content: space-between;
			border-bottom: 1px solid #c7c9cb;
			
			.index {
				width: 40px;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 16px;
				font-weight: bold;
			}
		
			.dangerContent {
				display: flex;
				flex-direction: column;
				padding: 0px 15px;
				font-size: 12px;
				color: #8f9091;
				padding-left: 0;
			}
		}
		
		.startBtn {
			position: fixed;
			width: 100%;
			bottom: 0;
			display: flex;
			justify-content: center;
			padding: 20px 0;
			
			.startBtn_container {
				width: 100%;
				margin: 0 15px;
			}
			
			.hasStartBtn_container {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				margin: 0 15px;
				
				button {
					flex: 1;
				}
			}
			
			button {
				width: 100%;
				height: 40px;
			}
		}
	}
</style>

<style lang="scss">
	.review {
		.van-cell {
			padding: 8px 0;
			border-bottom: 1px solid #cfcfcf;
			font-size: 12px;
			
			&:last-child {
				border-bottom: none;
			}
			
			.van-cell__title {
				color: #565656;
			}
		}
		
		.van-cell.van-cell--clickable {
			padding-right: 15px;
		}
		
		.startBtn {
			
			.stopCheckBtn.van-button.van-button--info.van-button--normal {
				background-color: #9e9e9e;
				border: none;
				margin-left: 10px;
			}
		}
	}
</style>
