<template>
	<view class="todo-page">
		<view class="background"></view>
		<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="Nav_User.NAME" borderBottom>
						<u--input disabledColor="#fff" v-model="(model.Nav_OperationStep||{}).NAME" disabled fontSize="14px" customStyle="margin:0px;display:flex;padding:3px 0px" border="none" inputAlign="right">
						</u--input>
					</u-form-item>
					<u-form-item label="动火区域：" prop="Product_Unit" borderBottom>
						<u--input v-model="(model.Nav_Area||{}).NAME" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>
					<u-form-item label="动火地点" prop="LOCATION" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.JOB_LOCATION" border="none" inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="动火方式：" prop="Nav_Type" borderBottom>
						<u--input v-model="(model.Nav_Type||{}).NAME" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>

					<u-form-item label="动火计划开始时间" prop="CHECKDATETIME" borderBottom>
						<u--input disabled disabledColor="#fff" v-model="model.JOB_DATE" border="none" inputAlign="right" fontSize="14px"></u--input>

					</u-form-item>
					<u-form-item label="动火计划结束时间" prop="ENDTIME" borderBottom>
						<u--input disabled disabledColor="#fff" v-model="model.JOB_END_DATE" border="none" inputAlign="right" fontSize="14px"></u--input>

					</u-form-item>
					<u-form-item label="动火具体事项" prop="LOCATION" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.JOB_CONTENT" border="none" inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="存在的风险">

					</u-form-item>
					<view class="tag-view" v-if="model.Nav_Risks">
						<uni-tag class="tag" v-for="(i, k) in model.Nav_Risks.filter(i => !i.IS_DELETED)" :key="k" :inverted="true" :text="i.RISK_NAME" type="primary" />
					</view>
					<view class="upload-title">附件：</view>
					<full-upload v-model="model.Nav_Files" :isShowBtn='false'></full-upload>
					<u-form-item required label="动火作业现场条件验收情况" prop="LOCATION">

					</u-form-item>
					<u--textarea v-model="model.COMPLETED_CONDITION" placeholder="请输入动火作业现场条件验收情况" border="surround"></u--textarea>
					<u-form-item required label="是否可以动火：" prop="Nav_User.NAME" @click="handleChange('FOYesOrNoEnum')" borderBottom>
						<u--input disabledColor="#fff" v-model="model.IS_FIREName" disabled placeholder="请选择是否可以动火" suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px"
							customStyle="margin:0px;display:flex;padding:3px 0px" border="none" inputAlign="right">
						</u--input>
					</u-form-item>
					<u-form-item required label="动火实际开始时间" prop="CHECKDATETIME" borderBottom @click="showCheckDate(1)">
						<u--input disabled disabledColor="#fff" v-model="model.ACT_DATE" placeholder="请选择时间" border="none" inputAlign="right" fontSize="14px"></u--input>
						<u-icon style="margin-left: 4px;" name="arrow-down" size="12"></u-icon>
					</u-form-item>
					<u-form-item required label="矿调度人员：" prop="Nav_User.NAME" @click="handleChangeMonitor('Nav_DispatchUser')" borderBottom>
						<u--input disabledColor="#fff" v-model="(model.Nav_DispatchUser||{}).NAME" disabled placeholder="请选择矿调度人员" suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px"
							customStyle="margin:0px;display:flex;padding:3px 0px" border="none" inputAlign="right">
						</u--input>
					</u-form-item>
					<view class="upload-title">现场条件验收附件：</view>
					<full-upload v-model="model.Nav_FireFiles"></full-upload>
				</u--form>
			</view>
			<view style="padding: 10px 16px;" v-if="stepsPageList === 0" class="bottom-button">
				<u-button type="primary" @click="stepAdd" color="#3d4b70" :loading="stepLoad">下一步</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>
					<uni-collapse :border="false" accordion>
						<view v-for="(item, index) in model.Nav_Details.filter(i => !i.IS_DELETED)" :key="index">
							<uni-collapse-item title-border="none" :border="false">
								<template v-slot:title>
									<view class="uni-collapse-item__title-box">
										<view class="uni-collapse-item__title-text">
											{{item.CONTENT?index+1+'.'+item.JOB_STEPName+'--'+item.CONTENT:index+1+'.'}}
										</view>
										<view @click.stop style="display: flex;flex-direction: row;align-items: center;">
											<u-switch v-model="item.IS_CONFIRM_NEW" @change="changeConfirm($event,item)" size="18" style="margin-right: 10px;"></u-switch>
											<u-icon @click="handleDelRowBefore(item)" name="trash" color="#ff4d4f" size="21" style="margin-right: 10px;"></u-icon>
										</view>
									</view>
								</template>
								<view class="content" style="padding: 0px 0px 0px 10px;">
									<u-form-item label="顺序：" prop="Nav_User.NAME" @ borderBottom>
										<u--input disabledColor="#fff" v-model="item.NUM" placeholder="请输入顺序" type="number" fontSize="14px" customStyle="margin:0px;display:flex;padding:3px 0px" border="none"
											inputAlign="right">
										</u--input>
									</u-form-item>
									<u-form-item label="作业阶段：" prop="Nav_User.NAME" @click="handleChange('FOJobStepEnum',item)" borderBottom>
										<u--input disabledColor="#fff" v-model="item.JOB_STEPName" disabled placeholder="请选择作业阶段" suffixIcon="arrow-down" suffixIconStyle="font-size:12px" fontSize="14px"
											customStyle="margin:0px;display:flex;padding:3px 0px" border="none" inputAlign="right">
										</u--input>
									</u-form-item>
									<u-form-item label="作业流程及安全措施：">

									</u-form-item>
									<u--textarea v-model="item.CONTENT" placeholder="请输入作业流程及安全措施" border="surround"></u--textarea>
								</view>


							</uni-collapse-item>
						</view>
					</uni-collapse>
					<view style="padding: 10px 16px;display: flex;flex-direction: row;">
						<u-button type="primary" @click="handleNewCheckArea" color="#3d4b70">新增</u-button>
						<!-- <u-button type="primary" @click="handleNewCheckList" color="#3d4b70" style="margin-left: 5px;">检查清单</u-button> -->
					</view>
				</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>
			<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" />
			<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>
			<people-selector :defaultChecked="peopleSelectOption.defaultChecked" :show="peopleSelectOption.showSelector" @select="handleSelectorPeople" @close="peopleSelectOption.showSelector = false">
			</people-selector>
			<u-datetime-picker :show="dateTimePickerInfo.showCheckDate" v-model='dateTimePickerInfo.defaultDateTime' @confirm="handleCheckDate" @close="dateTimePickerInfo.showCheckDate = false"
				@cancel="dateTimePickerInfo.showCheckDate = false" :mode="dateTimePickerInfo.mode"></u-datetime-picker>
			<query-selector :show="showPopupMonitor" :total="curTotalMonitor" :lists="monitorLists" :defaultValue="currentOperateMonitor.NAME" @close="handleClosePopupMonitor" @search="handleSearchMonitor"
				@select="handleSelectedMonitor" />
		</view>
	</view>
