<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="dataModel" 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="dataModel.Product_Unit" 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="dataModel.Check_Type" 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_Period" >
						<u--input v-model="dataModel.Check_Period" 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_Level" >
						<u--input v-model="dataModel.Check_Level" 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="dataModel.Check_Date" 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="dataModel.UserNames" border="none" inputAlign="right" disabled class="richtext"></rich-text>
					<view class="upload-title">附件：</view>
					<full-upload v-model="dataModel.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="dataModel" ref="wForm" class="sub-form">


					<view style="position: relative;">

						<view style="position: absolute;left: -10px;color: #3d4b70;top: -3px;">*</view>
					</view>

					<view style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;margin-top: 20px;">检查内容</view>
					<view v-for="(item,index) in dataModel.Nav_CheckRecordDetails" :key="index" style="border-bottom: #ceccca 1px solid;margin-bottom: 10px;padding-bottom: 10px;">
						<u-form-item :label="index+1+'.区域:'" @click="handleChangeStep('Area',[index])">
							<u--input v-model="item.Nav_RiskArea.NAME" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
							</u--input>
							<u-icon name="arrow-down" size="12" style="margin-left: 10px;"></u-icon>
							<view @click.stop>
								<u-icon @click="handleDelRowBefore('Area',[index])" name="trash" color="#ff4d4f" size="21" style="margin-left: 20px;"></u-icon>
							</view>

						</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 v-show="!!item.Nav_CheckRecordDetailUsers.length" class="tag-view">
							<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="检查内容" @click="handleNewCheckContent(item,index)">
							<u-button text="新增检查内容" size="small" type="primary" style="margin-left: 40%;"></u-button>
							<!-- <u-icon name="plus-circle" size="24" color="#3d9cff" slot="right"></u-icon> -->
						</u-form-item>
						<view v-for="(item1,index1) in item.Nav_DetailContents" :key="index1" style="padding: 0px 5px;">
							<u-form-item prop="Nav_Contents">

								<view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;flex: 1;">
									<view @click="handleChangeStep('Content',[index,index1])" style="flex: 1;">
										{{item1.Nav_Contents?index1+1+'.'+item1.Nav_Contents.CHECKCONTENT:index1+1+'.'}}
									</view>
									<view class="action" style="display: flex;flex-direction: row;align-items: center;justify-content: space-around;">
										<u-icon @click="handleDelRowBefore('Content',[index,index1])" name="trash" color="#ff4d4f" size="21" style="margin-right: 20px;"></u-icon>
										<u-icon name="arrow-up" size="12" v-if="item1.showPack" @click="handlePack(index, index1)"></u-icon>
										<u-icon name="arrow-down" size="12" v-if="!item1.showPack" @click="handlePack(index, index1)"></u-icon>
									</view>
								</view>
							</u-form-item>

							<!-- <u-form-item label="" prop="HIDDEN_LEVEL" @click="handleCheckContent(item1)">
								<u--input v-model="item1.Nav_Contents.CHECKCONTENT" suffixIcon="arrow-down" suffixIconStyle="font-size: 12px" disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item> -->
							<!-- <u--textarea v-model="item1.Nav_Contents.CHECKCONTENT" placeholder="请输入内容" v-if="item1.Nav_Contents"></u--textarea> -->
							<view v-if="item1.showPack==true">
								<u-subsection :list="subsectionList" :current="item1.CHECK_RESULTS" @change="sectionChange($event,[index,index1])"></u-subsection>
								<!-- <u-form-item label="检查依据" @click="handleChangeStep('Inspection',[index,index1])">
									<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
									</u-icon>
								</u-form-item>
								<u--textarea v-model="item1.Nav_CheckRecordDetailBasicsName" disabled placeholder="请选择检查依据" maxlength="-1"></u--textarea>
								<u-form-item label="判定标准" prop="CHECKSTANDARD" border-bottom>
									<u--input v-model="item1.CHECKSTANDARD" placeholder="请填写判定标准" disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
									</u--input>
								</u-form-item> -->
								<u-form-item label="隐患描述" @click="handleChangeStep('Description',[index,index1])">
									<u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12">
									</u-icon>
								</u-form-item>
								<u--textarea v-model="item1.Nav_Question.DESCREPTION" disabled placeholder="请选择隐患描述" maxlength="-1"></u--textarea>
								<u-form-item label="隐患等级" prop="HIDDEN_LEVEL" @click="handleChangeRiskLevel(index,index1)" border-bottom>
									<u--input v-model="item1.HIDDEN_LEVEL" 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="item1.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="item1.Nav_CheckRecordDetailFiles" :isShowBtn='true' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>
							</view>

						</view>
					</view>
					<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>
			<u-picker :show="showPopupUnit" :columns="UnitLists" @confirm="confirmUnit" @cancel="cancelUnit" :defaultIndex="UnitDefaultIndex"></u-picker>
			<u-picker :show="showPopupRiskLevel" :columns="RiskLevel" @confirm="confirmRiskLevel" @cancel="cancelRiskLevel" :defaultIndex="RiskLevelDefaultIndex"></u-picker>
			<u-picker :show="showPopupType" :columns="TypeLists" @confirm="confirmType" @cancel="cancelType" :defaultIndex="TypeDefaultIndex"></u-picker>
			<u-picker :show="showPopupPeriod" :columns="PeriodLists" @confirm="confirmPeriod" @cancel="cancelPeriod" :defaultIndex="PeriodDefaultIndex"></u-picker>
			<u-picker :show="showPopupLevel" :columns="LevelLists" @confirm="confirmLevel" @cancel="cancelLevel" :defaultIndex="LevelDefaultIndex"></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
	} from '../../../../utils/common'
	import {
		FMProductionUnit,
		CheckPeriods,
		CheckLevels,
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		GetCheckContentsInfo,
		GetIdentityUserRecord,
		RecordFullUpdate,
		GetRiskAreaInfo,
		CheckTypeNewOrderPaged,
		SKEnterpriseLibrary,
		GetCheckInspection,
		GetHiddenScripList
	} 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'
	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: {},
				dataModel: {
					Nav_Files: [],
					Check_Type: '',
					Check_Period: '',
					Check_Level: '',
					SECURITY_INSPECTION_NOTICE_ID:null,
					Check_Date: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					Nav_CheckRecordDetails: [{
						Nav_RiskArea: {
							NAME: ''
						},
						Nav_Users: [],
						Nav_DetailContents: {
							Nav_Contents: {
								CHECKCONTENT: ''
							},
							HIDDEN_LEVEL:null,
						}

					}],
				},
				model: {
					CHECK_TYPE_ID: '',
					SECURITY_INSPECTION_NOTICE_ID:null,
					PLANCHECKFREQUENCY: '',
					DEPARTMENT_TYPE: 0,
					CHECK_TIME: '',
					ORG_ID: '',
					Nav_CheckRecordDetails: [{
						RISK_AREA_ID: '',
						CHECK_CONTENTS_ID: '',
						Nav_CheckRecordDetailBasics: [],
						CHECKSTANDARD: '',
						Nav_CheckNoticeDetailUsers: {
							USER_ID: ''
						},


					}],

				},
				peopleSelectOption: {
					showSelector: false,
					value: null,
					index: 0,
					defaultChecked: []
				},
				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,

			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.model.ID = option.ID ? option.ID : '';
			this.ID = option.ID ? option.ID : '';
			this.getCheckType()
		},
		methods: {
			loadData() {
				// this.getCheckType()
				// const json = {}
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				extendRule(json, 'ID', 1, this.ID);
				extendRule(json, 'TASK_ID', 1, this.TaskID);
				extendIgnoreDataRule(json)
				// extendInclude(json, 'Nav_CheckRecordDetails.Nav_DetailContents.Nav_Question');
				GetIdentityUserRecord(json).then(res => {
					this.stepLoad = false
					// this.model = res;
					this.dataModel.SECURITY_INSPECTION_NOTICE_ID = res.SECURITY_INSPECTION_NOTICE_ID
					this.dataModel.Check_Type = res.Nav_CheckType ? res.Nav_CheckType.NAME : ''
					this.Check_Type_ID = res.CHECK_TYPE_ID
					this.dataModel.Check_Period = res.PLANCHECKFREQUENCY == 0 ? '无' : res.PLANCHECKFREQUENCY == 10 ? '每天' : res.PLANCHECKFREQUENCY == 20 ? '每周' : res.PLANCHECKFREQUENCY == 30 ? '每月' : res
						.PLANCHECKFREQUENCY == 40 ? '每季度' : res.PLANCHECKFREQUENCY == 50 ? '每半年' : res.PLANCHECKFREQUENCY == 60 ? '每年' : '每班'
					this.dataModel.Check_Level = res.DEPARTMENT_TYPE == 0 ? '部门' : res.DEPARTMENT_TYPE == 1 ? '车间' : res.DEPARTMENT_TYPE == 2 ? '班组' : res.DEPARTMENT_TYPE == 3 ? '公司' : '岗位'
					this.dataModel.Nav_Files = res.Nav_CheckRecordFiles
					this.dataModel.Check_Date = res.CHECK_TIME
					this.dataModel.UserNames = res.CHECK_PERSON
					
					this.dataModel.Product_Unit = MineTypeName[res.MineType]
					this.stepsPage = res.STATUS == 0 ? 0 : 1
					this.dataModel.Nav_CheckRecordDetails = res.Nav_CheckRecordDetails ? res.Nav_CheckRecordDetails : []
					if (this.dataModel.Nav_CheckRecordDetails.length > 0) {
						this.dataModel.Nav_CheckRecordDetails.map((item, index) => {
							if (item.Nav_DetailContents && item.Nav_DetailContents.length > 0) {
								item.Nav_DetailContents.map((item1, index1) => {
									if (index1 == 0 && index == 0) {
										item1['showPack'] = true
									} else {
										item1['showPack'] = false
									}
									if (!item1.Nav_Question || !item1.Nav_Question.DESCREPTION) {
										item1.Nav_Question = {
											DESCREPTION: ''
										}
									}
									if (!item1.Nav_Contents || !item1.Nav_Contents.CHECKCONTENT) {
										item1.Nav_Contents = {
											CHECKCONTENT: ''
										}
									}
									if(item1.CHECK_RESULT){
										item1.CHECK_RESULTS = Number(item1.CHECK_RESULT.toString().slice(0, 1))
									}else{
										item1.CHECK_RESULTS = 0
									}
									
									if(item1.HIDDEN_LEVEL){
										item1.HIDDEN_LEVEL = item1.HIDDEN_LEVEL == 0 ? '一般' : '重大'
									}
									
									if (item1.Nav_CheckRecordDetailBasics.length > 0) {
										let areaShow = ''
										item1.Nav_CheckRecordDetailBasics.map(o => {
											if (o.Nav_Law && o.Nav_Law.NAME) {
												areaShow += o.Nav_Law.NAME + ' 、'
											}

										})
										item1['Nav_CheckRecordDetailBasicsName'] = areaShow
									} else {
										item1['Nav_CheckRecordDetailBasicsName'] = ''
									}
								})
							}

						})
					}

				})

				
			},

			getMessage(e) {
				this.newCheckList = false
				e.forEach((itemA) => {
					let matched = false;
					let newElementB = {
						Nav_Contents: {
							CHECKCONTENT: itemA.CHECK_CONTENT
						},
						CHECK_CONTENTS_ID: itemA.CHECK_CONTENTS_ID,
						Nav_CheckRecordDetailBasics: itemA.Nav_DetailBasics,
						Nav_CheckRecordDetailBasicsName: itemA.Nav_DetailBasicsName,
						CHECKSTANDARD: itemA.CHECK_STANDARD,
						Nav_Question: {
							DESCREPTION: ''
						},
						HIDDEN_LEVEL: null,
						HIDDEN_PLACE: '',
						CHECK_RESULT: 0,
						CHECK_RESULTS: 0,
						Nav_CheckRecordDetailFiles: [],
						showPack: false
					};
					this.dataModel.Nav_CheckRecordDetails.forEach((itemB) => {
						if (itemA.AREA_NAME == itemB.Nav_RiskArea.NAME) {
							itemB.Nav_DetailContents.push(newElementB);
							matched = true;
						}
					});
					if (!matched) {
						this.dataModel.Nav_CheckRecordDetails.push({
							Nav_RiskArea: {
								NAME: itemA.AREA_NAME
							},
							RISK_AREA_ID: itemA.AREA_ID,
							Nav_CheckRecordDetailUsers: [],
							Nav_DetailContents: [newElementB],

						})
						// this.dataModel.Nav_CheckRecordDetails.push(newElementB);
					}
				});
				// this.dataModel.Nav_CheckRecordDetails.map(item=>{
				// 	if(item.)
				// })
				// this.dataModel.Nav_CheckRecordDetails.push({
				// 	Nav_RiskArea: {
				// 		NAME: ''
				// 	},
				// 	Nav_CheckRecordDetailUsers: [],
				// 	Nav_DetailContents: [],

				// })
			},
			handlePack(index, index1) {
				this.dataModel.Nav_CheckRecordDetails[index].Nav_DetailContents[index1].showPack = this.dataModel.Nav_CheckRecordDetails[index].Nav_DetailContents[index1].showPack == false ? true : false
				this.dataModel.Nav_CheckRecordDetails = [...this.dataModel.Nav_CheckRecordDetails]

			},
			sectionChange(index, item) {
				this.dataModel.Nav_CheckRecordDetails[item[0]].Nav_DetailContents[item[1]].CHECK_RESULTS = index
				if (index == 0) {
					this.dataModel.Nav_CheckRecordDetails[item[0]].Nav_DetailContents[item[1]].CHECK_RESULT = 0
				} else {
					this.dataModel.Nav_CheckRecordDetails[item[0]].Nav_DetailContents[item[1]].CHECK_RESULT = Number(index.toString() + '0')
				}
				this.dataModel.Nav_CheckRecordDetails = [...this.dataModel.Nav_CheckRecordDetails]
			},
			getCheckType() {
				const json = initFilter(this.orgId, "", "CODE", 1)
				const TypeList = []
				json.Limit = 100
				CheckTypeNewOrderPaged(json).then(res => {
					 (res.Data || res).map((item, index) => {
						TypeList.push(item.NAME)
						if (item.NAME == this.dataModel.Check_Type) {
							this.TypeDefaultIndex = [index]
						}
					})
					this.TypeListres = res.Data

				})
				this.TypeLists = [TypeList]
				this.loadData()
			},
			stepAdd() {
				// if (!this.dataModel.Check_Period) {
				// 	uni.showToast({
				// 		title: '请选择检查周期',
				// 		icon: 'none'
				// 	})
				// 	return
				// }
				// if (!this.dataModel.Check_Level) {
				// 	uni.showToast({
				// 		title: '请选择检查层级',
				// 		icon: 'none'
				// 	})
				// 	return
				// }
				// if (!this.dataModel.Check_Type) {
				// 	uni.showToast({
				// 		title: '请选择检查类型',
				// 		icon: 'none'
				// 	})
				// 	return
				// }
				// if (!this.dataModel.Product_Unit) {
				// 	uni.showToast({
				// 		title: '请选择生产单元',
				// 		icon: 'none'
				// 	})
				// 	return
				// }
				if (!this.dataModel.Check_Date) {
					uni.showToast({
						title: '请选择检查时间',
						icon: 'none'
					})
					return
				}
				this.TypeListres.map(item => {
					if (item.NAME == this.dataModel.Check_Type) {
						this.Check_Type_ID = item.ID
					}
				})
				this.stepsPageList = this.stepsPageList + 1
			},
			stepReduce() {
				this.stepsPageList = this.stepsPageList - 1
			},
			cancelRiskLevel() {
				this.showPopupRiskLevel = false
			},
			handleChangeRiskLevel(index, index1) {
				this.RiskLevel = [
					['一般', '重大']
				]
				this.showPopupRiskLevel = true
				this.poparr = [index, index1]
			},
			confirmRiskLevel(e) {
				this.dataModel.Nav_CheckRecordDetails[this.poparr[0]].Nav_DetailContents[this.poparr[1]].HIDDEN_LEVEL = e.value[0]
				this.dataModel.Product_RiskLevel = e.value[0]
				this.showPopupRiskLevel = false
			},
			cancelType() {
				this.showPopupType = false
			},
			handleChangeType() {
				// this.TypeLists = [FMProductionUnit]

				this.showPopupType = true
			},
			confirmType(e) {
				this.dataModel.Check_Type = e.value[0]

				this.showPopupType = false
			},
			handleChangeUnit() {
				this.UnitLists = [FMProductionUnit]
				this.showPopupUnit = true
			},
			cancelUnit() {
				this.showPopupUnit = false
			},
			confirmUnit(e) {
				this.dataModel.Product_Unit = e.value[0]
				this.showPopupUnit = false
			},
			cancelPeriod() {
				this.showPopupPeriod = false
			},
			handleChangePeriod() {
				this.PeriodLists = [CheckPeriods]
				this.showPopupPeriod = true
			},
			confirmPeriod(e) {
				this.dataModel.Check_Period = e.value[0]
				this.showPopupPeriod = false
			},
			cancelLevel() {
				this.showPopupLevel = false

			},
			handleChangeLevel() {
				this.LevelLists = [CheckLevels]
				CheckLevels.map((item, index) => {
					if (item == this.dataModel.Check_Level) {
						this.LevelDefaultIndex = [index]
					}
				})
				this.showPopupLevel = true
			},
			confirmLevel(e) {
				this.dataModel.Check_Level = e.value[0]
				this.showPopupLevel = false
			},
			confirmDate(e) {
				this.dataModel.Check_Date = uni.$u.timeFormat(e.value,
					'yyyy-mm-dd hh:MM:ss')
				this.dateTime = this.dataModel.Check_Date
				this.showPopupDate = false
			},
			handleChangeDate() {
				this.showPopupDate = true
			},
			cancelDate() {
				this.showPopupDate = false
			},
			handleSelectorPeople(e) {
				const {
					index: key
				} = this.peopleSelectOption
				this.dataModel.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,
						}
					})
				}
			},
			handleChangeStep(name, index) {
				this.nowName = name
				this.nowIndex = index
				// this.chooseCheckContent = [index, index1]
				this.currentOperateStep = {}
				this.showPopupStep = true
				this.handleSearchStep()
			},
			handleClosePopupStep() {
				this.showPopupStep = false
				this.isMultiple = false
				this.defaultChecked = []
				// this.showPopupCertificate = false
			},
			handleSearchStep(val, pageIndex) {
				let requestInfo = this.nowName == 'Area' ? GetRiskAreaInfo :
					this.nowName == 'Content' ? GetCheckContentsInfo :
					this.nowName == 'Inspection' ? GetCheckInspection : GetHiddenScripList
				let p = this.dataModel.Nav_CheckRecordDetails[this.nowIndex[0]].Nav_DetailContents[this.nowIndex[1]]
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "",0, pageIndex ?? 1)
				if (val) {
					extendRule(json, 'NAME', 9, val);
				}
				
				
				json.Limit = 20
				if (pageIndex) {
					json.Start = (pageIndex - 1) * json.Limit;
				}
				if (this.nowName == 'Inspection') {
					this.isMultiple = true

					if (p.Nav_CheckRecordDetailBasics && p.Nav_CheckRecordDetailBasics.length > 0) {

						p.Nav_CheckRecordDetailBasics.map(item => {
							let newId = item.LAW_ID;
							// 创建一个新对象，ID 为 item.LAW_ID，其他属性和 item 相同
							let newItem = {
								...item,
								ID: newId
							};
							// 将新对象添加到 this.defaultChecked 数组中
							this.defaultChecked.push(newItem);
						})
					} else {
						this.defaultChecked = []
					}
				} else {
					this.isMultiple = false
				}
				if (this.nowName == 'Description' && p.CHECK_CONTENTS_ID) {
					extendRule(json, 'CHECK_CONTENTS_ID', 1, p.CHECK_CONTENTS_ID);
				}
				requestInfo(json).then(res => {
					// if (res.IsSuccessful) {
							this.curTotalStep = res.TotalCount
					this.stepLists = (res.Data || res).map(i => {
						return {
							...i,
							id: i.ID,
							name: i.NAME || i.CHECKCONTENT || i.DESCREPTION,
						}
					})
				
					// }
				})
			},
			handleSelectedStep(val) {
				this.defaultChecked = []
				if (this.nowName == 'Area') {
					this.dataModel.Nav_CheckRecordDetails[this.nowIndex[0]].RISK_AREA_ID = val.ID
					this.dataModel.Nav_CheckRecordDetails[this.nowIndex[0]].Nav_RiskArea = val
				} else if (this.nowName == 'Content') {
					this.dataModel.Nav_CheckRecordDetails[this.nowIndex[0]].Nav_DetailContents[this.nowIndex[1]].CHECK_CONTENTS_ID = val.ID
					this.dataModel.Nav_CheckRecordDetails[this.nowIndex[0]].Nav_DetailContents[this.nowIndex[1]].Nav_Contents = val
				} else if (this.nowName == 'Inspection') {
					let listArea = []
					let areaShow = ''
					if (val.length > 0) {
						val.forEach((item, i) => {
							if (i > 0) {
								areaShow += ' '
							}
							let newItem = {
								...item,
								LAW_ID: item.ID,
								SECURITY_INSPECTION_RECORD_DETAIL_ID: item.ID,
								NAME: item.NAME || item.Nav_Law.NAME,
							};
							listArea.push(newItem)
							if (item.NAME && item.NAME != null) {
								areaShow += item.NAME
							} else if (item.Nav_Law && item.Nav_Law.NAME != null) {
								areaShow += item.Nav_Law.NAME
							}
						})
					}
					this.dataModel.Nav_CheckRecordDetails[this.nowIndex[0]].Nav_DetailContents[this.nowIndex[1]].Nav_CheckRecordDetailBasics = listArea
					this.dataModel.Nav_CheckRecordDetails[this.nowIndex[0]].Nav_DetailContents[this.nowIndex[1]].Nav_CheckRecordDetailBasicsName = areaShow
				} else if (this.nowName == 'Description') {
					this.dataModel.Nav_CheckRecordDetails[this.nowIndex[0]].Nav_DetailContents[this.nowIndex[1]].Nav_Question = val
					this.dataModel.Nav_CheckRecordDetails[this.nowIndex[0]].Nav_DetailContents[this.nowIndex[1]].CHECK_QUESTION_ID = val.ID
				}
				this.dataModel.Nav_CheckRecordDetails = [...this.dataModel.Nav_CheckRecordDetails]
				this.showPopupStep = false

			},
			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}`
				// })
			},
			handleNewCheckArea() {
				this.dataModel.Nav_CheckRecordDetails.push({
					Nav_RiskArea: {
						NAME: ''
					},
					Nav_CheckRecordDetailUsers: [],
					Nav_DetailContents: [],

				})
			},
			handleNewCheckContent(item, index) {
				this.dataModel.Nav_CheckRecordDetails[index].Nav_DetailContents.unshift({
					Nav_Contents: {
						CHECKCONTENT: ''
					},
					CHECK_CONTENTS_ID: '',
					Nav_CheckRecordDetailBasics: [],
					CHECKSTANDARD: '',
					Nav_Question: {
						DESCREPTION: ''
					},
					HIDDEN_LEVEL: null,
					HIDDEN_PLACE: '',
					CHECK_RESULT: 0,
					CHECK_RESULTS: 0,
					Nav_CheckRecordDetailFiles: [],
				})
				this.dataModel.Nav_CheckRecordDetails = [...this.dataModel.Nav_CheckRecordDetails]
			},
			handleDelRowBefore(name, nowIndex) {
				this.nowName = name
				this.nowIndex = nowIndex
				this.showDelModalIndex = nowIndex[0]

			},
			confirmDel() {
				if (this.nowName == 'Area') {
					this.dataModel.Nav_CheckRecordDetails.splice(this.nowIndex[0], 1)
				} else {
					this.dataModel.Nav_CheckRecordDetails[this.nowIndex[0]].Nav_DetailContents.splice(this.nowIndex[1], 1)
				}

				this.showDelModalIndex = undefined
			},
			cacelDel() {
				this.showDelModalIndex = undefined
			},
			submit() {
				for (let item of this.dataModel.Nav_CheckRecordDetails) {
					if (item.Nav_CheckRecordDetailUsers.length == 0) {
						uni.showToast({
							title: '请选择检查人员',
							icon: 'none'
						})
						return
					}
					for (let item1 of item.Nav_DetailContents) {
						if (!item1.Nav_Contents.CHECKCONTENT) {
							uni.showToast({
								title: '请填写检查内容',
								icon: 'none'
							})
							return
						}
						// if (!item1.Nav_Question.DESCREPTION) {
						// 	uni.showToast({
						// 		title: '请选择隐患描述',
						// 		icon: 'none'
						// 	})
						// 	return
						// }
					}
				}
				let period = this.dataModel.Check_Period
				let checkP = period == '无' ? 0 : period == '每天' ? 10 : period == '每周' ? 20 : period == '每月' ? 30 : period == '每季' ? 40 : period == '每半年' ? 50 : period == '每年' ? 60 : 70
				let Check_Level = this.dataModel.Check_Level
				const level = Check_Level == '部门' ? 0 : Check_Level == '车间' ? 1 : Check_Level == '班组' ? 2 : Check_Level == '公司' ? 3 : 4
				this.model.CHECK_TYPE_ID = this.Check_Type_ID //检查类型
				this.model.PLANCHECKFREQUENCY = checkP //检查周期
				this.model.DEPARTMENT_TYPE = level //检查层级
				this.model.SECURITY_INSPECTION_NOTICE_ID = this.dataModel.SECURITY_INSPECTION_NOTICE_ID
				this.model.CHECK_TIME = this.dataModel.Check_Date //检查时间
				this.model.MineType = MineTypeIndex[this.dataModel.Product_Unit]
				let arr = []
				this.dataModel.Nav_CheckRecordDetails.map(item => {
					item.Nav_DetailContents.map(item1 => {
						arr.push({
							RISK_AREA_ID: item.RISK_AREA_ID,
							CHECK_CONTENTS_ID: item1.CHECK_CONTENTS_ID,
							Nav_CheckRecordDetailBasics: item1.Nav_CheckRecordDetailBasics,
							CHECKSTANDARD: item1.CHECKSTANDARD,
							CHECK_QUESTION_ID: item1.CHECK_QUESTION_ID,
							// Nav_Question:item1.Nav_Question,
							HIDDEN_LEVEL: item1.HIDDEN_LEVEL ==null?null:item1.HIDDEN_LEVEL== '一般' ? 0 : 10,
							HIDDEN_PLACE: item1.HIDDEN_PLACE,
							CHECK_RESULT: item1.CHECK_RESULT,
							Nav_CheckRecordDetailFiles: item1.Nav_CheckRecordDetailFiles,
							Nav_CheckRecordDetailUsers: item.Nav_CheckRecordDetailUsers.map(obj => {
								return {
									USER_ID: obj.USER_ID,
									IS_DELETED: obj.IS_DELETED
								}

							})
						})
					})
				})
				this.model.Nav_CheckRecordDetails = arr
				const result = this.dataModel.Nav_Files.map((obj) => {
					return Object.assign({}, obj, {
						IMG_FILE_ID: obj.IMG_FILE_ID,
					})
					return obj
				})
				this.model.Nav_CheckRecordFiles = result
				if (this.model.ORG_ID == '') {
					this.model.ORG_ID = this.ORG_ID
				}
				this.model.ID = this.ID
				this.model.TaskID = this.TaskID
				this.model.PUBLISH = "SaveAndNotify";
				RecordFullUpdate(this.model).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>