<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 required label="生产单元：" prop="Product_Unit" @click="handleChange('SKProductionUnit')">
						<u--input v-model="(model.Nav_ProductionUnit||{}).NAME" 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="Check_Type" >
						<u--input v-model="(model.Nav_CheckType||{}).NAME" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px"></u--input>
						
					</u-form-item>
					<u-form-item label="检查周期：" prop="PLANCHECKFREQUENCYName">
						<u--input v-model="model.PLANCHECKFREQUENCYName" 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="DEPARTMENT_TYPEName">
						<u--input v-model="model.DEPARTMENT_TYPEName" 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 required label="检查时间：" prop="Check_Date" @click="handleChangeDate()">
						<u--input v-model="model.CHECK_TIME" 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="Check_Date">
						<u--input v-model="model.CHECK_PERSON" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>
					<view class="upload-title">附件：</view>
					<full-upload v-model="model.Nav_CheckRecordFiles"></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_CheckRecordDetails.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_RiskArea?index+1+'.'+item.Nav_RiskArea.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 required label="检查区域：" prop="CHECK_TIME" @click="handleShowSheet({title: '检查区域', name: 'Nav_RiskArea',itemData:item})">
										<u--input disabled v-if="item.Nav_RiskArea" v-model="item.Nav_RiskArea.NAME" disabledColor="#ffffff" placeholder="请选择检查区域" border="none" inputAlign="right" fontSize="14px">

										</u--input>
										<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
										</u-icon>
									</u-form-item>
									<u-form-item required label="检查人员" @click="handleShowUserSelector(item,index)">
										<u-icon name="man-add" size="24" color="#3d9cff" slot="right"></u-icon>
									</u-form-item>
									<view class="tag-view" v-if="item.Nav_CheckRecordDetailUsers">
										<uni-tag class="tag" v-for="(i, k) in item.Nav_CheckRecordDetailUsers.filter(i => !i.IS_DELETED)" :key="k" :inverted="true" :text="i.Nav_User.NAME" type="primary" />
									</view>
									<u-form-item required label="检查内容：" prop="CHECK_TIME" @click="handleShowSheet({title: '检查内容', name: 'Nav_Contents',itemData:item})">
										<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
										</u-icon>
									</u-form-item>
									<u-textarea v-model="(item.Nav_Contents||{}).CHECKCONTENT" disabled placeholder="请选择检查内容"></u-textarea>
									<u-form-item borderBottom label="检查依据" prop="HIDDEN_PLACE" border-bottom>
									</u-form-item>
									<u--textarea v-model="item.Nav_CheckRecordDetailBasicsName" disabled maxlength="-1"></u--textarea>
									<u-form-item borderBottom label="判定标准" prop="HIDDEN_PLACE" border-bottom>
										<u--input v-model="item.CHECKSTANDARD" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item required label="检查情况" prop="Product_Unit" @click="handleChange('SKCheckResultEnum',item)" borderBottom>
										<u--input v-model="item.CHECK_RESULTName" disabled disabledColor="#ffffff" 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="隐患描述：" prop="CHECK_TIME" @click="handleShowSheet({title: '隐患描述', name: 'Nav_Question',itemData:item})">
										<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
										</u-icon>
									</u-form-item>
									<view v-if="item.Nav_Question" style="display: flex;flex-direction: row;justify-content: center;align-items: center;">
										<u-textarea v-model="(item.Nav_Question||{}).DESCREPTION" disabled placeholder="请选择隐患描述">
										</u-textarea>
										<u-icon style="margin-left: 10px;" name="trash" color="#ff4d4f" size="20" @click="handleDelQuestion(item)">
										</u-icon>
									</view>
									<view v-else style="display: flex;flex-direction: row;justify-content: center;align-items: center;">
										<u-textarea disabled placeholder="请选择隐患描述">
										</u-textarea>
										<u-icon style="margin-left: 10px;" name="trash" color="#ff4d4f" size="20" @click="handleDelQuestion(item)">
										</u-icon>
									</view>
									<u-form-item label="隐患具体描述：" prop="CHECK_TIME">

									</u-form-item>
									<u-textarea v-model="item.HIDDEN_DESCRIPTION" placeholder="请填写隐患具体描述">
									</u-textarea>
									<u-form-item label="隐患等级" prop="HIDDEN_LEVEL" @click="handleChange('SKHiddenLevel',item)" border-bottom>
										<u--input v-model="item.HIDDEN_LEVELName" disabled placeholder="请选择隐患等级" suffixIcon="arrow-down" suffixIconStyle="font-size: 12px" disabledColor="#ffffff" inputAlign="right"
											fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="隐患地点" prop="HIDDEN_PLACE" border-bottom>
										<u--input v-model="item.HIDDEN_PLACE" placeholder="请填写隐患地点" disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="隐患原因" prop="Nav_Reasons" @click="handleShowSheet({title: '隐患原因', name: 'Nav_Reasons',itemData:item})">
										<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12"></u-icon>
									</u-form-item>
									<u--textarea disabled autoHeight disabledColor="#fff" v-model="item.ReasonsNAME" placeholder="隐患原因" border="none"></u--textarea>


									<!-- <u-form-item label="是否新增" borderBottom>
										<u--input v-model="item.MARKName" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
										</u--input>
									</u-form-item> -->
									<u-form-item label="隐患照片" prop="CHECKSTANDARD">
									</u-form-item>
									<full-upload v-model="item.Nav_CheckRecordDetailFiles" :isShowBtn='true' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>
								</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" :plain="true" style="margin-right: 5px;">新增检查区域</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>
			<u-datetime-picker :show="showPopupDate" v-model="dateTime" mode="datetime" @confirm="confirmDate" @cancel="cancelDate"></u-datetime-picker>
			<people-selector :defaultChecked="peopleSelectOption.defaultChecked" :show="peopleSelectOption.showSelector" @select="handleSelectorPeople" @close="peopleSelectOption.showSelector = false">
			</people-selector>
			<query-selector :multiple="isMultiple" :show="showPopupStep" :total="curTotalStep" :lists="stepLists" :defaultValue="currentOperateStep.NAME" @close="handleClosePopupStep" @search="handleSearchStep"
				@select="handleSelectedStep" :defaultChecked="defaultChecked" />
			<u-modal :show="newCheckList" title="检查清单" class="modal-three" showCancelButton :showConfirmButton="false" @cancel="cancelButton">
				<checkListPage @transmitData="getMessage"></checkListPage>
			</u-modal>
		</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 {
		GetNewCheckContentsInfo,
		GetNewRiskAreaInfo,
		GetSafeInfo,
		RecordFullUpdate,
		GetHiddenScripList,
		CheckSKTypeNewOrderPaged,
		SKHiddenReason
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices';
	import stepTitle from '@/components/custom/step-title.vue'
	import swipeActionItem from '../../../../uni_modules/uview-ui/libs/config/props/swipeActionItem';
	import checkListPage from '../../../../pages/apply/subPages/SK/checkListPage.vue'
	import {
		getEnum,
		GetEnumAnyOrder
	} from '../../../../services/common';
	export default {
		components: {
			stepTitle,
			checkListPage
		},
		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: {},
				model: {
					Nav_CheckRecordFiles: [],
					Check_Type: '',
					Check_Period: '',
					Check_Level: '',
					SECURITY_INSPECTION_NOTICE_ID: null,
					CHECK_TIME: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					Nav_CheckRecordDetails: [{
						Nav_RiskArea: {
							NAME: ''
						},
						Nav_Contents: {
							CHECKCONTENT: ''
						},
						Nav_Question: {
							DESCREPTION: ''
						},
						Nav_Users: [],
						HIDDEN_LEVEL: null,
					}],
				},
				peopleSelectOption: {
					showSelector: false,
					value: null,
					index: 0,
					defaultChecked: []
				},
				selectorInfo: {
					name: 'user',
					isMultiple: false,
					showPopup: false,
					totalCount: 0,
					title: '考核结果选择',
					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.fetchEnums(['SKProductionUnit', 'SKPLANCHECKFREQUENCYEnum', 'SKDepartmentTypeEnum',
				'SKCheckResultEnum', 'SKHiddenLevel'
			]);
		},
		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 orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				extendRule(json, 'ID', 1, this.ID);
				extendInclude(json, 'Nav_CheckType');
				extendInclude(json, 'Nav_Type');
				extendInclude(json, 'Nav_ProductionUnit');
				extendInclude(json, 'Nav_CheckRecordFiles.Nav_ImgFile');
				extendInclude(json, 'Nav_CheckRecordDetails');
				extendInclude(json, 'Nav_CheckRecordDetails.Nav_RiskArea');
				extendInclude(json, 'Nav_CheckRecordDetails.Nav_CheckRecordDetailBasics.Nav_Law');
				extendInclude(json, 'Nav_CheckRecordDetails.Nav_Contents');
				extendInclude(json, 'Nav_CheckRecordDetails.Nav_Question');
				extendInclude(json, 'Nav_CheckRecordDetails.Nav_CheckRecordDetailFiles.Nav_ImgFile');
				extendInclude(json, 'Nav_CheckRecordDetails.Nav_CheckRecordDetailUsers.Nav_User');

				extendIgnoreDataRule(json)
				// extendInclude(json, 'Nav_CheckRecordDetails.Nav_DetailContents.Nav_Question');
				GetSafeInfo(json).then(res => {
					this.stepLoad = false
					this.model = res;
					this.model.ID = this.ID
					this.stepsPage = res.STATUS == 0 ? 0 : 1
					this.model.PLANCHECKFREQUENCYName = res.PLANCHECKFREQUENCY !== undefined ? this.enumsData['SKPLANCHECKFREQUENCYEnum'].find(item => item.code === res.PLANCHECKFREQUENCY).name : '';
					this.model.DEPARTMENT_TYPEName = res.DEPARTMENT_TYPE !== undefined ? this.enumsData['SKDepartmentTypeEnum'].find(item => item.code === res.DEPARTMENT_TYPE).name : '';
					this.model.Nav_CheckRecordDetails.map((item => {
						if (item.CHECK_RESULT !== undefined) {
							item.CHECK_RESULTName = this.enumsData['SKCheckResultEnum'].find(item1 => item1.code === item.CHECK_RESULT).name;
						} else {
							item.CHECK_RESULT = this.enumsData['SKCheckResultEnum'][0].code
							item.CHECK_RESULTName = this.enumsData['SKCheckResultEnum'][0].name;
						}
						if (item.HIDDEN_LEVEL !== undefined) {
							item.HIDDEN_LEVELName = this.enumsData['SKHiddenLevel'].find(item1 => item1.code === item.HIDDEN_LEVEL).name;
						} else {
							item.HIDDEN_LEVELName = ''
							item.HIDDEN_LEVEL = null
						}
						if (item.Nav_CheckRecordDetailBasics && item.Nav_CheckRecordDetailBasics.length > 0) {
							let areaShow = ''
							item.Nav_CheckRecordDetailBasics.map(o => {
								if (o.Nav_Law && o.Nav_Law.NAME) {
									areaShow += o.Nav_Law.NAME + ' 、'
								}

							})
							item.Nav_CheckRecordDetailBasicsName = areaShow
						}
						let ReasonsNAME = ''
						if (item.Nav_CheckRecordDetailReasons && item.Nav_CheckRecordDetailReasons.length > 0) {
							for (let i = 0; i < item.Nav_CheckRecordDetailReasons.length; i++) {
								ReasonsNAME += (ReasonsNAME.length > 0 ? "," : "") + item
									.Nav_CheckRecordDetailReasons[i].Nav_Reason.NAME;
							}
						}
						item.ReasonsNAME = ReasonsNAME

						// item.MARKName = this.enumsData['SKMarkEnum'].find(item1 => item1.code === item.MARK).name;
					}))

				})
			},
			stepAdd() {
				if (!this.model.PRODUCTION_UNIT_ID) {
					uni.showToast({
						title: '请选择生产单元',
						icon: 'none'
					})
					return
				}
				if (!this.model.CHECK_TIME) {
					uni.showToast({
						title: '请选择检查时间',
						icon: 'none'
					})
					return
				}
				this.stepsPageList = this.stepsPageList + 1
			},
			stepReduce() {
				this.stepsPageList = this.stepsPageList - 1
			},
			confirmDate(e) {
				this.model.CHECK_TIME = uni.$u.timeFormat(e.value,
					'yyyy-mm-dd hh:MM:ss')
				this.dateTime = this.model.CHECK_TIME
				this.showPopupDate = false
			},
			handleChangeDate() {
				this.showPopupDate = true
			},
			cancelDate() {
				this.showPopupDate = false
			},
			handleSelectorPeople(e) {
				const {
					index: key
				} = this.peopleSelectOption
				this.model.Nav_CheckRecordDetails[key].Nav_CheckRecordDetailUsers = e.map(i => {
					return {
						USER_ID: i.USER_ID,
						IS_DELETED: i.IS_DELETED,
						NAME: i.NAME,
						Nav_User: {
							NAME: i.NAME,
							ID: i.USER_ID
						}
					}
				})
			},
			handleShowUserSelector(item, index) {
				this.peopleSelectOption = {
					showSelector: true,
					value: item,
					index,
					defaultChecked: item.Nav_CheckRecordDetailUsers.map(i => {
						return {
							...i,
							NAME: i.Nav_User.NAME,
							USER_ID: i.Nav_User.ID,
						}
					})
				}
			},

			confirmButton() {
				this.newCheckList = false
			},
			cancelButton() {
				this.newCheckList = false
			},
			handleNewCheckList() {
				this.newCheckList = true
				// uni.navigateTo({
				// 	url:`/pages/apply/subPages/SK/checkListPage?ID=${this.ID}&TaskID=${this.TaskID}`
				// })
			},
			getMessage(e) {
				this.newCheckList = false
				e.forEach((itemA) => {
					this.model.Nav_CheckRecordDetails.push({
						Nav_RiskArea: {
							NAME: itemA.AREA_NAME
						},
						RISK_AREA_ID: itemA.AREA_ID,
						Nav_CheckRecordDetailUsers: [],
						Nav_Contents: {
							CHECKCONTENT: itemA.CHECK_CONTENT
						},
						CHECK_CONTENTS_ID: itemA.CHECK_CONTENTS_ID,
						Nav_Question: {
							DESCREPTION: ''
						},
						HIDDEN_LEVEL: null,
						HIDDEN_LEVELName: '',
						HIDDEN_PLACE: '',
						CHECK_RESULT: this.enumsData['SKCheckResultEnum'][0].code,
						CHECK_RESULTName: this.enumsText['SKCheckResultEnum'][0],
						Nav_CheckRecordDetailFiles: [],
						MARK: 0,
						ID: guid(),
						ORG_ID: this.ORG_ID,
						SECURITY_INSPECTION_RECORD_ID: this.model.ID,
						TaskID: this.TaskID

					})

				});
			},
			handleNewCheckArea() {
				this.model.Nav_CheckRecordDetails.push({
					ID: guid(),
					ORG_ID: this.ORG_ID,
					SECURITY_INSPECTION_RECORD_ID: this.model.ID,
					Nav_RiskArea: {
						NAME: ''
					},
					Nav_Contents: {
						CHECKCONTENT: ''
					},
					CHECK_RESULT: this.enumsData['SKCheckResultEnum'][0].code,
					CHECK_RESULTName: this.enumsText['SKCheckResultEnum'][0],
					Nav_Question: {
						DESCREPTION: ''
					},
					HIDDEN_DESCRIPTION: '',
					Nav_CheckRecordDetailReasons: [],
					ReasonsNAME:'',
					Nav_CheckRecordDetailBasics: [],
					CHECKCONTENT: '',
					HIDDEN_LEVEL: null,
					HIDDEN_LEVELName: '',
					HIDDEN_PLACE: '',
					MARK: null,
					Nav_CheckRecordDetailFiles: [],
					Nav_CheckRecordDetailUsers: [],

				})
			},
			handleDelQuestion(item) {
				item.Nav_Question = {}
				item.CHECK_QUESTION_ID = ''
				this.$forceUpdate()
			},
			handleDelRowBefore(item) {
				item.IS_DELETED = true
				this.$forceUpdate()

			},
			confirmDel() {
				this.model.Nav_CheckRecordDetails.splice(this.nowIndex, 1)
				this.showDelModalIndex = undefined
			},
			cacelDel() {
				this.showDelModalIndex = undefined
			},
			handleChange(name, item) {
				if (name == 'SKProductionUnit') {
					const json = initFilter(this.ORG_ID)
					getRequest(json, "/FM/UserProductionUnitSet/OrderPaged").then(res => {
						this.comPickerInfo = {
							showSheet: true,
							columns: [res],
							name: name
						}
					})


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

					}
				}


			},
			onConfirmPicker(e) {
				if (this.comPickerInfo.name == 'SKProductionUnit') {
					this.model.Nav_ProductionUnit = e.value[0]
					this.model.PRODUCTION_UNIT_ID = e.value[0].ID
				} else if (this.comPickerInfo.name == 'SKCheckResultEnum') {
					this.comPickerInfo.dataItem.CHECK_RESULTName = e.value[0].NAME
					this.comPickerInfo.dataItem.CHECK_RESULT = e.value[0].ID

				} else if (this.comPickerInfo.name == 'SKHiddenLevel') {
					this.comPickerInfo.dataItem.HIDDEN_LEVELName = e.value[0].NAME
					this.comPickerInfo.dataItem.HIDDEN_LEVEL = e.value[0].ID
				}
				this.comPickerInfo = {
					showSheet: false,
					dataItem: this.comPickerInfo.dataItem,
					columns: [],
					title: '',
					name: '',
					formIndex: 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




				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_RiskArea') {
					if (p.val) {
						extendRule(json, 'NAME', 9, p.val);
					}

					// extendRule(json, 'DEVICE_STATUS', 1, '1');
					dataSelect = await GetNewRiskAreaInfo(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_CheckType') {
					if (p.val) {
						extendRule(json, 'NAME', 9, p.val);
					}
					if (this.model.PRODUCTION_UNIT_ID) {
						extendRule(json, 'PRODUCTION_UNIT_ID', 1, this.model.PRODUCTION_UNIT_ID);
					}

					dataSelect = await CheckSKTypeNewOrderPaged(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_Contents') {
					if (p.val) {
						extendRule(json, 'CHECKCONTENT', 9, p.val);
					}

					json.Sort = 'CHECKCONTENT'
					dataSelect = await GetNewCheckContentsInfo(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].CHECKCONTENT
							}
						}
						return res.Data
					})
				} else if (p.name == 'Nav_Question') {
					if (p.val) {
						extendRule(json, 'DESCREPTION', 9, p.val);
					}
					if (p.itemData.CHECK_CONTENTS_ID && p.itemData.CHECK_CONTENTS_ID !== '') {
						extendRule(json, 'CHECK_CONTENTS_ID', 1, p.itemData.CHECK_CONTENTS_ID);
					}
					json.Sort = 'DESCREPTION'
					dataSelect = await GetHiddenScripList(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].DESCREPTION
							}
						}
						return res.Data
					})
				} else if (p.name == 'Nav_Reasons') {
					if (p.val) {
						extendRule(json, 'NAME', 9, p.val);
					}

					this.selectorInfo.isMultiple = true
					json.Sort = 'NAME'
					json.Limit = 20
					if (p.pageIndex) {
						json.Start = (p.pageIndex - 1) * json.Limit;
					}
					// extendRule(json, 'CHECKOBJECT', 1, this.model.CHECKOBJECT);
					dataSelect = await SKHiddenReason(json).then(res => {
						this.selectorInfo.totalCount = res.TotalCount
						if (res != undefined && res.Data != undefined && res.Data.length > 0) {
							for (let i = 0; i < res.Data.length; i++) {
								res.Data[i].name = res.Data[i].NAME
								// res[i].code = res[i].CODE
							}
						}
						return res.Data
					})
					if (p.itemData.Nav_CheckRecordDetailReasons.length > 0 && p.itemData.Nav_CheckRecordDetailReasons[0]
						.Nav_Reason != null) {
						// this.selectorInfo.defaultChecked = []
						p.itemData.Nav_CheckRecordDetailReasons.forEach(e => {
							defaultChecked.push(e.Nav_Reason)
						})
					} else {
						defaultChecked = null
					}
				}

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

			handleSelected(e) {
				this.selectorInfo.showPopup = false
				if (this.selectorInfo.name == 'Nav_RiskArea') {
					this.selectorInfo.itemData.Nav_RiskArea = e;
					this.selectorInfo.itemData.RISK_AREA_ID = e.ID;
				} else if (this.selectorInfo.name == 'Nav_Contents') {
					this.selectorInfo.itemData.Nav_Contents = e;
					this.selectorInfo.itemData.CHECK_CONTENTS_ID = e.ID;
					this.selectorInfo.itemData.CHECKSTANDARD = e.CHECK_STANDARD
					if (e.Nav_ContentsBasics && e.Nav_ContentsBasics.length > 0) {
						let areaShow = ''
						e.Nav_ContentsBasics.map(o => {
							if (o.Nav_Law && o.Nav_Law.NAME) {
								areaShow += o.Nav_Law.NAME + ' 、'
							}
						})
						this.selectorInfo.itemData.Nav_CheckRecordDetailBasicsName = areaShow
						this.selectorInfo.itemData.Nav_CheckRecordDetailBasics = e.Nav_ContentsBasics
					}else{
						this.selectorInfo.itemData.Nav_CheckRecordDetailBasicsName = ''
						this.selectorInfo.itemData.Nav_CheckRecordDetailBasics = []
					}
				} else if (this.selectorInfo.name == 'Nav_Question') {
					this.selectorInfo.itemData.Nav_Question = e;
					this.selectorInfo.itemData.CHECK_QUESTION_ID = e.ID;
					this.selectorInfo.itemData.HIDDEN_LEVEL = e.QUESTION_LEVEL
					this.selectorInfo.itemData.HIDDEN_LEVELName = this.enumsData['SKHiddenLevel'].find(item1 => item1.code === e.QUESTION_LEVEL).name;
				} else if (this.selectorInfo.name == 'Nav_CheckType') {
					this.model.Nav_CheckType = e;
					this.model.CHECK_TYPE_ID = e.ID;
				} else if (this.selectorInfo.name == 'Nav_Reasons') {
					let listProject = []
					let projectShow = ''
					if (e.length > 0) {
						e.forEach((item, i) => {
							if (item.name != null || item.NAME != null) {
								if (i > 0) {
									projectShow += ' '
								}
								listProject.push({
									ID: guid(),
									SECURITY_INSPECTION_RECORD_DETAIL_ID: this.selectorInfo.itemData.ID,
									REASON_ID: item.ID,
									ORG_ID: item.ORG_ID,
									Nav_Reason: item
								})
								projectShow += item.NAME
							}
						})
					}
					this.selectorInfo.itemData.Nav_CheckRecordDetailReasons = listProject
					this.selectorInfo.itemData.ReasonsNAME = projectShow
				}


			},
			submit() {
				for (let item of this.model.Nav_CheckRecordDetails.filter(i => !i.IS_DELETED)) {
					if (!item.Nav_CheckRecordDetailUsers || item.Nav_CheckRecordDetailUsers.length == 0) {
						uni.showToast({
							title: '请选择检查人员',
							icon: 'none'
						})
						return
					}
					if (!item.Nav_RiskArea || !item.Nav_RiskArea.NAME) {
						uni.showToast({
							title: '请选择检查区域',
							icon: 'none'
						})
						return
					}
					if (!item.Nav_Contents || !item.Nav_Contents.CHECKCONTENT) {
						uni.showToast({
							title: '请填写检查内容',
							icon: 'none'
						})
						return
					}
					// if (!item.CHECK_RESULTName) {
					// 	uni.showToast({
					// 		title: '请选择检查情况',
					// 		icon: 'none'
					// 	})
					// 	return
					// }
				}
				this.modelEdit = JSON.parse(JSON.stringify(this.model))
				delete this.modelEdit.Nav_ApplyDepartment
				delete this.modelEdit.Nav_ApplyUser
				delete this.modelEdit.Nav_CheckType

				this.modelEdit.Nav_CheckRecordDetails.map(item => {
					item.PUBLISH = 'SaveAndNotify'
					delete item.Nav_Contents
					delete item.Nav_RiskArea
					delete item.Nav_Question
				})
				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'
				RecordFullUpdate(this.modelEdit).then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})


			}

		}



	}
</script>

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

	.todo-page>>>.u-steps-item__line {
		width: 187.6px !important;
	}

	.modal-three>>>.u-modal__content {
		padding: 12px 10px 25px 10px;
	}
</style>