<template>
	<view class="table-wrap entRiskPointCheck-table">
		<view v-for="(item, index) in dataList.hazardList" :key="item.hazardId" class="hazardList-wrap">
			<view class="hazardList">
				<view class="hazardTitle-wrap">
					<view class="hazardTitle">标题：{{item.hazardTitle}}</view>
					<view class="hazardCode">编号：{{item.hazardCode}}</view> 					
				</view>
				<view class="hazard-cont">
					<view v-for="(item1, riskIndex) in item.riskList" 
					:key="item1.riskId" class="hazardItem"
					:class="(item.riskList.length-1)===riskIndex?'delBorder':''">
						<view class="riskList">
							<view class="hazardHead">
								<view>风险源：{{item1.riskSource}}</view>
								<view>危险因素：{{item1.riskReason}}</view>
								<view>等级：{{item1.riskLevel}}</view>						
							</view>
							<view class="riskItem" 
								v-for="(measure, index) in item1.measureList" 
								:key="measure.measureId"
								@click="check(measure,item)">
								<view>措施分类：{{measure.measureTypeTitle}}</view>
								<view>管控措施：{{measure.measureContent}}</view>
								<text>法律依据：{{measure.measureReference}}</text>
								<text class="risk-desc">描述：{{measure.measureDesc}}</text>
								<template v-if="measure.checkResult===0">
									<text class="status primary">处理</text>
								</template>
								<template v-if="measure.checkResult===1">
									<text class="status success">通过</text>
								</template>
								<template v-if="measure.checkResult===2">
									<text class="status error">不通过</text>
								</template>
								<template v-if="measure.checkResult===3">
									<text class="status warn">有隐患</text>
								</template>
								<text class="zhcx-iconfont zhcx-icon-youbianjiantoujiaoduxiao"></text>
							</view>
						</view>
					</view>					
				</view>
			</view>
		</view>
		<view class="handle-wrap">
			<button class="bottom-button-left" type="primary" @click="AllCheck()">全部通过</button>
			<button class="bottom-button-right" type="primary" @click="FinishCheck()">完成检查</button>			
		</view>
	</view>
</template>

<script>
	import { getCheckList, getCheckTaskView } from '@/api/entRiskPoint.js'
	import {
		verifyCheckTaskDoingIsComplete,
		batchUpdateCheckTaskDoingRecord,
		completeCheckTaskDoingRecord
	} from '@/api/checkRecord.js'
	import { deepClone } from '@/libs/index.js'
	export default {
		data() {
			return {
				dataList: [{ hazardList: [] }],
				queryConditions: {
					checklistId: '',
					riskPointId: ''
				},
			}
		},
		onLoad(options) {
			console.log({
				"检查表":options
			})
			this.queryConditions.taskId = options.taskId
			this.queryConditions.riskPointId = options.riskPointId
			//请求页面数据
			this.getData(options.taskId);
		},
		methods: {
			getData(taskId) {
				getCheckTaskView(taskId).then((resp) => {
					const { code, data, count } = resp
					if (code === 0) {
						console.log("成功")
						this.queryConditions.total = count
						this.dataList = data
					}
				}).catch((error) => {
					console.log(error)
				})
			},

			check(measure,item) {
				//跳转到分级管控检查表页面
				let riskPointId=this.queryConditions.riskPointId;
				let taskId=this.queryConditions.taskId;
				if(!riskPointId){
					uni.showToast({
						title:"riskPointId未找到"
					})
					return;
				}
				if(!taskId){
					uni.showToast({
						title:"taskId未找到"
					})
					return;
				}	
				measure.hazardId=item.hazardId;
				uni.setStorageSync('entRiskPointMeasure',measure)
				uni.reLaunch({
					url: `/views/entRiskPointCheck/checkInfo?taskId=${taskId}&riskPointId=${riskPointId}`
				});
			},
			//全部通过
			AllCheck() {
				batchUpdateCheckTaskDoingRecord(this.queryConditions.taskId).then((res) => {
					const { code, data, conut } = res
					if (code === 0) {
						uni.showToast({
							icon:'none',
							title:'操作成功！'
						})
						this.getData(this.queryConditions.taskId);
					}
				})
			},
			//完成
			FinishCheck() {
				completeCheckTaskDoingRecord(this.queryConditions.taskId).then((res) => {
					const { code, data, conut } = res
					if (code === 0) {
						let riskPointId=this.queryConditions.riskPointId;
						uni.showToast({
							icon:'none',
							title:'完成任务成功！',
							complete() {
								//回跳到检查清单
								// uni.reLaunch({
								//     url: '/views/entRiskPointCheck/index?id=' + riskPointId
								// });	
								//跳转到首页
								uni.reLaunch({
									url:"/pages/index/index",
								})
								// uni.switchTab({
								// 	url:"/pages/index/index",
								// })							
							}
						})					
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.entRiskPointCheck-table{
		// padding:0 20upx;
		// margin-top: 30upx;
		margin-bottom: 150upx;
		.hazardList-wrap{
			.hazardList {
				padding:30upx;
				margin-bottom:30upx;
				background-color: #f5f5f5;
				// border-radius: 10upx;
				box-shadow: 0 0 6upx rgba(0,0,0,0.5);
				.hazardHead{
					background-color:#fff;
					font-weight: 600;
					padding-bottom: 10px;
				}
				.hazardTitle-wrap{
					.hazardTitle{
						font-weight: 600;
						font-size: 34upx;
					}	
					.hazardCode{
						font-weight: 600;
						font-size: 34upx;
						padding-bottom: 15upx;
					}				
				}	
				.hazardItem{
					background-color: #fff;
					margin-top: 28upx;
					border-top: 1px solid #eaeaea;
					padding:10upx 0;
					&.delBorder{
						border-top:none;
					}				
				}	
				.risk-desc{
					margin-left: 16upx;
				}
				.riskList{
					.riskItem{
						border-top: 1px solid #eaeaea;
						position: relative;
						padding: 20upx 0;
						.zhcx-iconfont{
							font-size: 16px;
							position: absolute;
							right: 10upx;
							top: 50%;
							transform: translateY(-50%);
						}
						.status{
							&.primary{
								color: #1aad19;
							}
							&.warn{
								color: #e6a23c;
							}
							&.success{
								color:#0081FF;
							}
							&.error{
								color: red;
							}
						}
					}				
				}					
			}					
		}
		.handle-wrap{
			width: 750upx;
			position: fixed;
			left: 0;
			bottom: 5upx;
			text-align: center;
			.bottom-button-left {
				width: 350upx;
				background-color: #31bc07;
				border-top-right-radius: 0;
				border-bottom-right-radius: 0;
				display: inline-block;
			}
			.bottom-button-right {
				width: 350upx;
				background-color: DodgerBlue;
				border-top-left-radius: 0;
				border-bottom-left-radius:0 ;
				display: inline-block;
			}					
		}								
	}		
</style>
