<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 required label="作业名称：" prop="Nav_User.NAME" @click="handleChangeMonitor('Nav_OperationStep')" borderBottom>
						<u--input disabledColor="#fff" v-model="(model.Nav_OperationStep||{}).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>
					<u-form-item label="是否节假日：" prop="Nav_User.NAME" @click="handleChange('IS_HOLIDAY')" borderBottom>
						<u--input disabledColor="#fff" v-model="model.IS_HOLIDAYName" 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="作业风险等级：" prop="Nav_User.NAME" @click="handleChange('SKEvaluateLevelEnum')" borderBottom>
						<u--input disabledColor="#fff" v-model="model.EVALUATE_LEVELName" 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="Nav_User.NAME" @click="handleChangeMonitor('Nav_FireDepartment')" borderBottom>
						<u--input disabledColor="#fff" v-model="(model.Nav_FireDepartment||{}).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>
					<u-form-item required label="施工单位负责人：" prop="Nav_User.NAME" @click="handleChangeMonitor('Nav_FireUser')" borderBottom>
						<u--input disabledColor="#fff" v-model="(model.Nav_FireUser||{}).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>
					<u-form-item required label="安全生产管理人员：" prop="Nav_User.NAME" @click="handleChangeMonitor('Nav_SafeUser')" borderBottom>
						<u--input disabledColor="#fff" v-model="(model.Nav_SafeUser||{}).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>
					<u-form-item label="动火区域：" prop="Product_Unit" @click="handleChangeMonitor('Nav_Area')" borderBottom>
						<u--input v-model="(model.Nav_Area||{}).NAME" placeholder="请选择动火区域" disabled disabledColor="#ffffff" 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="LOCATION" borderBottom>
						<u--input disabledColor="#ffffff" v-model="model.JOB_LOCATION" border="none" inputAlign="right" fontSize="14px" placeholder="请输入地点"></u--input>
					</u-form-item>
					<u-form-item label="动火方式：" prop="Nav_Type" @click="handleChangeMonitor('Nav_Type')" borderBottom>
						<u--input v-model="(model.Nav_Type||{}).NAME" placeholder="请选择动火方式" disabled disabledColor="#ffffff" 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="LOCATION" borderBottom>
						<u--input disabledColor="#ffffff" v-model="model.JOB_CONTENT" border="none" inputAlign="right" fontSize="14px" placeholder="请输入地点"></u--input>
					</u-form-item>
					<u-form-item required label="动火计划开始时间" prop="CHECKDATETIME" borderBottom @click="showCheckDate(1)">
						<u--input disabled disabledColor="#fff" v-model="model.JOB_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="ENDTIME" borderBottom @click="showCheckDate(2)">
						<u--input disabled disabledColor="#fff" v-model="model.JOB_END_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 label="存在的风险" @click="handleShowSheet({title: '存在的风险', name: 'Nav_Risks'})">
						<u-icon name="arrow-down" size="12" slot="right"></u-icon>
					</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"></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_Users.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.Nav_User?index+1+'.'+item.Nav_User.NAME:index+1+'.'}}
										</view>
										<view @click.stop>
											<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="CERTIFICATE_TYPE_SHOW" @click="handleShowSheet({title: '人员类别', name: 'Nav_UserType',itemData:item})" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="(item.Nav_UserType||{}).NAME" inputAlign="right" placeholder="请选择人员类别" suffixIcon="arrow-down" suffixIconStyle="font-size:12px"
											fontSize="14px" customStyle="margin:0px;display:flex;padding:3px 9px" border="none"></u--input>
									</u-form-item>
									<u-form-item label="作业人员" prop="personName" @click="handleShowSheet({title: '作业人员', name: 'Nav_User',itemData:item})" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="(item.Nav_User||{}).NAME" inputAlign="right" placeholder="请选择作业人员" suffixIcon="arrow-down" suffixIconStyle="font-size:12px"
											fontSize="14px" customStyle="margin:0px;display:flex;padding:3px 9px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="证件名称" prop="certificateName" @click="handleShowSheet({title: '证件名称', name: 'Nav_Train',itemData:item})" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="(item.Nav_Train||{}).CERTIFICATE_NAME" inputAlign="right" placeholder="请选择人员证件" suffixIcon="arrow-down"
											suffixIconStyle="font-size:12px" fontSize="14px" customStyle="margin:0px;display:flex;padding:3px 9px" border="none"></u--input>
									</u-form-item>
									<u-form-item label="证件编号" prop="CertificateCode" borderBottom>
										<u--input disabled disabledColor="#fff" placeholder="请选择人员证件" inputAlign="right" v-model="item.CERTIFICATE_CODE" fontSize="14px" border="none"
											customStyle="margin:0px;display:flex;padding:3px 9px;"></u--input>
									</u-form-item>
									<view class="upload-title">附件：</view>
									<full-upload v-model="item.Nav_UserFiles"></full-upload>
								</view>


							</uni-collapse-item>
						</view>
					</uni-collapse>
					<view style="padding: 10px 16px;display: flex;flex-direction: row;">
						<u-button type="primary" @click="handleAddUser" 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;" class="bottom-button" v-if="stepsPageList === 1">
				<u-button type="primary" @click="stepReduce" color="#3d4b70" :plain="true" style="margin-right: 5px;">上一步</u-button>
				<u-button type="primary" @click="stepAddTwo" color="#3d4b70" style="margin-left: 5px;">下一步</u-button>
			</view>
			<view class="card" v-if="stepsPageList === 2">
				<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>
											<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: column;" v-if="stepsPageList === 2" class="bottom-button">
				<u-button @click="submit('0')" :plain="true" color="#3d4b70">保存</u-button>
				<view style="display: flex;flex-direction: row;margin-top: 10px;">
					<u-button @click="stepReduce" :plain="true" color="#3d4b70" style="margin-right: 5px;">上一步</u-button>
					<u-button @click="submit('SaveAndNotify')" color="#3d4b70" style="margin-left: 5px">提交</u-button>
				</view>
			</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,
		transformData
	} 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,
		GetEnumAnyOrder
	} 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: ''
					},
					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(['SKEvaluateLevelEnum', 'FOJobStepEnum']);
		},
		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() {
				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_ApplyUser');
					extendInclude(json, 'Nav_ApplyDepartment');
					extendInclude(json, 'Nav_Company');
					extendInclude(json, 'Nav_ProductionUnit');
					extendInclude(json, 'Nav_Class');
					extendInclude(json, 'Nav_Users');
					extendInclude(json, 'Nav_Users.Nav_User');
					extendInclude(json, 'Nav_Files.Nav_ImgFile');
					extendInclude(json, 'Nav_AfterUsers');
					extendInclude(json, 'Nav_AfterUsers.Nav_AfterUser');
					extendInclude(json, 'Nav_Details');
					extendInclude(json, 'Nav_Details.Nav_User');
					extendInclude(json, 'Nav_Details.Nav_DetailFiles.Nav_ImgFile');
					extendInclude(json, 'Nav_Details.Nav_DetailAreas.Nav_Area');

					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

					})
				}
			},
			stepAdd() {
				const isBlank = (value) => {
					return typeof value !== 'string' || value.trim() === '';
				};
				if (isBlank(this.model.Nav_OperationStep.NAME) ||
					isBlank(this.model.Nav_FireDepartment.NAME) ||
					isBlank(this.model.Nav_FireUser.NAME) ||
					isBlank(this.model.Nav_SafeUser.NAME) ||
					isBlank(this.model.JOB_DATE) ||
					isBlank(this.model.JOB_END_DATE)) {
					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: name == 'IS_HOLIDAY' ? [
						['是', '否']
					] : [this.enumsData[name]],
					name: name,
					itemData: item
				}
			},
			onConfirmPicker(e) {
				if (this.comPickerInfo.name == 'SKEvaluateLevelEnum') {
					this.model.EVALUATE_LEVELName = e.value[0].name
					this.model.EVALUATE_LEVEL = e.value[0].ID
				} else if (this.comPickerInfo.name == 'IS_HOLIDAY') {
					this.model.IS_HOLIDAYName = e.value[0]
					this.model.IS_HOLIDAY = e.value[0] == '是' ? true : false
				} 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_OperationStep') {
					extendRule(json, 'TASK_LEVEL', 2, '1')
					extendInclude(json, 'Nav_OperationStep');
					getWorkLists(json).then(res => {
						if (res.IsSuccessful) {
							this.monitorLists = res.Data.map(i => {
								return {
									...i,
									name: i.Nav_OperationStep.NAME,
									// code: i.CODE
								}
							})
							this.curTotalMonitor = res.TotalCount
						}
					})
				} else if (this.currentOperateMonitor == 'Nav_FireUser' || this.currentOperateMonitor == 'Nav_SafeUser') {
					extendRule(json, 'ENABLE_STATUS', 1, '0')
					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
						}
					})
				} else if (this.currentOperateMonitor == 'Nav_FireDepartment') {
					extendRule(json, 'ENABLE_STATUS', 1, '0')
					extendInclude(json, 'Nav_User');
					getDepartmentLists(json).then(res => {
						if (res.IsSuccessful) {
							this.monitorLists = res.Data.map(i => {
								return {
									...i,
									name: i.NAME,
									code: i.CODE
								}
							})
							this.curTotalMonitor = res.TotalCount
						}
					})
				} else if (this.currentOperateMonitor == 'Nav_Type') {
					getFireType(json).then(res => {
						if (res.IsSuccessful) {
							this.monitorLists = res.Data.map(i => {
								return {
									...i,
									name: i.NAME,
									code: i.CODE
								}
							})
							this.curTotalMonitor = res.TotalCount
						}
					})
				} else if (this.currentOperateMonitor == 'Nav_Area') {
					getRiskArea(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_OperationStep') {
					this.model.Nav_OperationStep = val.Nav_OperationStep
					this.model.OPERATION_STEP_ID = val.Nav_OperationStep.ID

					this.getDetail()
					// this.enumsData.filter
				} else if (this.currentOperateMonitor == 'Nav_FireDepartment') {
					this.model.Nav_FireDepartment = val
					this.model.FIRE_DEPARTMENT_ID = val.ID
					this.model.Nav_FireUser = val.Nav_User
					this.model.FIRE_USER_ID = val.Nav_User.ID
					this.getGetSafeUser()

				} else if (this.currentOperateMonitor == 'Nav_FireUser') {
					this.model.Nav_FireUser = val
					this.model.FIRE_USER_ID = val.ID

				} else if (this.currentOperateMonitor == 'Nav_SafeUser') {
					this.model.Nav_SafeUser = val
					this.model.SAFE_USER_ID = val.ID
				} else if (this.currentOperateMonitor == 'Nav_Area') {
					this.model.Nav_Area = val
					this.model.AREA_ID = val.ID
				} else if (this.currentOperateMonitor == 'Nav_Type') {
					this.model.Nav_Type = val
					this.model.TYPE_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({
								ID: e.ENTERPRISE_LIBRARY_ID,
								NAME: e.RISK_NAME
							})
						})
					} 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.JOB_DATE = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				} else if (this.dateTimePickerInfo.dataIndex == 2) {
					this.model.JOB_END_DATE = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				}
				this.dateTimePickerInfo.showCheckDate = false

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


			}

		}



	}
</script>

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