</template>

<script>
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		extendIgnoreDataRule,
		guid,
		initFilter,
		initFilterGroup
	} from '../../../../utils/common'
	import {
		FMProductionUnit,
		CheckPeriods,
		CheckLevels,
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		getUserLists,
		getDepartmentLists,
		getProductionUnitLists,
		getClassLists,
	} from '../../../../services/safe';
	import {
		getUser,
		getFOFireJob,
		fullFOFireJob,
		getRiskArea,
		getWorkLists,
		getFireType,
		getSafeUser,
		getSKEnterpriseLibrary,
		getRelatedUserType,
		getRenewalTrain,
		getAnalyzeDetail
	} from '../../../../services/apply/FOServices/FOServices.js'
	import stepTitle from '@/components/custom/step-title.vue'
	import swipeActionItem from '../../../../uni_modules/uview-ui/libs/config/props/swipeActionItem';
	import {
		getEnum
	} from '../../../../services/common';
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				showDelModalIndex: undefined,
				showDelModalIndex1: undefined,
				subsectionList: ['无隐患', '有隐患', '不涉及'],
				isMultiple: false,
				defaultChecked: [],
				RiskLevel: ['一般', '重大'],
				showPopupUnit: false,
				UnitDefaultIndex: [0],
				RiskLevelDefaultIndex: [0],
				UnitLists: [],
				showPopupRiskLevel: false,
				TypeLists: [],
				showPopupType: false,
				TypeDefaultIndex: [0],
				PeriodLists: [],
				showPopupPeriod: false,
				PeriodDefaultIndex: [0],
				LevelLists: [],
				showPopupStep: false,
				showPopupLevel: false,
				curTotalStep: 0,
				stepLists: [],
				LevelDefaultIndex: [0],
				showPopupDate: false,
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				checkListData: {},
				monitorLists: [],
				currentOperateMonitor: {},
				showPopupMonitor: false,
				curTotalMonitor: 0,
				model: {
					Nav_ApplyUser: {
						NAME: ''
					},
					Nav_ApplyDepartment: {
						NAME: ''
					},
					Nav_ProductionUnit: {
						NAME: ''
					},
					Nav_OperationStep: {
						NAME: ''
					},
					Nav_FireDepartment: {
						NAME: ''
					},
					Nav_FireUser: {
						NAME: ''
					},
					Nav_SafeUser: {
						NAME: ''
					},
					Nav_Area: {
						NAME: ''
					},
					Nav_Type: {
						NAME: ''
					},
					Nav_DispatchUser: {
						NAME: ''
					},
					IS_HOLIDAY: false,
					IS_HOLIDAYName: '否',
					EVALUATE_LEVEL: '',
					EVALUATE_LEVELName: '',
					JOB_LOCATION: '',
					JOB_CONTENT: '',
					JOB_DATE: '',
					JOB_END_DATE: '',
					Nav_Users: [],
					Nav_Risks: [],
					Nav_Details: [],
					Nav_Files: []
				},
				peopleSelectOption: {
					showSelector: false,
					value: null,
					index: 0,
					defaultChecked: []
				},
				dateTimePickerInfo: {
					showCheckDate: false,
					dataIndex: undefined,
					defaultDateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					value: '',
					name: '',
					mode: ''
				},
				selectorInfo: {
					name: 'user',
					isMultiple: false,
					showPopup: false,
					totalCount: 0,
					title: '考核结果选择',
					itemData: {},
					dataItem: {},
					index: 0,
					columns: [],
					dataLists: [],
					defaultText: '',
					defaultChecked: []
				},
				comPickerInfo: {
					showSheet: false,
					dataItem: {},
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				dateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM'),
				stepsText: ['发起', '归档'],
				stepsPage: 0,
				stepsPageList: 0,
				Pu: '',
				Check_Type_ID: '',
				TypeListres: {},
				TaskID: '',
				poparr: '',
				currentOperateStep: {},
				chooseCheckContent: '',
				chooseCheckArea: '',
				currentOperateArea: {},
				areaLists: [],
				curTotalArea: 0,
				showPopupArea: false,
				nowIndex: {},
				nowName: '',
				newCheckList: false,
				stepLoad: true,
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {} // 存储枚举文本列表（用于下拉选择等场景）

			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.model.ID = option.ID ? option.ID : '';
			this.ID = option.ID ? option.ID : '';
			// this.loadData();
			this.fetchEnums(['FOYesOrNoEnum', 'FOJobStepEnum']);
		},
		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() {
				if (this.ID == undefined || this.ID == '') {
					this.stepLoad = false
					this.model.Nav_Details = []
					if (this.ID == undefined || this.ID == '')
						this.ID = guid()
					this.model.ID = this.ID
					const orgId = uni.getStorageSync('orgId')
					const json = initFilter(orgId, "", "")
					let userid = uni.getStorageSync('appInfo').User.ID
					extendRule(json, 'ID', 1, userid);
					extendInclude(json, 'Nav_Department.Nav_Unit');
					extendIgnoreDataRule(json)
					// extendInclude(json, 'Nav_Details.Nav_DetailContents.Nav_Question');
					getUser(json).then(res => {
						this.stepLoad = false
						this.model.Nav_ApplyUser.NAME = res.NAME
						this.model.APPLY_USER_ID = res.ID
						this.model.Nav_ApplyDepartment.NAME = res.Nav_Department.NAME
						this.model.APPLY_DEPARTMENT_ID = res.DEPARTMENT_ID
						this.model.Nav_ProductionUnit.NAME = res.Nav_Department.Nav_Unit.NAME
						this.model.PRODUCTION_UNIT_ID = res.Nav_Department.PRODUCTION_UNIT_ID

					})
				} else {
					const orgId = uni.getStorageSync('orgId')
					const json = initFilter(orgId, "", "")
					extendRule(json, 'ID', 1, this.ID);
					extendInclude(json, 'Nav_OperationStep');
					extendInclude(json, 'Nav_Area');
					extendInclude(json, 'Nav_Type');
					extendInclude(json, 'Nav_Risks');
					extendInclude(json, 'Nav_Files.Nav_ImgFile');
					extendInclude(json, 'Nav_DispatchUser');
					extendInclude(json, 'Nav_FireFiles.Nav_ImgFile');
					extendInclude(json, 'Nav_Details');
					extendInclude(json, 'Nav_Details.Nav_DetailFiles.Nav_ImgFile');
					extendIgnoreDataRule(json)
					// extendInclude(json, 'Nav_Details.Nav_DetailContents.Nav_Question');
					getFOFireJob(json).then(res => {
						this.stepLoad = false
						this.model = res;
						this.model.ID = this.ID
						if (this.model.Nav_Details && this.model.Nav_Details.length > 0) {
							this.model.Nav_Details.map(item => {
								item.JOB_STEPName = item.JOB_STEP !== '' && item.JOB_STEP !== undefined ? this.enumsData['FOJobStepEnum'].find(item1 => item1.code === item.JOB_STEP).name : ''
							})
						}

					})
				}
			},
			changeConfirm(e,item){
				item.IS_CONFIRM_NEW =e
			},
			stepAdd() {
				
				const isBlank = (value) => {
					return typeof value !== 'string' || value.trim() === '';
				};
				if (isBlank(this.model.COMPLETED_CONDITION) ||
					isBlank(this.model.IS_FIREName) ||
					isBlank(this.model.ACT_DATE) ||
					isBlank(this.model.DISPATCH_USER_ID)
				) {
					uni.$showErrorInfo('请检查必填项，必填项不能为空')
				} else {
					this.stepsPageList = this.stepsPageList + 1
				}

			},
			stepReduce() {
				this.stepsPageList = this.stepsPageList - 1
			},
			stepAddTwo() {
				this.stepsPageList = this.stepsPageList + 1
			},
			handleChange(name, item) {
				this.comPickerInfo = {
					showSheet: true,
					columns: [this.enumsData[name]],
					name: name,
					itemData: item
				}
			},
			onConfirmPicker(e) {
				if (this.comPickerInfo.name == 'FOYesOrNoEnum') {
					this.model.IS_FIREName = e.value[0].name
					this.model.IS_FIRE = e.value[0].ID
				} else if (this.comPickerInfo.name == 'FOJobStepEnum') {
					this.comPickerInfo.itemData.JOB_STEPName = e.value[0].name
					this.comPickerInfo.itemData.JOB_STEP = e.value[0].ID
				}

				this.comPickerInfo = {
					showSheet: false,
					columns: [],
					title: '',
					formIndex: undefined
				}
			},
			handleClosePopupMonitor() {
				this.showPopupMonitor = false
			},
			handleChangeMonitor(name) {
				this.currentOperateMonitor = name
				this.showPopupMonitor = true
				this.handleSearchMonitor('init')
			},
			handleSearchMonitor(val, pageIndex) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "NAME", '', pageIndex)

				if (val !== 'init') {
					const tempGroup = initFilterGroup(false);
					extendGroupRule(tempGroup, 'NAME', 9, val)
					extendFilterGroup(json, tempGroup);
				}
				json.Limit = 20
				if (pageIndex) {
					json.Start = (pageIndex - 1) * 20;
				}

				if (this.currentOperateMonitor == 'Nav_DispatchUser') {
					getUserLists(json).then(res => {
						if (res.IsSuccessful) {
							this.monitorLists = res.Data.map(i => {
								return {
									...i,
									name: i.NAME,
									code: i.CODE
								}
							})
							this.curTotalMonitor = res.TotalCount
						}
					})
				}

			},
			handleSelectedMonitor(val) {
				this.showPopupMonitor = false
				if (this.currentOperateMonitor == 'Nav_DispatchUser') {
					this.model.Nav_DispatchUser = val
					this.model.DISPATCH_USER_ID = val.ID

				}
				this.currentOperateMonitor = val
			},
			getDetail() {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, this.model.OPERATION_STEP_ID)
				getAnalyzeDetail(json).then(res => {

					if (res) {
						this.model.Nav_Details = res.Nav_Details
						this.model.EVALUATE_LEVEL = res.EVALUATE_LEVEL
						this.model.AUDIT_LEVEL = res.AUDIT_LEVEL
						this.model.EVALUATE_LEVELName = this.enumsData['SKEvaluateLevelEnum'].find(item => item.code === res.EVALUATE_LEVEL).name
						if (this.model.Nav_Details && this.model.Nav_Details.length > 0) {
							this.model.Nav_Details.map(item1 => {
								item1.JOB_STEPName = this.enumsData['FOJobStepEnum'].find(item => item.code === item1.JOB_STEP).name
							})
						}
					}


				})
			},
			getGetSafeUser() {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, this.model.FIRE_DEPARTMENT_ID)
				getSafeUser(json).then(res => {

					if (res) {
						this.model.Nav_SafeUser = res
						this.model.SAFE_USER_ID = res.ID
					} else {
						this.model.Nav_SafeUser = {
							NAME: ''
						}
						this.model.SAFE_USER_ID = ''
					}


				})
			},
			handleAddUser() {
				this.model.Nav_Users.push({
					ID: guid(),
					FIRE_JOB_ID: this.model.ID,
					ORG_ID: uni.getStorageSync('orgId'),
					Nav_UserType: {
						NAME: ''
					},
					Nav_User: {
						NAME: ''
					},
					Nav_Train: {
						CERTIFICATE_NAME: ''
					},
					CERTIFICATE_CODE: '',
					USER_TYPE_ID: '',
					USER_ID: '',
					TRAIN_ID: '',
					Nav_UserFiles: []

				})
			},
			handleNewCheckArea() {
				this.model.Nav_Details.push({
					ID: guid(),
					FIRE_JOB_ID: this.model.ID,
					ORG_ID: uni.getStorageSync('orgId'),
					NUM: 1,
					JOB_STEP: '',
					CONTENT: '',

				})
			},
			handleDelRowBefore(item) {
				this.nowIndex = item
				this.showDelModalIndex = 1

			},
			confirmDel() {
				this.nowIndex.IS_DELETED = true
				this.showDelModalIndex = undefined
			},
			cacelDel() {
				this.showDelModalIndex = undefined
			},
			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 == 'Nav_Risks') {
					if (p.val) {
						extendRule(json, 'RISK_NAME', 9, p.val);
					}
					json.Sort = 'RISK_NAME'
					this.selectorInfo.isMultiple = true


					// extendRule(json, 'DEVICE_STATUS', 1, '1');
					if (this.model.AREA_ID !== '' && this.model.AREA_ID !== undefined) {
						extendRule(json, 'AREA_ID', 1, this.model.AREA_ID)
					}

					dataSelect = await getSKEnterpriseLibrary(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].RISK_NAME
							}
						} else {
							uni.showToast({
								title: '暂无信息',
								icon: 'none'
							})
						}
						return res.Data
					})
					if (this.model.Nav_Risks && this.model.Nav_Risks.length > 0 && this.model.Nav_Risks[0]
						.Nav_Risk != null) {
						// this.selectorInfo.defaultChecked = []
						this.model.Nav_Risks.forEach(e => {
							defaultChecked.push(e.Nav_Risk)
						})
					} else {
						defaultChecked = null
					}
				} else if (p.name == 'Nav_UserType') {
					dataSelect = await getRelatedUserType(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 == 'Nav_User') {
					extendRule(json, 'ENABLE_STATUS', 1, '0')
					dataSelect = await getUserLists(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 == 'Nav_Train') {
					if (p.val) {
						extendRule(json, 'CERTIFICATE_NAME', 9, p.val);
					}
					json.Sort = 'CERTIFICATE_NAME'
					if (p.itemData.USER_ID !== '' && p.itemData.USER_ID !== undefined) {
						extendRule(json, 'USER_ID', 1, p.itemData.USER_ID)
					}

					extendInclude(json, 'Nav_Files.Nav_ImgFile')
					dataSelect = await getRenewalTrain(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].CERTIFICATE_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,
					itemData: this.selectorInfo.itemData
				}
				this.handleShowSheet(p)
			},

			handleSelected(e) {
				this.selectorInfo.showPopup = false
				if (this.selectorInfo.name == 'Nav_Risks') {
					let listArea = []
					if (e.length > 0) {
						e.forEach((item, i) => {
							if (item.name != null || item.NAME != null) {
								listArea.push({
									ID: guid(),
									FIRE_JOB_ID: this.model.ID,
									ENTERPRISE_LIBRARY_ID: item.ID,
									ORG_ID: item.ORG_ID,
									RISK_NAME: item.RISK_NAME,
									Nav_Risk: item
								})
							}
						})
					}
					this.model.Nav_Risks = listArea
					// this.model.RiskAreaNAME = areaShow
				} else if (this.selectorInfo.name == 'Nav_UserType') {
					this.selectorInfo.itemData.Nav_UserType = e
					this.selectorInfo.itemData.USER_TYPE_ID = e.ID
				} else if (this.selectorInfo.name == 'Nav_User') {
					this.selectorInfo.itemData.Nav_User = e
					this.selectorInfo.itemData.USER_ID = e.ID
				} else if (this.selectorInfo.name == 'Nav_Train') {
					this.selectorInfo.itemData.Nav_Train = e
					this.selectorInfo.itemData.TRAIN_ID = e.ID
					this.selectorInfo.itemData.CERTIFICATE_CODE = e.CERTIFICATE_CODE
					if (e.Nav_Files && e.Nav_Files.length > 0) {
						e.Nav_Files.map(item => {
							this.selectorInfo.itemData.Nav_UserFiles.push(item)
						})
					}
					// this.selectorInfo.itemData.Nav_UserFiles =this.selectorInfo.itemData.Nav_UserFiles.push(e.Nav_Files) 
				}


			},
			showCheckDate(dataIndex, item) {
				this.dateTimePickerInfo = {
					showCheckDate: true,
					defaultDateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					dataIndex: dataIndex,
					item: item,
					mode: 'datetime'
				}
			},
			//隐藏控件 显示时间
			handleCheckDate(e) {
				if (this.dateTimePickerInfo.dataIndex == 1) {
					this.model.ACT_DATE = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				}
				this.dateTimePickerInfo.showCheckDate = false

			},
			submit() {
				this.modelEdit = JSON.parse(JSON.stringify(this.model))
				delete this.modelEdit.Nav_ApplyDepartment
				delete this.modelEdit.Nav_ApplyUser
				delete this.modelEdit.Nav_Area
				delete this.modelEdit.Nav_FireDepartment
				delete this.modelEdit.Nav_FireUser
				delete this.modelEdit.Nav_OperationStep
				delete this.modelEdit.Nav_ProductionUnit
				delete this.modelEdit.Nav_SafeUser
				delete this.modelEdit.Nav_Type
				delete this.modelEdit.Nav_DispatchUser
				if (this.model.Nav_Risks && this.model.Nav_Risks.length > 0) {
					this.model.Nav_Risks.map(item => {
						delete item.Nav_Risk
					})
				}
				if (this.modelEdit.Nav_Users && this.modelEdit.Nav_Users.length > 0) {
					this.modelEdit.Nav_Users.map(item => {
						item.PUBLISH = 'SaveAndNotify'
						delete item.Nav_Train
						delete item.Nav_User
						delete item.Nav_UserType
						if (item.Nav_UserFiles && item.Nav_UserFiles.length > 0) {
							item.Nav_UserFiles.map(item1 => {
								item1.FIRE_JOB_USER_ID = item.ID
							})
						}
					})
				}

				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.PUBLISH = 'SaveAndNotify'
				fullFOFireJob(this.modelEdit).then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})


			}

		}



	}
</script>

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