<template>
	<view class="page">
		<view class="wrap">
			<template v-if="itemList.length>0">
				<view class="checklist" v-for="(hazardlist,idx) in itemList" :key="idx">
					<view class="title more">{{hazardlist.hazardTitle}}</view>
					<view class="item-cont" v-if="hazardlist.riskList&&hazardlist.riskList.length>0">
						<view class="checklistItem" v-for="(riskItem,itemIdx) in hazardlist.riskList" :key="itemIdx">
							<view class="itemTitle more"> {{riskItem.riskTitle}}</view>
							<view  class="point-cont" v-if="riskItem.recordList&&riskItem.recordList.length>0">
								<view class="point" v-for="(measure,measureIdx) in riskItem.recordList" :key="measureIdx" @click="check(measure)">
									<view class="pointContent">
											<text style="padding-right: 5px;">{{measureIdx+1}})</text>
											<text>{{measure.measureContent}}</text>
									</view>
									<view class="status">{{measure.checkResult|checkResultFilter}}</view>
								</view>
							</view>
						</view>				
					</view>				
				</view>
				<view class="handle-container">	
					<view class="handle" @click="handleSubmit(1)">全部通过</view>
					<view class="handle" @click="handleSubmit(2)">全不通过</view>	
					<view class="handle" @click="handleSubmit(3)">提交</view>
					<view class="handle" @click="handleSubmit(4)">撤销</view>
					<view class="handle" @click="handleSubmit(5)">转交</view>
				</view>
			</template>
			<template v-else>没有可处理的清单^-_-^</template>
		</view>		
	</view>
</template>
<script>
import { getChecklistHazardRecordView } from '@/api/aqpt/checklistRecordHazardApi'
import { batchUpdateChecklistHazardRecordDoing } from '@/api/aqpt/checklistHazardRecordApi'
import {cancelCheckTask,completeCheckTask} from '@/api/aqpt/task.js'	
	export default {
		data() {
			return {
				defaultProps: {
					id: 'itemId', 
					children: 'children',
					label: 'itemTitle'
				},
				accountInfo:{},
				divider: false,
				edit: true,
				itemList:[],
				recordId:undefined,
				checklistId:undefined,
				handleVisiable:false,
				type:undefined,
				status:undefined,
				taskTitle:""
			}
		},
		  filters: {
		    checkResultFilter(i) {
			  if (i >= 0) {
			    const strs = [
			      '未检查',
			      '通过'
			    ]
			    return strs[i]
			  } else {
			    if (i === -1) {
			      return '未通过'
			    } else if (i === -2) {
			      return '发现隐患'
			    }
			  }
		    }
		  },
		onLoad({rid,cid,title}) {
			this.checklistId=cid	
			this.recordId=rid	
			let accountInfo=uni.getStorageSync('accountInfo')
			this.accountInfo=accountInfo
			this.taskTitle=title
			this.getchecklistRecord(rid)
		},
		methods: {
			getchecklistRecord(recordId){
				getChecklistHazardRecordView(recordId).then((res)=>{
					this.itemList=res.data.hazardList
					this.status=res.data.status				
				})
			},
			check(measure){		
				uni.setStorageSync("measure",measure)
				uni.navigateTo({
					url:"/pages/index/handle/task/hazardRecord/form"
				})								
			},
			handleSubmit(type){
				let recordId=this.recordId;
				let checklistId=this.checklistId;
				if(type===1){
					batchUpdateChecklistHazardRecordDoing(recordId,1).then(()=>{
						this.getchecklistRecord(checklistId,recordId)
					})
				}
				if(type===2){
					batchUpdateChecklistHazardRecordDoing(recordId,-1).then(()=>{
						this.getchecklistRecord(checklistId,recordId)
					})
				}				
				if(type===3){//完成
					completeCheckTask(recordId).then(()=>{				
						uni.switchTab({
							url:'/pages/index/index'
						})
					}).catch(()=>{
						uni.showToast({
							icon:"none",
							title:"操作失败"
						})
					})
				}
				if(type===4){//放弃
					cancelCheckTask(recordId).then(()=>{
						uni.switchTab({
							url:'/pages/index/index'
						})
					}).catch(()=>{
						uni.showToast({
							icon:"none",
							title:"操作失败"
						})
					})
				}	
				if(type===5){//转交
					let taskTitle=this.taskTitle;
					uni.navigateTo({
						url:`/pages/index/handle/task/checkList/form/transferCheckTask?tid=${recordId}&title=${taskTitle}`
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		background-color: #F5F6F8;
		padding: 20rpx;
		min-height: 100vh;
		box-sizing: border-box;
		margin-bottom: 100rpx;
		.page-head{
			text-align: right;
			padding-bottom: 10rpx;
			.handle{
				display: inline-block;
				background-color: #3384FF;
				color: #fff;
				padding: 10rpx 15rpx;
				box-sizing: border-box;
				border-right: 1rpx solid #eaeaea;
				font-size: 30rpx;
				text-align: center;
				&:nth-child(4){
					border: 0;
				}
			}
		}
	}	
	.wrap{
		padding: 20rpx;
		background-color: #fff;
		.checklist{
			.title{
				color: #222222;
				font-size: 32rpx;
				height: 98rpx;
				line-height: 98rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				border-bottom: 1px dashed #E8E8E8;				
			}
			.more{
				background-image: url('/static/tree_more.png');
				background-size: 30rpx 30rpx;
				padding-left: 40rpx;
				background-position: center left;
				background-repeat: no-repeat;
			}
			.item-cont{
				padding-left: 20rpx;
				border-bottom: 1px dashed #E8E8E8;	
				.checklistItem{
					.itemTitle{
						color: #222222;
						font-size: 32rpx;	
						height: 98rpx;
						line-height: 98rpx;
					}
				}
				.point-cont{
					padding-left: 30rpx;
					.point{
						display: flex;						
						color: #666;
						font-size: 28rpx;	
						// height: 98rpx;
						// line-height: 98rpx;
						.pointContent{
							flex: 1;
						}
					}
				}
			}
		}
			
		.handle-container{
			position: fixed;
			width: 100%;
			left: 0;
			bottom: 0;
			background-color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
			border-top: 1rpx solid #eaeaea;
			.handle{
				display:block;
				background-color: #3384FF;
				color: #fff;
				padding: 15rpx 0;
				width: 20%;
				box-sizing: border-box;
				border-right: 1rpx solid #eaeaea;
				font-size: 26rpx;
				text-align: center;
				&:last-child{
					border: 0;
				}
			}
		}
	}
</style>
