<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="model" 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="CONTEXT" borderBottom v-if="model.STATUS==40">
					</u-form-item>
					<u--textarea v-html="model.CONTEXT" border="surround" v-if="model.STATUS==40" disabled></u--textarea>
					<u-form-item  label="评估年度：" prop="YEAR">
						<u--input v-model="model.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="model.CONTENTS" placeholder="请输入内容" autoHeight></u--textarea> -->
					<u-form-item  label="开始时间:" @click="handleChangeRecitify('start')">
						<u--input v-model="model.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="model.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 required label="评价要求:" @click="handleChangeStep('','','demand')">
						<u--input v-model="(model.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="(model.Nav_Require||{}).NAME" disabled autoHeight></u--textarea>
					<view class="upload-title">附件：</view>
					<full-upload v-model="model.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="model" 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 model.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('SKProductionUnit',item)" border-bottom>
								<u--input v-model="item.MineTypeName" 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 required label="风险名称" prop="CHECKSTANDARD" @click="handleChangeStep(index,'RiskName')" border-bottom>
								<u--input v-model="item.RISK_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 required 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 required label="风险评价L" border-bottom @click="handleShowSheetForArea(item,{title: '风险评价', name: 'EVALUATE_L'})">
								<u--input v-model="(item.Nav_SCOREL||{}).SCORE" 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 required label="风险评价E" border-bottom @click="handleShowSheetForArea(item,{title: '风险评价', name: 'EVALUATE_E'})">
								<u--input v-model="(item.Nav_SCOREE||{}).SCORE" 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 required label="风险评价C" border-bottom @click="handleShowSheetForArea(item,{title: '风险评价', name: 'EVALUATE_C'})">
								<u--input v-model="(item.Nav_SCOREC||{}).SCORE" 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 required 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 required label="风险等级" prop="HIDDEN_PLACE" @click="handleChangeUnit('SKEvaluateLevelEnum',item)" border-bottom>
								<u--input v-model="item.EVALUATE_LEVELName" 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="请输入应急处置" fontSize="14px"></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 required 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;">
														{{item1.Nav_Department?index1+1+'.管控部门 : ' +'.'+item1.Nav_Department.NAME:index1+1+'.'}}
													</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 required borderBottom label="管控层级：" prop="Check_Level" @click="handleChangeUnit('SKDepartmentTypeEnum',item1)">
											<u--input v-model="item1.DEPARTMENT_TYPEName" 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 required 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="comPickerInfo.showSheet" :columns="comPickerInfo.columns" @confirm="onConfirmPicker" @close="comPickerInfo.showSheet=false" @cancel="comPickerInfo.showSheet=false" keyName="NAME"></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" />
			<query-selector :multiple="selectorInfo.isMultiple" :show="selectorInfo.showPopup" :title="selectorInfo.title" :lists="selectorInfo.dataLists" :defaultChecked="selectorInfo.defaultChecked"
				@search="handleSearch" @select="handleSelected" @close="selectorInfo.showPopup=false" :total="selectorInfo.totalCount" />
		</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,
		GetScorel,
		GetScoree,
		GetScorec
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import {
		getEnum
	} from '../../../../services/common';
	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: [],
				model: {
					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: ''
						},
						Nav_SCOREL: {
							SCORE: 0
						},
						Nav_SCOREE: {
							SCORE: 0
						},
						Nav_SCOREC: {
							SCORE: 0
						},
						EVALUATE_SCORE: 0,
						EVALUATE_LEVEL: '',
						EVALUATE_LEVELName:'',
						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,
				comPickerInfo: {
					showSheet: false,
					dataItem: {},
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				selectorInfo: {
					name: 'user',
					isMultiple: false,
					showPopup: false,
					totalCount: 0,
					title: '考核结果选择',
					dataItem: {},
					index: 0,
					columns: [],
					dataLists: [],
					defaultText: '',
					defaultChecked: []
				},
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {} // 存储枚举文本列表（用于下拉选择等场景）

			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.ID = option.ID ? option.ID : '';
			this.fetchEnums(['SKProductionUnit', 'SKEvaluateLevelEnum', 'SKDepartmentTypeEnum']);
		},
		methods: {
			async fetchEnums(enumNames) {
				try {
					// 存储所有枚举请求的Promise
					const enumPromises = enumNames.map(name => {
						return getEnum({
							name
						}).then(res => {
							// 统一处理枚举格式：添加name/code字段，便于后续映射
							return {
								enumName: name,
								data: res.map(item => ({
									...item,
									name: item.NAME, // 统一显示名称字段
									code: item.ID // 统一值字段
								}))
							};
						});
					});

					// 等待所有枚举请求完成
					const results = await Promise.all(enumPromises);
					// 存储枚举结果到data中（键为枚举名称，值为处理后的数据）
					results.forEach(({
						enumName,
						data
					}) => {
						this.enumsData[enumName] = data;
						// 生成文本列表（如需要）
						this.enumsText[enumName] = data.map(item => item.name);
					});
					// 所有枚举获取完成后，执行loadData
					this.loadData();
				} catch (error) {
					console.error('枚举请求失败:', error);
					uni.showToast({
						title: '枚举数据加载失败',
						icon: 'none'
					});
				}
			},
			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.model = res;
					this.stepsPage = res.STATUS == 0 ? 0 : res.STATUS == 20 ? 1 : 2
					this.model.START_DATE = uni.$u.timeFormat(res.START_DATE, 'yyyy-mm-dd')
					this.model.END_DATE = uni.$u.timeFormat(res.END_DATE, 'yyyy-mm-dd')
					this.model.RequireName = res.Nav_Require.NAME
					this.model.Nav_Details.map(item => {
						item['showPack'] = false
						item['isShowControl'] = false
						item['curNow'] = 0
						item.Nav_SCOREL = item.Nav_SCOREL ? item.Nav_SCOREL : {
							SCORE: ''
						}
						item.Nav_SCOREE = item.Nav_SCOREE ? item.Nav_SCOREE : {
							SCORE: ''
						}
						item.Nav_SCOREC = item.Nav_SCOREC ? item.Nav_SCOREC : {
							SCORE: ''
						}
						item.MineTypeName = item.MineType !== undefined ? this.enumsData['SKProductionUnit'].find(item1 => item1.code === item.MineType).name : '';
						item.EVALUATE_LEVELName = item.EVALUATE_LEVEL !== undefined ? this.enumsData['SKEvaluateLevelEnum'].find(item1 => item1.code === item.EVALUATE_LEVEL).name : '';
						item.Nav_DetailDeparts.map(item1 => {
							item1.DEPARTMENT_TYPEName = item1.DEPARTMENT_TYPE !== undefined ? this.enumsData['SKDepartmentTypeEnum'].find(item2 => item2.code === item1.DEPARTMENT_TYPE).name : '';
						})
					})
					this.stepLoad = false

				})
			},
			sectionChange(index, e) {
				this.model.Nav_Details[index].curNow = e
				this.model.Nav_Details = [...this.model.Nav_Details]
			},
			changeControl(index) {
				this.model.Nav_Details[index].isShowControl = this.model.Nav_Details[index].isShowControl == false ? true : false
				this.model.Nav_Details = [...this.model.Nav_Details]
			},
			handlePack(index) {
				this.model.Nav_Details[index].showPack = this.model.Nav_Details[index].showPack == false ? true : false
				this.model.Nav_Details = [...this.model.Nav_Details]

			},
			handleChangeUnit(name,item) {
				this.comPickerInfo = {
					showSheet: true,
					columns: [this.enumsText[name]],
					dataItem: item,
					name: name
				}
			},
			onConfirmPicker(e) {
				console.log(this.comPickerInfo.dataItem)
				if (this.comPickerInfo.name == 'SKProductionUnit') {
					this.comPickerInfo.dataItem.MineTypeName = e.value[0]
					this.comPickerInfo.dataItem.MineType = this.enumsData['SKProductionUnit'][e.indexs[0]].code
			
				} else if (this.comPickerInfo.name == 'SKEvaluateLevelEnum') {
					this.comPickerInfo.dataItem.EVALUATE_LEVELName = e.value[0]
					this.comPickerInfo.dataItem.EVALUATE_LEVEL = this.enumsData['SKEvaluateLevelEnum'][e.indexs[0]].code
				}else if (this.comPickerInfo.name == 'SKDepartmentTypeEnum') {
					
					this.comPickerInfo.dataItem.DEPARTMENT_TYPEName = e.value[0]
					this.comPickerInfo.dataItem.DEPARTMENT_TYPE = this.enumsData['SKDepartmentTypeEnum'][e.indexs[0]].code
				}
				this.comPickerInfo = {
					showSheet: false,
					dataItem: this.comPickerInfo.dataItem,
					columns: [],
					title: '',
					formIndex: undefined
				}
			},
			stepAdd() {
				if (!this.model.Nav_Require.NAME) {
					uni.showToast({
						title: '评价要求不能为空',
						icon: 'none'
					})
					return
				}

				this.stepsPageList = this.stepsPageList + 1
			},
			stepReduce() {
				this.stepsPageList = this.stepsPageList - 1
			},
			handleNewCheckContent() {
				this.model.Nav_Details.push({
					showPack: false,
					MineType: '',
					MineTypeName: '',
					Nav_Area: {
						NAME: ''
					},
					RISK_NAME: '',
					Nav_RiskName: {
						NAME: ''
					},
					RISK_DESCRIPTION: '',
					Nav_Type: {
						NAME: ''
					},
					Nav_SCOREL: {
						SCORE: ''
					},
					Nav_SCOREE: {
						SCORE: ''
					},
					Nav_SCOREC: {
						SCORE: ''
					},
					EVALUATE_SCORE: 0,
					EVALUATE_LEVEL:0,
					EVALUATE_LEVELName: '低风险',
					Nav_DetailDeparts: [],
					Nav_DetailMeasures: [],
					isShowControl: false,
				})

				this.model.Nav_Details = [...this.model.Nav_Details]
			},
			handleNewControlMea(index) {
				this.model.Nav_Details[index].Nav_DetailMeasures.push({
					NUM: 0,
					MEASURES_NAME: '',
					EMERGENCY: '',
				})
			},
			handleNewControlLev(index) {
				this.model.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.model.Nav_Details.splice(this.nowIndex[0], 1)
				} else if (this.nowIndex[2] == 'Num') {
					this.model.Nav_Details[this.nowIndex[0]].Nav_DetailMeasures.splice(this.nowIndex[1], 1)
				} else {
					this.model.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.model.START_DATE = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd')

				} else {
					this.model.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)
				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.model.Nav_Require.NAME = val.NAME
					this.model.REQUIRE_ID = val.ID
					this.model.RequireName = val.NAME
				} else if (this.nowIndex[2] == 'Area') {
					this.model.Nav_Details[this.nowIndex[0]].Nav_Area.NAME = val.NAME
					this.model.Nav_Details[this.nowIndex[0]].AREA_ID = val.ID
				} else if (this.nowIndex[2] == 'Category') {
					this.model.Nav_Details[this.nowIndex[0]].Nav_Type.NAME = val.NAME
					this.model.Nav_Details[this.nowIndex[0]].TYPE_ID = val.ID
				} else if (this.nowIndex[2] == 'Dep') {
					this.model.Nav_Details[this.nowIndex[0]].Nav_DetailDeparts[this.nowIndex[1]].Nav_Department.NAME = val.NAME
					this.model.Nav_Details[this.nowIndex[0]].Nav_DetailDeparts[this.nowIndex[1]].DEPARTMENT_ID = val.ID
				} else if (this.nowIndex[1] == 'RiskName') {
					this.model.Nav_Details[this.nowIndex[0]].RISK_NAME = val.NAME
					this.model.Nav_Details[this.nowIndex[0]].RISK_NAME_ID = val.ID
				} else {
					this.model.Nav_Details[this.nowIndex[0]].Nav_DetailDeparts[this.nowIndex[1]].Nav_User.NAME = val.NAME
					this.model.Nav_Details[this.nowIndex[0]].Nav_DetailDeparts[this.nowIndex[1]].USER_ID = val.ID
				}
				this.showPopupStep = false

			},
			handleShowSheetForArea(item, todo) {
				const validDetails = this.model.Nav_Details.filter(i => !i.IS_DELETED);
				const index = validDetails.indexOf(item);
				this.handleShowSheet({
					title: todo.title,
					name: todo.name,
					index: index
				});
			},
			async handleShowSheet(p) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "", 0, p.pageIndex ?? 1)
				// const json = initFilter(this.ORG_ID, "", "", 0, p.pageIndex ?? 1)
				let dataSelect = []
				var defaultChecked = []
				this.selectorInfo.isMultiple = false




				if (p.val) {
					extendRule(json, 'NAME', 9, p.val);
				}
				json.Limit = 20
				if (p.pageIndex) {
					json.Start = (p.pageIndex - 1) * json.Limit;
				}
				json.Sort = 'NAME'
				// json.SelectField = ["ID", "NAME", "NAME", "CODE"]
				// json.Sort = "NAME"
				// json.Order = 1
				if (p.name == 'EVALUATE_L') {

					// extendRule(json, 'DEVICE_STATUS', 1, '1');
					dataSelect = await GetScorel(json).then(res => {
						this.selectorInfo.totalCount = res.TotalCount
						if (res != undefined && res.Data.length > 0) {
							for (let i = 0; i < res.Data.length; i++) {
								res.Data[i].name = res.Data[i].NAME
							}
						}
						return res.Data
					})
				} else if (p.name == 'EVALUATE_E') {
					dataSelect = await GetScoree(json).then(res => {
						this.selectorInfo.totalCount = res.TotalCount
						if (res != undefined && res.Data.length > 0) {
							for (let i = 0; i < res.Data.length; i++) {
								res.Data[i].name = res.Data[i].NAME
							}
						}
						return res.Data
					})
				} else if (p.name == 'EVALUATE_C') {
					dataSelect = await GetScorec(json).then(res => {
						this.selectorInfo.totalCount = res.TotalCount
						if (res != undefined && res.Data.length > 0) {
							for (let i = 0; i < res.Data.length; i++) {
								res.Data[i].name = res.Data[i].NAME
							}
						}
						return res.Data
					})
				}

				if (defaultChecked == null)
					defaultChecked = []
				if (dataSelect.length) {
					this.selectorInfo = {
						itemData: p.itemData != undefined ? p.itemData : this.selectorInfo
							.itemData, //itemData: p.itemData,  搜索的时候  p.itemData为空  赋值修改 为 她自己本身 this.selectorInfo.itemData
						isMultiple: this.selectorInfo.isMultiple,
						totalCount: this.selectorInfo.totalCount,
						showPopup: true,
						title: p.title,
						name: p.name,
						dataLists: dataSelect,
						defaultChecked: defaultChecked,
						index: p.index
					}
				} else {
					// 暂无数据
				}
			},
			//数据加载
			handleSearch(val, pageIndex) {
				var p = {
					name: this.selectorInfo.name,
					title: this.selectorInfo.title,
					val: val,
					pageIndex: pageIndex,
					index: this.selectorInfo.index
				}
				this.handleShowSheet(p)
			},

			handleSelected(e) {
				this.selectorInfo.showPopup = false
				const validDetails = this.model.Nav_Details.filter(i => !i.IS_DELETED);
				const index = this.selectorInfo.index;
				const realIndex = this.model.Nav_Details.findIndex(item => item === validDetails[index]);
				if (this.selectorInfo.name == 'EVALUATE_L') {
					this.model.Nav_Details[realIndex].Nav_SCOREL = e;
					this.model.Nav_Details[realIndex].SCOREL_ID = e.ID;
				} else if (this.selectorInfo.name == 'EVALUATE_E') {
					this.model.Nav_Details[realIndex].Nav_SCOREE = e;
					this.model.Nav_Details[realIndex].SCOREE_ID = e.ID;
				} else if (this.selectorInfo.name == 'EVALUATE_C') {
					this.model.Nav_Details[realIndex].Nav_SCOREC = e;
					this.model.Nav_Details[realIndex].SCOREC_ID = e.ID;
				}
				let l = this.model.Nav_Details[realIndex].Nav_SCOREL.SCORE
				let o = this.model.Nav_Details[realIndex].Nav_SCOREE.SCORE
				let c = this.model.Nav_Details[realIndex].Nav_SCOREC.SCORE
				this.model.Nav_Details[realIndex].EVALUATE_SCORE = l * o * c
				let D = this.model.Nav_Details[realIndex].EVALUATE_SCORE
				if (D >= 320) {
					this.model.Nav_Details[realIndex].EVALUATE_LEVELName = "重大风险";
				} else if (D >= 160 && D < 320) {
					this.model.Nav_Details[realIndex].EVALUATE_LEVELName = "较大风险";
				} else if (D >= 70 && D < 160) {
					this.model.Nav_Details[realIndex].EVALUATE_LEVELName = "一般风险";
				} else {
					this.model.Nav_Details[realIndex].EVALUATE_LEVELName = "低风险";
				}
				this.model.Nav_Details[realIndex].EVALUATE_LEVEL = this.model.Nav_Details[realIndex].EVALUATE_LEVELName !== undefined ? this.enumsData['SKEvaluateLevelEnum'].find(item1 => item1.name === this.model.Nav_Details[
					realIndex].EVALUATE_LEVELName).code : ''

				this.$forceUpdate()
			},

			submit() {
				let i = 1
				for (let item of this.model.Nav_Details) {
					if (!item.MineTypeName) {
						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.RISK_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.SCOREL_ID) {
						uni.showToast({
							title: '顺序' + i + '风险评价L不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.SCOREE_ID) {
						uni.showToast({
							title: '顺序' + i + '风险评价E不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.SCOREC_ID) {
						uni.showToast({
							title: '顺序' + i + '风险评价C不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.EVALUATE_SCORE) {
						uni.showToast({
							title: '顺序' + i + '分值D不能为空',
							icon: 'none'
						})
						return
					}
					if (!item.EVALUATE_LEVELName) {
						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_TYPEName) {
								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.modelEdit = JSON.parse(JSON.stringify(this.model))

				this.modelEdit.Nav_Details.map(item => {
					item.PUBLISH = 'SaveAndNotify'
				})
				if (this.TaskID == null || this.TaskID == '') {
					this.modelEdit.TaskID = '00000000-0000-0000-0000-000000000000'
				} else {
					this.modelEdit.TaskID = this.TaskID
				}
				if (this.modelEdit.ORG_ID == null || this.modelEdit.ORG_ID == '')
					this.modelEdit.ORG_ID = this.ORG_ID
				this.modelEdit.ID = this.ID
				this.modelEdit.PUBLISH = 'SaveAndNotify'
				EvaluationFullUpdate(this.modelEdit).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>