<template>
	<view class="todo-page">
		<step-title :stepPage="stepsPage" :stepText="stepsText"></step-title>
		<view class="allview">
			<view class="card" v-if="stepsPageList === 0">
				<u--form labelWidth="auto" :model="dataModel" ref="wForm" class="demo-ruleForm">
					<view style="position: relative;">
						<view style="position: absolute;left: -10px;color: #3d4b70;top: -3px;">*</view>
					</view>

					<view style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;">基本信息填写</view>
					<u-form-item label="评估年度：" prop="YEAR">
						<u--input v-model="dataModel.YEAR" disabled Color="#ffffff" placeholder="请填写年度" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>
					<!-- <u-form-item label="辨识与评估内容:">
					</u-form-item>
					<u--textarea v-model="dataModel.CONTENTS" placeholder="请输入内容" autoHeight></u--textarea> -->
					<u-form-item label="开始时间:" @click="handleChangeRecitify('start')">
						<u--input v-model="dataModel.START_DATE" placeholder="请选择时间" disabled Color="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
						<!-- <u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
						</u-icon> -->
					</u-form-item>
					<u-form-item label="结束时间:" @click="handleChangeRecitify('end')">
						<u--input v-model="dataModel.END_DATE" placeholder="请选择时间" disabled Color="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
						<!-- <u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
						</u-icon> -->
					</u-form-item>
					<u-form-item label="评价要求:" @click="handleChangeStep('','','demand')" v-if="dataModel.Nav_Require">
						<u--input v-model="dataModel.Nav_Require.NAME" placeholder="请选择辨识要求" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
						<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
						</u-icon>
					</u-form-item>
					<u--textarea v-model="dataModel.Nav_Require.NAME" disabled autoHeight v-if="dataModel.Nav_Require"></u--textarea>
					<view class="upload-title">附件：</view>
					<full-upload v-model="dataModel.Nav_Files" :isShowBtn='true' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>

				</u--form>
			</view>
			<view style="padding: 10px 16px;" v-if="stepsPageList === 0" class="bottom-button">
				<u-button type="primary" :loading="stepLoad" @click="stepAdd" color="#3d4b70">下一步</u-button>
			</view>
			<view class="card" v-if="stepsPageList === 1">
				<u--form labelWidth="auto" :model="dataModel" ref="wForm" class="sub-form">


					<view style="position: relative;">

						<view style="position: absolute;left: -10px;color: #3d4b70;top: -3px;">*</view>
					</view>

					<view style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;margin-top: 20px;">辨识内容</view>
					<view v-for="(item,index) in dataModel.Nav_Details" :key="index" style="border-bottom: #ceccca 1px solid;margin-bottom: 10px;padding-bottom: 10px;">
						<u-form-item prop="Nav_Contents" :label="index+1+'.辨识区域：'" @click="handleChangeStep(index,'','Area')">

							<view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;flex: 1;">
								<!-- <view @click="handleChangeStep(index,'','Area')" style="flex: 1;">
									{{index+1+'.辨识区域：'+item.Nav_Area.NAME}}
								</view> -->
								<u--input v-model="item.Nav_Area.NAME" disabled disabledColor="#ffffff" placeholder="请选择辨识区域" border="none" fontSize="14px">
								</u--input>
								<view class="action" @click.stop style="display: flex;flex-direction: row;align-items: center;justify-content: space-around;">
									<u-icon @click="handleDelRowBefore(index,'','Area')" name="trash" color="#ff4d4f" size="21" style="margin-right: 20px;"></u-icon>
									<u-icon name="arrow-up" size="12" v-if="item.showPack" @click="handlePack(index)"></u-icon>
									<u-icon name="arrow-down" size="12" v-if="!item.showPack" @click="handlePack(index)"></u-icon>
								</view>
							</view>

						</u-form-item>
						<view v-if="item.showPack==true">
							<u-form-item label="生产单元：" @click="handleChangeUnit(index,'','MinType')" border-bottom>
								<u--input v-model="item.MineType" disabled disabledColor="#ffffff" placeholder="请选择生产单元" border="none" inputAlign="right" fontSize="14px">
								</u--input>
								<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
								</u-icon>
							</u-form-item>
							<!-- <u-form-item label="风险名称" prop="CHECKSTANDARD" border-bottom>
								<u--input v-model="item.RISK_NAME" placeholder="请填写风险名称" disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item> -->
							<u-form-item label="风险名称" prop="CHECKSTANDARD" @click="handleChangeStep(index,'RiskName')" border-bottom>
								<u--input v-model="item.Nav_RiskName.NAME" placeholder="请填写风险名称" suffixIcon="arrow-down" suffixIconStyle="font-size: 12px" disabledColor="#ffffff" inputAlign="right" fontSize="14px"
									border="none">
								</u--input>
							</u-form-item>
							<u-form-item label="风险描述" prop="HIDDEN_DESCRIPTION">
							</u-form-item>
							<u--textarea v-model="item.RISK_DESCRIPTION" placeholder="请填写风险描述" autoHeight maxlength="-1"></u--textarea>
							<u-form-item label="风险类别" prop="HIDDEN_LEVEL" @click="handleChangeStep(index,'','Category')" border-bottom>
								<u--input v-model="item.Nav_Type.NAME" placeholder="请选择风险类别" disabled suffixIcon="arrow-down" suffixIconStyle="font-size: 12px" disabledColor="#ffffff" inputAlign="right" fontSize="14px"
									border="none">
								</u--input>
							</u-form-item>
							<u-form-item label="风险评价L" border-bottom>
								<u-number-box integer v-model="item.EVALUATE_L" :min="-10000" :max="10000" @change="changeCore(index,'L',$event)"></u-number-box>
							</u-form-item>
							<u-form-item label="风险评价E" border-bottom>
								<u-number-box integer v-model="item.EVALUATE_E" :min="-10000" :max="10000" @change="changeCore(index,'E',$event)"></u-number-box>
							</u-form-item>
							<u-form-item label="风险评价C" border-bottom>
								<u-number-box integer v-model="item.EVALUATE_C" :min="-10000" :max="10000" @change="changeCore(index,'C',$event)"></u-number-box>
							</u-form-item>
							<u-form-item label="分值D" border-bottom>
								<u--input v-model="item.EVALUATE_SCORE" placeholder="请输入风险评价" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item>
							<u-form-item label="风险等级" prop="HIDDEN_PLACE" @click="handleChangeUnit(index,'','Level')" border-bottom>
								<u--input v-model="item.EVALUATE_LEVEL" placeholder="请选择风险等级" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
								<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
								</u-icon>
							</u-form-item>
							<u-form-item label="应急处置" prop="EMERGENCY" borderBottom>
								<u--input disabledColor="#ffffff" v-model="item.EMERGENCY" border="none"  inputAlign="right" placeholder="请输入应急处置"></u--input>
							</u-form-item>
							<u-form-item label="管控信息" prop="HIDDEN_PLACE" @click="changeControl(index)">
								<u-icon slot="right" name="plus-circle" size="18" v-if="!item.isShowControl">
								</u-icon>
								<u-icon slot="right" name="minus-circle" size="18" v-if="item.isShowControl">
								</u-icon>
							</u-form-item>
							<view v-if="item.isShowControl">
								<u-subsection :list="childList" :current="item.curNow" @change="sectionChange(index,$event)"></u-subsection>
								<view v-if="item.curNow==0&&item.Nav_DetailMeasures.length!==0">
									<view v-for="(item1,index1) in item.Nav_DetailMeasures" :key="index1" style="margin: 5px 5px;padding: 0px 10px;">
										<u-form-item :label="index1+1+'.顺序'" prop="NUM" borderBottom>
											<u-number-box integer v-model="item1.NUM" :min="-10000" :max="10000"></u-number-box>
											<!-- <u--input disabledColor="#ffffff" v-model="item1.NUM" border="none" inputAlign="right" placeholder="请输入顺序">
											</u--input> -->
											<u-icon @click="handleDelRowBefore(index,index1,'Num')" name="trash" color="#ff4d4f" size="21" style="margin-left: 20px;"></u-icon>
										</u-form-item>
										<u-form-item label="管控措施" prop="MEASURES_NAME" borderBottom>
											<u--input disabledColor="#ffffff" v-model="item1.MEASURES_NAME" border="none" inputAlign="right" placeholder="请输入管控措施"></u--input>
										</u-form-item>
										<!-- <u-form-item label="应急处置" prop="EMERGENCY" borderBottom>
											<u--input disabledColor="#ffffff" v-model="item1.EMERGENCY" border="none"  inputAlign="right" placeholder="请输入应急处置"></u--input>
										</u-form-item> -->
									</view>

								</view>
								<u-button text="新增管控措施" size="small" type="primary" style="width: 80%;margin-top: 20px;" @click="handleNewControlMea(index)" v-if="item.curNow==0"></u-button>
								<view v-if="item.curNow==1&&item.Nav_DetailDeparts.length!==0">
									<view v-for="(item1,index1) in item.Nav_DetailDeparts" :key="index1" style="margin: 5px 5px;padding: 0px 10px;">
										<u-form-item borderBottom>
											<view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;flex: 1;">
												<view @click="handleChangeStep(index,index1,'Dep')" style="flex: 1;display: flex;flex-direction: row;align-items: center;">
													<view style="flex: 1;">
														{{index1+1+'.管控部门 : ' +item1.Nav_Department.NAME}}
													</view>
													<u-icon style="margin-left: 5px;margin-right: 20px;" name="arrow-down" size="12">
													</u-icon>
												</view>
												<view class="action" style="display: flex;flex-direction: row;align-items: center;justify-content: space-around;">
													<u-icon @click="handleDelRowBefore(index,index1,'Dep')" name="trash" color="#ff4d4f" size="21"></u-icon>
												</view>
											</view>
										</u-form-item>
										<u-form-item borderBottom label="管控层级：" prop="Check_Level" @click="handleChangeUnit(index,index1,'ControlLevel')">
											<u--input v-model="item1.DEPARTMENT_TYPE" disabled disabledColor="#ffffff" placeholder="请选择管控层级" border="none" inputAlign="right" fontSize="14px">

											</u--input>
											<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
											</u-icon>
										</u-form-item>
										<u-form-item borderBottom label="管控责任人" prop="HIDDEN_PLACE" @click="handleChangeStep(index,index1,'Peo')" border-bottom>
											<u--input v-model="item1.Nav_User.NAME" placeholder="请选择管控责任人" suffixIcon="arrow-down" suffixIconStyle="font-size: 12px" disabled disabledColor="#ffffff" inputAlign="right"
												fontSize="14px" border="none">
											</u--input>
										</u-form-item>
									</view>
								</view>
								<u-button text="新增管控层级" size="small" type="primary" style="width: 80%;margin-top: 20px;" @click="handleNewControlLev(index)" v-if="item.curNow==1"></u-button>
							</view>
						</view>
					</view>
					<u-button text="新增检查区域" type="primary" @click="handleNewCheckContent"></u-button>
				</u--form>
			</view>
			<view style="padding: 10px 16px;display: flex;flex-direction: row;" v-if="stepsPageList === 1" class="bottom-button">
				<u-button type="primary" @click="stepReduce" color="#3d4b70" :plain="true" style="margin-right: 5px;">上一步</u-button>
				<u-button type="primary" @click="submit" color="#3d4b70" style="margin-left: 5px;">提交</u-button>
			</view>
			<u-picker :show="showPopupUnit" :columns="UnitLists" @confirm="confirmUnit" @cancel="cancelUnit" :defaultIndex="UnitDefaultIndex"></u-picker>
			<u-modal :show="showDelModalIndex >= 0" @confirm="confirmDel" @cancel="cacelDel" :showCancelButton="true" title="确认删除？"></u-modal>
			<u-datetime-picker :show="showPopupRecitifyDate" v-model="dateRecitifyTime" mode="date" @confirm="confirmRecitifyDate" @cancel="cancelRecitifyDate"></u-datetime-picker>
			<query-selector :show="showPopupStep" :total="curTotalStep" :lists="stepLists" :defaultValue="currentOperateStep.NAME" @close="handleClosePopupStep" @search="handleSearchStep" @select="handleSelectedStep" />
		</view>
	</view>
