<template>
	<view class="todo-page">
		<step-title :stepPage="stepsPage" :stepText="stepsText"></step-title>
		<view class="allview">
			<view class="card" v-if="stepsPageList === 0">
				<u--form labelWidth="auto" :model="model" ref="wForm" class="demo-ruleForm">
					<view style="position: relative;">
						<view style="position: absolute;left: -10px;color: #3d4b70;top: -3px;">*</view>
					</view>

					<view style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;">基本信息填写</view>
					<u-form-item label="生产单元：" prop="Product_Unit">
						<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-if="model.Nav_CheckType" v-model="model.Nav_CheckType.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="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 label="检查时间：" prop="CHECK_TIME" @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="UserNames">
					</u-form-item>
					<rich-text style="line-height: 30px;" autoHeight type="textarea" v-html="model.UserNames" border="none" inputAlign="right" disabled class="richtext"></rich-text> -->
					<view class="upload-title">附件：</view>
					<full-upload v-model="model.Nav_CheckRecordFiles" :isShowBtn='true' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>

				</u--form>
			</view>
			<view style="padding: 10px 16px;" v-if="stepsPageList === 0" class="bottom-button">
				<u-button type="primary" @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" :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+'.'}}
											<span v-if="item.Nav_CheckRecordDetailUsers && item.Nav_CheckRecordDetailUsers.length">
												（{{ item.Nav_CheckRecordDetailUsers.filter(i => !i.IS_DELETED).map(u => u.Nav_User.NAME).join('、') }}）
											</span>
										</view>
										<view @click.stop>
											<u-icon @click="handleDelRowBefore(index)" name="trash" color="#ff4d4f" size="21" style="margin-right: 10px;"></u-icon>
										</view>
									</view>
								</template>
								<view class="content">
									<u-form-item label="检查区域：" prop="CHECK_TIME" @click="handleShowSheetForArea(item,{title: '检查区域', name: 'Nav_RiskArea'})">
										<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 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 label="检查内容：" prop="CHECK_TIME" @click="handleShowSheetForArea(item,{title: '检查内容', name: 'Nav_Contents'})">
										<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 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="handleShowSheetForArea(item,{title: '隐患描述', name: 'Nav_Question'})">
										<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(index)">
										</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(index)">
										</u-icon>
									</view>
									<!-- <u--textarea v-model="item.Nav_Question.DESCREPTION" disabled placeholder="请选择隐患描述" maxlength="-1"></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="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">新增检查区域</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>

			<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="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>

		</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 {
		GetCheckContentsInfo,
		GetRecordSummary,
		SummaryFullUpdate,
		GetRiskAreaInfo,
		GetCheckInspection,
		GetHiddenScripList,
		GetNewRiskAreaInfo,
		CheckTypeNewOrderPaged
	} 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 {
		getEnum,
		GetEnumAnyOrder
	} from '../../../../services/common';
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				showDelModalIndex: undefined,
				showDelModalIndex1: undefined,
				subsectionList: ['无隐患', '有隐患', '不涉及'],
				curNow: 1,
				RiskLevel: ['一般', '重大'],
				showPopupUnit: false,
				UnitDefaultIndex: [0],
				showPopupRiskLevel: false,
				RiskLevelDefaultIndex: [0],
				UnitLists: [],
				TypeLists: [],
				showPopupType: false,
				isMultiple: false,
				defaultChecked: [],
				TypeDefaultIndex: [0],
				PeriodLists: [],
				showPopupPeriod: false,
				PeriodDefaultIndex: [0],
				LevelLists: [],
				showPopupStep: false,
				showPopupArea: false,
				showPopupLevel: false,
				stepLoad: true,
				curTotalStep: 0,
				curTotalArea: 0,
				stepLists: [],
				areaLists: [],
				LevelDefaultIndex: [0],
				showPopupDate: false,
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				model: {
					Nav_Files: [],
					Check_Type: '',
					Check_Period: '',
					Check_Level: '',
					SECURITY_INSPECTION_RECORD_ID: null,
					CHECK_TIME: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					Nav_CheckRecordDetails: [{
						Nav_RiskArea: {
							NAME: ''
						},
						Nav_Users: [],
						Nav_Contents: {
							CHECKCONTENT: ''
						},
						Nav_Question: {
							DESCREPTION: ''
						},


					}],
				},
				selectorInfo: {
					name: 'user',
					isMultiple: false,
					showPopup: false,
					totalCount: 0,
					title: '考核结果选择',
					dataItem: {},
					index: 0,
					columns: [],
					dataLists: [],
					defaultText: '',
					defaultChecked: []
				},
				peopleSelectOption: {
					showSelector: false,
					value: null,
					index: 0,
					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: '',
				ID: '',
				poparr: '',
				currentOperateStep: {},
				currentOperateArea: {},
				chooseCheckContent: '',
				chooseCheckArea: '',
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {} // 存储枚举文本列表（用于下拉选择等场景）

			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			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 json = {}
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				extendRule(json, 'ID', 1, this.ID);
				extendInclude(json, 'Nav_CheckType');
				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');
				json.IgnoreDataRule = true;
				extendIgnoreDataRule(json)
				GetRecordSummary(json).then(res => {
					this.stepLoad = false
					// this.model = res;
					this.model.SECURITY_INSPECTION_RECORD_ID = res.SECURITY_INSPECTION_RECORD_ID
					this.model = res;
					this.model.ID = this.ID
					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 : '';
					if (this.model.Nav_CheckRecordDetails && this.model.Nav_CheckRecordDetails.length > 0) {
						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
							}

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



					this.stepsPage = res.STATUS == 0 ? 0 : res.STATUS == 10 ? 1 : 2

				})

				// this.getCheckType()
			},

			stepAdd() {
				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,
						}
					})
				}
			},
			handleChange(name, item) {
				if (name == 'SKCheckResultEnum') {
					this.comPickerInfo = {
						showSheet: true,
						columns: [this.enumsText['SKCheckResultEnum']],
						dataItem: item,
						name: name
					}
				} else if (name == 'SKHiddenLevel') {
					this.comPickerInfo = {
						showSheet: true,
						columns: [this.enumsText['SKHiddenLevel']],
						dataItem: item,
						name: name
					}
				}

			},
			onConfirmPicker(e) {
				if (this.comPickerInfo.name == 'SKCheckResultEnum') {
					this.comPickerInfo = {
						showSheet: false,
						dataItem: this.comPickerInfo.dataItem,
						columns: [],
						title: '',
						formIndex: undefined
					}
					this.comPickerInfo.dataItem.CHECK_RESULTName = e.value[0]
					this.comPickerInfo.dataItem.CHECK_RESULT = this.enumsData['SKCheckResultEnum'][e.indexs[0]].code

				} else if (this.comPickerInfo.name == 'SKHiddenLevel') {
					this.comPickerInfo = {
						showSheet: false,
						dataItem: this.comPickerInfo.dataItem,
						columns: [],
						title: '',
						name: '',
						formIndex: undefined
					}
					this.comPickerInfo.dataItem.HIDDEN_LEVELName = e.value[0]
					this.comPickerInfo.dataItem.HIDDEN_LEVEL = this.enumsData['SKHiddenLevel'][e.indexs[0]].code
				}


			},

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





				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_Contents') {
					if (p.val) {
						extendRule(json, 'CHECKCONTENT', 9, p.val);
					}
					json.Sort = 'CHECKCONTENT'
					dataSelect = await GetCheckContentsInfo(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);
					}
					let data = this.model.Nav_CheckRecordDetails[p.index]
					if (data.CHECK_CONTENTS_ID && data.CHECK_CONTENTS_ID !== '') {
						extendRule(json, 'CHECK_CONTENTS_ID', 1, data.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
					})
				}

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

			handleSelected(e) {
				this.selectorInfo.showPopup = false
				const validDetails = this.model.Nav_CheckRecordDetails.filter(i => !i.IS_DELETED);
				const index = this.selectorInfo.index;
				const realIndex = this.model.Nav_CheckRecordDetails.findIndex(item => item === validDetails[index]);
				if (this.selectorInfo.name == 'Nav_RiskArea') {
					this.model.Nav_CheckRecordDetails[realIndex].Nav_RiskArea = e;
					this.model.Nav_CheckRecordDetails[realIndex].RISK_AREA_ID = e.ID;
				} else if (this.selectorInfo.name == 'Nav_Contents') {
					this.model.Nav_CheckRecordDetails[realIndex].Nav_Contents = e;
					this.model.Nav_CheckRecordDetails[realIndex].CHECK_CONTENTS_ID = e.ID;
				} else if (this.selectorInfo.name == 'Nav_Question') {
					this.model.Nav_CheckRecordDetails[realIndex].Nav_Question = e;
					this.model.Nav_CheckRecordDetails[realIndex].CHECK_QUESTION_ID = e.ID;
					this.model.Nav_CheckRecordDetails[realIndex].HIDDEN_LEVEL = e.QUESTION_LEVEL
					this.model.Nav_CheckRecordDetails[realIndex].HIDDEN_LEVELName = this.enumsData['SKHiddenLevel'].find(item1 => item1.code === e.QUESTION_LEVEL).name;
				}


			},
			handleNewCheckArea() {
				this.model.Nav_CheckRecordDetails.push({
					ID: guid(),
					ORG_ID: this.ORG_ID,
					SECURITY_INSPECTION_RECORD_SUMMARY_ID: this.model.ID,
					Nav_RiskArea: {
						NAME: ''
					},
					Nav_CheckRecordDetailUsers: [],
					Nav_Contents: {
						CHECKCONTENT: ''
					},
					CHECK_CONTENTS_ID: '',
					Nav_CheckRecordDetailBasics: [],
					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: [],

				})
			},
			handleDelRowBefore(index) {
				this.nowIndex = index
				this.showDelModalIndex = index

			},
			confirmDel() {
				this.model.Nav_CheckRecordDetails.splice(this.nowIndex, 1)
				this.showDelModalIndex = undefined
			},
			cacelDel() {
				this.showDelModalIndex = undefined
			},
			submit() {
				for (let item of this.model.Nav_CheckRecordDetails) {
					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
					}
				}
				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'
				// console.log(this.modelEdit,'this.modelEdit')
				SummaryFullUpdate(this.modelEdit).then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})


			}

		}



	}
</script>

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