<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 label="评估要求">
						<!-- 	<u--input v-model="(dataModel.Nav_Require||{}).NAME"  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_RequiresName" disabled autoHeight></u--textarea>
					<!-- 	<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.filter(i => !i.IS_DELETED)" :key="index" style="border-bottom: #ceccca 1px solid;margin-bottom: 10px;padding-bottom: 10px;">
						<u-form-item prop="Nav_Contents" :label="index+1+'.辨识区域：'" @click="handleShowSheet({title: '辨识区域', name: 'Nav_Area',itemData:item})">

							<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(item)" 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(item)"></u-icon>
									<u-icon name="arrow-down" size="12" v-if="!item.showPack" @click="handlePack(item)"></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.Nav_ProductionUnit||{}).NAME" 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="handleShowSheet({title: '风险类别', name: 'Nav_Type',itemData:item})" 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="handleShowSheet({title: '风险评价', name: 'EVALUATE_L',itemData:item})">
								<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="handleShowSheet({title: '风险评价', name: 'EVALUATE_E',itemData:item})">
								<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="handleShowSheet({title: '风险评价', name: 'EVALUATE_C',itemData:item})">
								<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" border-bottom>
								<u--input v-model="item.EVALUATE_LEVELName" p disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>

							</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" border-bottom>
								<u--input v-model="item.MARK_NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item>
							<uni-collapse class="collapse" ref="collapse">

								<uni-collapse-item title="管控措施" name="Variety components">
									<u-button type="primary" @click="handleNewControlMea(item)" color="#3d4b70">新增管控措施</u-button>
									<view v-if="item.Nav_DetailMeasures&&item.Nav_DetailMeasures.length!==0">
										<view v-for="item1 in item.Nav_DetailMeasures.filter(i => !i.IS_DELETED)" style="margin: 5px 5px;padding: 0px 10px;">
											<u-form-item label="序号" prop="HIDDEN_DESCRIPTION" border-bottom>
												<view slot="right" style="display: flex;flex-direction: row;align-items: center;">
													<u-number-box v-model="item1.NUM" integer></u-number-box>
													<u-icon @click="handleDelRowBefore(item1)" name="trash" color="#ff4d4f" size="21" style="margin-right: 20px;margin-left: 20px;"></u-icon>
												</view>

											</u-form-item>
											<u-form-item label="措施" prop="HIDDEN_DESCRIPTION">

											</u-form-item>
											<u--textarea v-model="item1.MEASURES_NAME" placeholder="请填写管控措施" autoHeight></u--textarea>
										</view>
									</view>
								</uni-collapse-item>
								<uni-collapse-item title="辨识岗位" name="Detail Posts">
									<u-button type="primary" @click="handleNewPost(item)" color="#3d4b70">新增辨识岗位</u-button>
									<view v-if="item.Nav_DetailPosts&&item.Nav_DetailPosts.length>0">

										<view v-for="(item1,index1) in item.Nav_DetailPosts.filter(i => !i.IS_DELETED)" style="padding: 10px;">
											<u-form-item :label="(index1+1)+' . '" prop="HIDDEN_PLACE" border-bottom>
												<!-- 	<u--input v-model="index1+1" disabled  disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
											</u--input> -->
												<u-icon @click="handleDelRowBefore(item1)" name="trash" color="#ff4d4f" size="21" style="margin-right: 20px;margin-left: 20px;" slot="right"></u-icon>
											</u-form-item>
											<u-form-item label="辨识部门" prop="HIDDEN_PLACE" border-bottom @click="handleShowSheet({title: '辨识部门', name: 'Nav_Department',itemData:item1})">
												<u--input v-model="(item1.Nav_Department||{}).NAME" disabled placeholder="请选择辨识部门" 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="HIDDEN_PLACE" border-bottom @click="handleShowSheet({title: '辨识岗位', name: 'Nav_ResultPostDets',itemData:item1})">
												<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
												</u-icon>
											</u-form-item>
											<u-textarea v-model="item1.Nav_ResultPostDetsName" disabled autoHeight placeholder="请选择辨识岗位"></u-textarea>
										</view>
									</view>
								</uni-collapse-item>
								<uni-collapse-item title="管控层级" name="Docs guide">
									<u-button type="primary" @click="handleNewControlLev(item)" color="#3d4b70">新增管控层级</u-button>
									<view v-if="item.Nav_DetailDeparts&&item.Nav_DetailDeparts.length>0">

										<view v-for="(item1,index1) in item.Nav_DetailDeparts.filter(i => !i.IS_DELETED)" style="padding: 10px;">
											<u-form-item borderBottom>
												<view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;flex: 1;">
													<view @click="handleShowSheet({title: '管控部门', name: 'Nav_DetailDeparts',itemData:item1})" 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(item1)" 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 borderBottom label="管控责任人" prop="HIDDEN_PLACE" border-bottom>
												<u--input v-model="((item1.Nav_Department||{}).Nav_User||{}).NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
												</u--input>
											</u-form-item>
										</view>
									</view>
								</uni-collapse-item>
							</uni-collapse>
						</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,
		transformData
	} from '../../../../utils/common'
	import {
		FMProductionUnit,
		SKEffective,
		SKMarkEnum,
		SKLevelEnum,
		CheckPeriods,
		CheckLevels,
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		EvaluationGet,
		EvaluationFullUpdate,
		getUserLists,
		GetEvaluationInfo,
		GetNewRiskAreaInfo,
		GetNewRiskTypeInfo,
		GetDepartmentInfo,
		GetRiskNameInfo,
		GetScorel,
		GetScoree,
		GetScorec,
		GetPostOrderPaged
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import {
		getEnum,
		GetEnumAnyOrder
	} 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,
						Nav_ProductionUnit: {
							NAME: ''
						},
						PRODUCTION_UNIT_ID: '',
						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: [],
					}]
				},
				dateRecitifyTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd'),
				stepsText: ['发起', '审批', '归档'],
				stepsPage: 0,
				stepsPageList: 0,
				TaskID: '',
				nowName: '',
				nowIndex: 0,
				childList: ['管控措施', '管控层级'],
				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', 'SKMarkEnum']);
		},
		methods: {
			fetchEnums(enumNames) {
				var dataParm = {
					'name': enumNames.join('|')
				}
				GetEnumAnyOrder(dataParm).then(res => {
					let newd = transformData(res, enumNames)
					this.enumsData = newd[0];
					// 生成文本列表（如需要）
					this.enumsText = newd[1]
					this.loadData();
				})
			},
			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_ProductionUnit');
				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
					let Nav_RequiresName = ''
					if (this.model.Nav_Requires && this.model.Nav_Requires.length > 0) {
						this.model.Nav_Requires.map(item => {
							if (item.Nav_Require&&item.Nav_Require.NAME !== null) {
								Nav_RequiresName += item.Nav_Require.NAME + ' ';
							}
						})
					}
					this.model.Nav_RequiresName = Nav_RequiresName
					this.model.Nav_Details.map(item => {
						item['showPack'] = false
						item.MARK_NAME = item.MARK !== undefined ? this.enumsData['SKMarkEnum'].find(item1 => item1.code === item.MARK)?.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 : '';
						})
						if (item.Nav_DetailPosts && item.Nav_DetailPosts.length > 0) {
							item.Nav_DetailPosts.map(item1 => {
								if (item1.Nav_PostDetails && item1.Nav_PostDetails.length > 0) {
									let Nav_ResultPostDetsName = ''
									item1.Nav_PostDetails.map(item2 => {
										if (item2.Nav_Post && item2.Nav_Post.NAME !== null) {
											Nav_ResultPostDetsName += item2.Nav_Post.NAME + ' ';
										}
									})
									item1.Nav_ResultPostDetsName = Nav_ResultPostDetsName
								}
							})

						}
					})
					this.stepLoad = false

				})
			},
			handlePack(item) {
				item.showPack = item.showPack == false ? true : false
				this.$forceUpdate()

			},
			handleChangeUnit(name, item) {
				if (name == 'SKProductionUnit') {
					const json = initFilter(this.ORG_ID)
					getRequest(json, "/FM/UserProductionUnitSet/OrderPaged").then(res => {
						this.comPickerInfo = {
							showSheet: true,
							columns: [res],
							dataItem: item,
							name: name
						}
					})


				} else {
					this.comPickerInfo = {
						showSheet: true,
						columns: [this.enumsText[name]],
						dataItem: item,
						name: name
					}
				}

			},
			onConfirmPicker(e) {
				if (this.comPickerInfo.name == 'SKProductionUnit') {
					this.comPickerInfo.dataItem.Nav_ProductionUnit = e.value[0]
					this.comPickerInfo.dataItem.PRODUCTION_UNIT_ID = e.value[0].ID

				} 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,
					Nav_ProductionUnit: {
						NAME: ''
					},
					PRODUCTION_UNIT_ID: '',
					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: [],
					Nav_DetailPosts:[],
					MARK: this.enumsData['SKMarkEnum'].find(item1 => item1.name === '新增').code,
					MARK_NAME: this.enumsData['SKMarkEnum'].find(item1 => item1.name === '新增').name,
					ID: guid()
				})

				this.model.Nav_Details = [...this.model.Nav_Details]
			},
			handleNewControlMea(item) {
				item.Nav_DetailMeasures.push({
					NUM: 1,
					ID: guid(),
					RISK_EVALUATION_DETAIL_ID: item.ID,
					MEASURES_NAME: '',
					IS_DELETED: false,
				})
			},
			handleNewPost(item) {
				item.Nav_DetailPosts.unshift({
					ID: guid(),
					RISK_EVALUATION_DETAIL_ID: item.ID,
					Nav_Department: {
						NAME: ''
					},
					DEPARTMENT_ID: '',
					Nav_PostDetails: [],
					IS_DELETED: false,
				})
			},
			handleNewControlLev(item) {
				item.Nav_DetailDeparts.push({
					DEPARTMENT_TYPE: '',
					Nav_Department: {
						NAME: ''
					},
					Nav_User: {
						NAME: ''
					},
					RISK_EVALUATION_DETAIL_ID:item.ID
				})
			},
			handleDelRowBefore(item) {
				item.IS_DELETED = true
				this.$forceUpdate()


			},
			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
			},
			async handleShowSheet(p) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "", 0, p.pageIndex ?? 1)
				let dataSelect = []
				// this.selectorInfo.defaultChecked = []
				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"
				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
								res.Data[i].code = res.Data[i].SCORE
							}
						}
						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
								res.Data[i].code = res.Data[i].SCORE
							}
						}
						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
								res.Data[i].code = res.Data[i].SCORE
							}
						}
						return res.Data
					})
				} else if (p.name == "Nav_Area") {
					dataSelect = await GetNewRiskAreaInfo(json).then(res => {
						this.selectorInfo.totalCount = res.TotalCount
						if (res.Data != 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 == "Nav_Type") {
					dataSelect = await GetNewRiskTypeInfo(json).then(res => {
						if (res.Data != 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 == "Nav_Department") {
					dataSelect = await GetDepartmentInfo(json).then(res => {
						if (res.Data != 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 == "Nav_ResultPostDets") {
					this.selectorInfo.isMultiple = true
					if (p.itemData.DEPARTMENT_ID) {
						extendRule(json, 'DEPARTMENT_ID', 1, p.itemData.DEPARTMENT_ID);
					}
					json.SelectField = ["ID", "NAME", "NAME"]
					dataSelect = await GetPostOrderPaged(json).then(res => {
						if (res.Data != undefined && res.Data.length > 0) {
							for (let i = 0; i < res.length; i++) {
								res[i].name = res.Data[i].NAME
								res[i].code = res.Data[i].CODE
							}
						}
						return res.Data
					})
					if (p.itemData.Nav_PostDetails && p.itemData.Nav_PostDetails.length > 0) {
						// this.selectorInfo.defaultChecked = []

						p.itemData.Nav_PostDetails.filter(i => !i.IS_DELETED).forEach(e => {
							if (e.Nav_Post != null && e.Nav_Post.NAME != null)
								defaultChecked.push(e.Nav_Post)
						})
					} else {
						defaultChecked = null
					}
				} else if (p.name == 'Nav_DetailDeparts') {
					json.Include=['Nav_User']
					dataSelect = await GetDepartmentInfo(json).then(res => {
						if (res.Data != 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
					}
				} 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
				if (this.selectorInfo.name == 'EVALUATE_L' || this.selectorInfo.name == 'EVALUATE_E' || this.selectorInfo.name == 'EVALUATE_C') {
					if (this.selectorInfo.name == 'EVALUATE_L') {
						this.selectorInfo.itemData.Nav_SCOREL = e;
						this.selectorInfo.itemData.SCOREL_ID = e.ID;
					} else if (this.selectorInfo.name == 'EVALUATE_E') {
						this.selectorInfo.itemData.Nav_SCOREE = e;
						this.selectorInfo.itemData.SCOREE_ID = e.ID;
					} else if (this.selectorInfo.name == 'EVALUATE_C') {
						this.selectorInfo.itemData.Nav_SCOREC = e;
						this.selectorInfo.itemData.SCOREC_ID = e.ID;
					}

					let l = this.selectorInfo.itemData.Nav_SCOREL.SCORE
					let o = this.selectorInfo.itemData.Nav_SCOREE.SCORE
					let c = this.selectorInfo.itemData.Nav_SCOREC.SCORE
					this.selectorInfo.itemData.EVALUATE_SCORE = Math.round(l * o * c)
					let D = this.selectorInfo.itemData.EVALUATE_SCORE
					if (D >= 320) {
						this.selectorInfo.itemData.EVALUATE_LEVELName = "重大风险";
					} else if (D >= 160 && D < 320) {
						this.selectorInfo.itemData.EVALUATE_LEVELName = "较大风险";
					} else if (D >= 70 && D < 160) {
						this.selectorInfo.itemData.EVALUATE_LEVELName = "一般风险";
					} else {
						this.selectorInfo.itemData.EVALUATE_LEVELName = "低风险";
					}
					this.selectorInfo.itemData.EVALUATE_LEVEL = this.selectorInfo.itemData.EVALUATE_LEVELName !== undefined ? this.enumsData['SKEvaluateLevelEnum'].find(item1 => item1.name === this.selectorInfo.itemData
						.EVALUATE_LEVELName).code : ''

					this.$forceUpdate()
				}

				if (this.selectorInfo.name == 'Nav_Area') {

					this.selectorInfo.itemData.Nav_Area = e
					this.selectorInfo.itemData.AREA_ID = e.ID
				} else if (this.selectorInfo.name == 'Nav_Type') {
					this.selectorInfo.itemData.Nav_Type = e
					this.selectorInfo.itemData.TYPE_ID = e.ID
				} else if (this.selectorInfo.name == 'Nav_Department') {
					this.selectorInfo.itemData.Nav_Department = e
					this.selectorInfo.itemData.DEPARTMENT_ID = e.ID
				} else if (this.selectorInfo.name == 'Nav_DetailDeparts') {
					this.selectorInfo.itemData.Nav_Department = e
					this.selectorInfo.itemData.DEPARTMENT_ID = e.ID
					this.selectorInfo.itemData.Nav_User = e.Nav_User
					this.selectorInfo.itemData.USER_ID = e.Nav_User?.ID

				} else if (this.selectorInfo.name == 'Nav_ResultPostDets') {
					let listArea = []
					let areaShow = ''
					if (e.length > 0) {
						e.forEach((item, i) => {
							if (item.name != null || item.NAME != null) {
								if (i > 0) {
									areaShow += ' '
								}
								listArea.push({
									ID: guid(),
									RISK_EVALUATION_DETAIL_POST_ID: this.selectorInfo.itemData.ID,
									POST_ID: item.ID,
									ORG_ID: item.ORG_ID,
									Nav_Post: item
								})
								areaShow += item.NAME
							}
						})
					}
					this.selectorInfo.itemData.Nav_PostDetails = listArea
					this.selectorInfo.itemData.Nav_ResultPostDetsName = areaShow
				}


			},


			submit() {
				let i = 1
				for (let item of this.model.Nav_Details.filter(i => !i.IS_DELETED)) {
					if (!item.PRODUCTION_UNIT_ID) {
						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.Nav_DetailMeasures.filter(i => !i.IS_DELETED).length !== 0) {
						for (let item1 of item.Nav_DetailMeasures.filter(i => !i.IS_DELETED)) {
							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.filter(i => !i.IS_DELETED).length !== 0) {
						for (let item1 of item.Nav_DetailDeparts.filter(i => !i.IS_DELETED)) {
							if (!item1.DEPARTMENT_TYPEName) {
								uni.showToast({
									title: '顺序' + i + '管控层级不能为空',
									icon: 'none'
								})
								return
							}
							if (!item1.Nav_Department.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>