</template>

<script>
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		extendIgnoreDataRule,
		guid,
		initFilter,
		initFilterGroup,
		handleOriginalArray
	} from '../../../../utils/common'
	import {
		FMProductionUnit,
		SKEffective,
		SKMarkEnum,
		SKLevelEnum,
		CheckPeriods,
		CheckLevels,
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		EvaluationGet,
		EvaluationFullUpdate,
		getUserLists,
		GetEvaluationInfo,
		GetRiskAreaInfo,
		GetRiskTypeInfo,
		GetDepartmentInfo,GetRiskNameInfo
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices';
	import stepTitle from '@/components/custom/step-title.vue'
	import swipeActionItem from '../../../../uni_modules/uview-ui/libs/config/props/swipeActionItem';
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				showDelModalIndex: undefined,
				showPopupDate: false,
				showPopupRecitifyDate: false,
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				currentOperateStep: {},
				showPopupStep: false,
				stepLists: [],
				curTotalStep: 0,
				showPopupUnit: false,
				stepLoad: true,
				UnitLists: [],
				UnitDefaultIndex: [0],
				LevelLists: [],
				dataModel: {
					YEAR: '',
					START_DATE: '',
					END_DATE: '',
					Nav_Require: {
						NAME: ''
					},
					RequireName: '',
					IDENTIFY_EVALUATION_PLAN_ID:null,
					Nav_Files: [],
					Nav_Details: [{
						showPack: false,
						MineType: '',
						Nav_Area: {
							NAME: ''
						},
						RISK_NAME: '',
						Nav_RiskName: {
							NAME: ''
						},
						RISK_DESCRIPTION: '',
						Nav_Type: {
							NAME: ''
						},
						EVALUATE_L: 0,
						EVALUATE_E: 0,
						EVALUATE_C: 0,
						EVALUATE_SCORE: 0,
						EVALUATE_LEVEL: '',
						Nav_DetailDeparts: [],
						Nav_DetailMeasures: [],
						isShowControl: false,
					}]
				},
				model: {
					ORG_ID: '',
					YEAR: '',
					START_DATE: '',
					END_DATE: '',
					Nav_Require: {
						NAME: ''
					},
					RequireName: '',
					IDENTIFY_EVALUATION_PLAN_ID:null,
					Nav_Files: [],
					Nav_Details: [{
						showPack: false,
						MineType: '',
						Nav_Area: {
							NAME: ''
						},
						RISK_NAME: '',
						Nav_RiskName: {
							NAME: ''
						},
						RISK_DESCRIPTION: '',
						Nav_Type: {
							NAME: ''
						},
						EVALUATE_L: 0,
						EVALUATE_E: 0,
						EVALUATE_C: 0,
						EVALUATE_SCORE: 0,
						EVALUATE_LEVEL: '',
						Nav_DetailDeparts: [],
						Nav_DetailMeasures: [],
						isShowControl: false,
					}]

				},
				dateRecitifyTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd'),
				stepsText: ['发起', '审批', '归档'],
				stepsPage: 0,
				stepsPageList: 0,
				TaskID: '',
				nowName: '',
				nowIndex: 0,
				childList: ['管控措施', '管控层级'],
				curNow: 0,

			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.ID = option.ID ? option.ID : '';
			this.loadData()
		},
		methods: {
			loadData() {
				// const json = {}
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				extendRule(json, 'ID', 1, this.ID);
				extendInclude(json, 'Nav_Require');
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				extendInclude(json, 'Nav_Details');
				extendInclude(json, 'Nav_Details.Nav_Area');
				extendInclude(json, 'Nav_Details.Nav_Type');
				extendInclude(json, 'Nav_Details.Nav_RiskName');
				extendInclude(json, 'Nav_Details.Nav_DetailMeasures');
				extendInclude(json, 'Nav_Details.Nav_DetailDeparts');
				extendInclude(json, 'Nav_Details.Nav_DetailDeparts.Nav_Department');
				extendInclude(json, 'Nav_Details.Nav_DetailDeparts.Nav_User');
				extendIgnoreDataRule(json)
				// extendRule(json, 'TASK_ID', 1, this.TaskID);
				EvaluationGet(json).then(res => {
					this.dataModel = res;
					this.dataModel.Nav_Require = res.Nav_Require ? res.Nav_Require : {
						NAME: ''
					}
					this.stepsPage = res.STATUS == 0 ? 0 : res.STATUS == 20 ? 1 : 2
					this.dataModel.START_DATE = uni.$u.timeFormat(res.START_DATE, 'yyyy-mm-dd')
					this.dataModel.END_DATE = uni.$u.timeFormat(res.END_DATE, 'yyyy-mm-dd')
					this.dataModel.RequireName = res.Nav_Require.NAME
					this.dataModel.Nav_Details.map(item => {
						item['showPack'] = false
						item['isShowControl'] = false
						item['curNow']=0
						item.MineType = MineTypeName[item.MineType]
						item.EVALUATE_LEVEL = item.EVALUATE_LEVEL == 10 ? '重大风险' : item.EVALUATE_LEVEL == 20 ? '较大风险' : item.EVALUATE_LEVEL == 30 ? '一般风险' : item.EVALUATE_LEVEL == 40 ? '低风险' : ''
						item.Nav_RiskName = item.Nav_RiskName? item.Nav_RiskName: {
							NAME: ''}
						item.Nav_DetailDeparts.map(item1 => {
							item1.DEPARTMENT_TYPE = item1.DEPARTMENT_TYPE == 0 ? '部门' : item1.DEPARTMENT_TYPE == 1 ? '车间' : item1.DEPARTMENT_TYPE == 2 ? '班组' : item1.DEPARTMENT_TYPE == 3 ? '公司' :
								'岗位'
						})
					})
					this.stepLoad = false

				})
			},
			sectionChange(index,e) {
				this.dataModel.Nav_Details[index].curNow = e
				this.dataModel.Nav_Details = [...this.dataModel.Nav_Details]
			},
			changeControl(index) {
				this.dataModel.Nav_Details[index].isShowControl = this.dataModel.Nav_Details[index].isShowControl == false ? true : false
				this.dataModel.Nav_Details = [...this.dataModel.Nav_Details]
			},
			changeCore(index, name, e) {
				let l = this.dataModel.Nav_Details[index].EVALUATE_L
				let o = this.dataModel.Nav_Details[index].EVALUATE_E
				let c = this.dataModel.Nav_Details[index].EVALUATE_C

				if (name == 'L') {
					this.dataModel.Nav_Details[index].EVALUATE_SCORE = e.value * o * c
				} else if (name == 'E') {
					this.dataModel.Nav_Details[index].EVALUATE_SCORE = e.value * l * c
				} else {
					this.dataModel.Nav_Details[index].EVALUATE_SCORE = e.value * l * o
				}
				this.dataModel.Nav_Details[index].EVALUATE_LEVEL = this.changeLevel(index)
			},
			changeLevel(index) {
				let D = this.dataModel.Nav_Details[index].EVALUATE_SCORE
				if (D >= 320) {
					return "重大风险";
				} else if (D >= 160 && D < 320) {
					return "较大风险";
				} else if (D >= 70 && D < 160) {
					return "一般风险";
				} else {
					return "低风险";
				}
			},
			handlePack(index) {
				this.dataModel.Nav_Details[index].showPack = this.dataModel.Nav_Details[index].showPack == false ? true : false
				this.dataModel.Nav_Details = [...this.dataModel.Nav_Details]

			},
			cancelUnit() {
				this.showPopupUnit = false
			},
			handleChangeUnit(index, index1, name) {
				this.nowIndex = [index, index1, name]
				if (name == 'MinType') {
					this.UnitLists = [FMProductionUnit]
				} else if (name == 'Level') {
					this.UnitLists = [SKLevelEnum]
				} else {
					this.UnitLists = [CheckLevels]
				}
				this.showPopupUnit = true
			},
			confirmUnit(e) {
				if (this.nowIndex[2] == 'MinType') {
					this.dataModel.Nav_Details[this.nowIndex[0]].MineType = e.value[0]
				} else if (this.nowIndex[2] == 'Level') {
					this.dataModel.Nav_Details[this.nowIndex[0]].EVALUATE_LEVEL = e.value[0]
				} else {
					this.dataModel.Nav_Details[this.nowIndex[0]].Nav_DetailDeparts[this.nowIndex[1]].DEPARTMENT_TYPE = e.value[0]
				}
				this.showPopupUnit = false
			},
			stepAdd() {
				if (!this.dataModel.YEAR) {
					uni.showToast({
						title: '年度不能为空',
						icon: 'none'
					})
					return
				}
				if (!this.dataModel.START_DATE) {
					uni.showToast({
						title: '开始时间不能为空',
						icon: 'none'
					})
					return
				}
				if (!this.dataModel.END_DATE) {
					uni.showToast({
						title: '结束时间不能为空',
						icon: 'none'
					})
					return
				}
				if (!this.dataModel.Nav_Require.NAME) {
					uni.showToast({
						title: '评价要求不能为空',
						icon: 'none'
					})
					return
				}

				this.stepsPageList = this.stepsPageList + 1
			},
			stepReduce() {
				this.stepsPageList = this.stepsPageList - 1
			},
			handleNewCheckContent() {
				this.dataModel.Nav_Details.push({
					showPack: false,
					MineType: '',
					Nav_Area: {
						NAME: ''
					},
					RISK_NAME: '',
					Nav_RiskName:{
						NAME: ''
					},
					RISK_DESCRIPTION: '',
					Nav_Type: {
						NAME: ''
					},
					EVALUATE_L: 0,
					EVALUATE_E: 0,
					EVALUATE_C: 0,
					EVALUATE_SCORE: 0,
					EVALUATE_LEVEL: '低风险',
					Nav_DetailDeparts: [],
					Nav_DetailMeasures: [],
					isShowControl: false,
				})

				this.dataModel.Nav_Details = [...this.dataModel.Nav_Details]
			},
			handleNewControlMea(index) {
				this.dataModel.Nav_Details[index].Nav_DetailMeasures.push({
					NUM: 0,
					MEASURES_NAME: '',
					EMERGENCY: '',
				})
			},
			handleNewControlLev(index) {
				this.dataModel.Nav_Details[index].Nav_DetailDeparts.push({
					DEPARTMENT_TYPE: '',
					Nav_Department: {
						NAME: ''
					},
					Nav_User: {
						NAME: ''
					},
				})
			},
			handleDelRowBefore(index, index1, name) {
				this.showDelModalIndex = index
				this.nowIndex = [index, index1, name]


			},
			confirmDel() {
				if (this.nowIndex[2] == 'Area') {
					this.dataModel.Nav_Details.splice(this.nowIndex[0], 1)
				} else if (this.nowIndex[2] == 'Num') {
					this.dataModel.Nav_Details[this.nowIndex[0]].Nav_DetailMeasures.splice(this.nowIndex[1], 1)
				} else {
					this.dataModel.Nav_Details[this.nowIndex[0]].Nav_DetailDeparts.splice(this.nowIndex[1], 1)
				}
				this.showDelModalIndex = undefined

			},
			cacelDel() {
				this.showDelModalIndex = undefined
			},
			cancelRecitifyDate() {
				this.showPopupRecitifyDate = false
			},
			handleChangeRecitify(name) {
				this.nowName = name
				this.showPopupRecitifyDate = true
			},
			confirmRecitifyDate(e) {
				if (this.nowName == 'start') {
					this.dataModel.START_DATE = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd')

				} else {
					this.dataModel.END_DATE = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd')
				}
				this.dateRecitifyTime = uni.$u.timeFormat(e.value,
					'yyyy-mm-dd')

				this.showPopupRecitifyDate = false
			},
			handleChangeStep(index, index1, name) {
				this.currentOperateStep = {}
				this.showPopupStep = true
				this.nowIndex = [index, index1, name]
				this.handleSearchStep('init')
			},
			handleClosePopupStep() {
				this.showPopupStep = false
				// this.showPopupCertificate = false
			},
			handleSearchStep(val, pageIndex) {
				let requestInfo = this.nowIndex[2] == 'demand' ? GetEvaluationInfo : this.nowIndex[2] == 'Area' ? GetRiskAreaInfo : this.nowIndex[2] == 'Category' ? GetRiskTypeInfo : this.nowIndex[2] == 'Dep' ?
					GetDepartmentInfo : this.nowIndex[1] == 'RiskName' ? GetRiskNameInfo:getUserLists
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "",0, pageIndex ?? 1)
				if (val) {
					extendRule(json, 'NAME', 9, val);
				}
				
				
				json.Limit = 20
				if (pageIndex) {
					json.Start = (pageIndex - 1) * json.Limit;
				}
				if (val !== 'init') {
					const tempGroup = initFilterGroup(false);
					extendGroupRule(tempGroup, 'NAME', 9, val)
					extendFilterGroup(json, tempGroup);
				}
				requestInfo(json).then(res => {
					// if (res.IsSuccessful) {
					this.stepLists = (res.Data || res).map(i => {
						return {
							...i,
							id: i.ID,
							name: i.NAME,
						}
					})
					this.curTotalStep = res.TotalCount
					// }
				})


			},
			handleSelectedStep(val) {
				if (this.nowIndex[2] == 'demand') {
					this.dataModel.Nav_Require.NAME = val.NAME
					this.dataModel.REQUIRE_ID = val.ID
					this.dataModel.RequireName = val.NAME
				} else if (this.nowIndex[2] == 'Area') {
					this.dataModel.Nav_Details[this.nowIndex[0]].Nav_Area.NAME = val.NAME
					this.dataModel.Nav_Details[this.nowIndex[0]].AREA_ID = val.ID
				} else if (this.nowIndex[2] == 'Category') {
					this.dataModel.Nav_Details[this.nowIndex[0]].Nav_Type.NAME = val.NAME
					this.dataModel.Nav_Details[this.nowIndex[0]].TYPE_ID = val.ID
				} else if (this.nowIndex[2] == 'Dep') {
					this.dataModel.Nav_Details[this.nowIndex[0]].Nav_DetailDeparts[this.nowIndex[1]].Nav_Department.NAME = val.NAME
					this.dataModel.Nav_Details[this.nowIndex[0]].Nav_DetailDeparts[this.nowIndex[1]].DEPARTMENT_ID = val.ID
				} else if (this.nowIndex[1] == 'RiskName') {
					this.dataModel.Nav_Details[this.nowIndex[0]].Nav_RiskName.NAME = val.NAME
					this.dataModel.Nav_Details[this.nowIndex[0]].RISK_NAME_ID = val.ID
				} 
				else {
					this.dataModel.Nav_Details[this.nowIndex[0]].Nav_DetailDeparts[this.nowIndex[1]].Nav_User.NAME = val.NAME
					this.dataModel.Nav_Details[this.nowIndex[0]].Nav_DetailDeparts[this.nowIndex[1]].USER_ID = val.ID
				}
				this.showPopupStep = false

			},

			submit() {
				let i=1
				for (let item of this.dataModel.Nav_Details) {
					if (!item.MineType) {
						uni.showToast({
							title: '顺序'+i+'生产单元不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.Nav_Area.NAME) {
						uni.showToast({
							title: '顺序'+i+'辨识区域不能为空',
							icon: 'none'
						})
						return
					}
					// if (!item.RISK_NAME) {
					// 	uni.showToast({
					// 		title: '风险名称不能为空',
					// 		icon: 'none'
					// 	})
					// 	return
					// }
					if (!item.Nav_RiskName.NAME) {
						uni.showToast({
							title: '顺序'+i+'风险名称不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.RISK_DESCRIPTION) {
						uni.showToast({
							title: '顺序'+i+'风险描述不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.Nav_Type.NAME) {
						uni.showToast({
							title: '顺序'+i+'风险类别不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.EVALUATE_L) {
						uni.showToast({
							title: '顺序'+i+'风险评价L不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.EVALUATE_E) {
						uni.showToast({
							title: '顺序'+i+'风险评价E不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.EVALUATE_C) {
						uni.showToast({
							title: '顺序'+i+'风险评价C不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.EVALUATE_SCORE) {
						uni.showToast({
							title: '顺序'+i+'分值D不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.EVALUATE_LEVEL) {
						uni.showToast({
							title: '顺序'+i+'风险等级不能为空',
							icon: 'none'
						})
						return
					}
					if(item.Nav_DetailMeasures.length!==0){
						for(let item1 of item.Nav_DetailMeasures){
							if (!item1.MEASURES_NAME) {
								uni.showToast({
									title: '顺序'+i+'管控措施不能为空',
									icon: 'none'
								})
								return
							}
							// if (!item1.EMERGENCY) {
							// 	uni.showToast({
							// 		title: '顺序'+i+'应急处置不能为空',
							// 		icon: 'none'
							// 	})
							// 	return
							// }
						}
					}
					if(item.Nav_DetailDeparts.length!==0){
						for(let item1 of item.Nav_DetailDeparts){
							if (!item1.DEPARTMENT_TYPE) {
								uni.showToast({
									title: '顺序'+i+'管控层级不能为空',
									icon: 'none'
								})
								return
							}
							if (!item1.Nav_Department.NAME) {
								uni.showToast({
									title: '顺序'+i+'管控部门不能为空',
									icon: 'none'
								})
								return
							}
							if (!item1.Nav_User.NAME) {
								uni.showToast({
									title: '顺序'+i+'管控责任人不能为空',
									icon: 'none'
								})
								return
							}
						}
					}
					i++
				}

				this.model.ORG_ID = this.ORG_ID
				let arr = []

				this.dataModel.Nav_Details.map(item => {
					arr.push({
						MineType: MineTypeIndex[item.MineType],
						AREA_ID: item.AREA_ID,
						RISK_NAME: item.RISK_NAME,
						RISK_NAME_ID: item.RISK_NAME_ID,
						RISK_DESCRIPTION: item.RISK_DESCRIPTION,
						TYPE_ID: item.TYPE_ID,
						EVALUATE_L: item.EVALUATE_L,
						EVALUATE_E: item.EVALUATE_E,
						EVALUATE_C: item.EVALUATE_C,
						EVALUATE_SCORE: item.EVALUATE_SCORE,
						EVALUATE_LEVEL: item.EVALUATE_LEVEL == '重大风险' ? 10 : item.EVALUATE_LEVEL == '较大风险' ? 20 : item.EVALUATE_LEVEL == '一般风险' ? 30 : item.EVALUATE_LEVEL == '低风险' ? 40 : 0,
						Nav_DetailDeparts: item.Nav_DetailDeparts.map(item => ({
							DEPARTMENT_TYPE: item.DEPARTMENT_TYPE == '部门' ? 0 : item.DEPARTMENT_TYPE == '车间' ? 1 : item.DEPARTMENT_TYPE == '班组' ? 2 : item.DEPARTMENT_TYPE == '公司' ? 3 : 4,
							DEPARTMENT_ID: item.DEPARTMENT_ID,
							USER_ID: item.USER_ID
						})),
						Nav_DetailMeasures: item.Nav_DetailMeasures,
					})
				})
				this.model = {
					ORG_ID: this.ORG_ID,
					YEAR: this.dataModel.YEAR,
					START_DATE: this.dataModel.START_DATE,
					END_DATE: this.dataModel.END_DATE,
					REQUIRE_ID: this.dataModel.REQUIRE_ID,
					IDENTIFY_EVALUATION_PLAN_ID:this.dataModel.IDENTIFY_EVALUATION_PLAN_ID,
					Nav_Files: this.dataModel.Nav_Files,
					Nav_Details: arr
				}
				this.model.ID = this.ID
				this.model.TaskID = this.TaskID
				this.model.PUBLISH = "SaveAndNotify";
				EvaluationFullUpdate(this.model).then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})


			}

		},
	}
</script>

<style scoped>
	@import url("../../../../style/css/newTemplate.css");

	.sub-form>>>.u-form-item__body__right__content__slot {
		display: flex;
		justify-content: flex-end;
	}
</style>