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

					<view style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;">基本信息填写</view>
					<u-form-item label="发起人：" prop="Nav_User.NAME" @click="handleChangeMonitor('Nav_ApplyUser')" borderBottom>
						<u--input disabledColor="#fff" v-model="(model.Nav_ApplyUser||{}).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="handleChangeMonitor('Nav_ApplyDepartment')" borderBottom>
						<u--input disabledColor="#fff" v-model="(model.Nav_ApplyDepartment||{}).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_ProductionUnit')" borderBottom>
						<u--input v-model="(model.Nav_ProductionUnit||{}).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="CHECKDATETIME" borderBottom @click="showCheckDate(1)">
						<u--input disabled disabledColor="#fff" v-model="model.JOB_START_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="值班结束时间" 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="班次：" prop="Nav_Class.NAME" @click="handleChangeMonitor('Nav_Class')" borderBottom>
						<u--input disabledColor="#fff" v-model="(model.Nav_Class||{}).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="值班领导" @click="handleShowSheet({title: '值班领导', name: 'Nav_Users'})">
						<u-icon name="man-add" size="24" color="#3d9cff" slot="right"></u-icon>
					</u-form-item>
					<view class="tag-view" v-if="model.Nav_Users">
						<uni-tag class="tag" v-for="(i, k) in model.Nav_Users.filter(i => !i.IS_DELETED)" :key="k" :inverted="true" :text="i.Nav_User.NAME" type="primary" />
					</view>
					<view class="upload-title">附件：</view>
					<full-upload v-model="model.Nav_Files"></full-upload>
					<u-form-item label="交接班地点" prop="LOCATION" borderBottom>
						<u--input disabledColor="#ffffff" v-model="model.PLACE" border="none" inputAlign="right" fontSize="14px" placeholder="请输入地点"></u--input>
					</u-form-item>
					<u-form-item label="接班人" @click="handleShowSheet({title: '接班人', name: 'Nav_AfterUsers'})">
						<u-icon name="man-add" size="24" color="#3d9cff" slot="right"></u-icon>
					</u-form-item>
					<view class="tag-view" v-if="model.Nav_AfterUsers">
						<uni-tag class="tag" v-for="(i, k) in model.Nav_AfterUsers.filter(i => !i.IS_DELETED)" :key="k" :inverted="true" :text="i.Nav_AfterUser.NAME" type="primary" />
					</view>
				</u--form>
			</view>
			<view style="padding: 10px 16px;" v-if="stepsPageList === 0" class="bottom-button">
				<u-button type="primary" @click="stepAdd" color="#3d4b70" :loading="stepLoad">下一步</u-button>
			</view>
			<view class="card" v-if="stepsPageList === 1">
				<u--form labelWidth="auto" :model="model" ref="wForm" class="sub-form">


					<view style="position: relative;">

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

					<view style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;margin-top: 20px;">检查内容</view>
					<uni-collapse :border="false" accordion>
						<view v-for="(item, index) in model.Nav_Details.filter(i => !i.IS_DELETED)" :key="index">
							<uni-collapse-item title-border="none" :border="false">
								<template v-slot:title>
									<view class="uni-collapse-item__title-box">
										<view class="uni-collapse-item__title-text">
											{{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="CHECKDATETIME" borderBottom @click="showCheckDate(3,item)">
										<u--input disabled disabledColor="#fff" v-model="item.START_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="结束时间" prop="ENDTIME" borderBottom @click="showCheckDate(4,item)">
										<u--input disabled disabledColor="#fff" v-model="item.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_DetailAreas',itemData:item})">
										<u-icon name="man-add" size="24" color="#3d9cff" slot="right"></u-icon>
									</u-form-item>
									<view class="tag-view" v-if="item.Nav_DetailAreas">
										<uni-tag class="tag" v-for="(i, k) in item.Nav_DetailAreas.filter(i => !i.IS_DELETED)" :key="k" :inverted="true" :text="i.Nav_Area.NAME" type="primary" />
									</view>
									<u-form-item label="现场情况描述：">

									</u-form-item>
									<u--textarea autoHeight v-model="item.DESCRIPTION" placeholder="请输入现场情况描述" border="surround"></u--textarea>
									<u-form-item label="发现问题：">

									</u-form-item>
									<u--textarea autoHeight v-model="item.QUESTION" placeholder="请输入发现问题" border="surround"></u--textarea>
									<u-form-item label="处置措施：">

									</u-form-item>
									<u--textarea autoHeight v-model="item.MEASURE" placeholder="请输入处置措施" border="surround"></u--textarea>
									<u-form-item label="现场责任人：" prop="Nav_User.NAME" @click="handleShowSheet({title: '现场责任人', name: 'Nav_User',itemData:item})" borderBottom>
										<u--input disabledColor="#fff" v-model="(item.Nav_User||{}).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="交接事项：">

									</u-form-item>
									<u--textarea autoHeight v-model="item.ITEM" placeholder="请输入交接事项" border="surround"></u--textarea>

									<u-form-item label="附件" prop="CHECKSTANDARD">
									</u-form-item>
									<full-upload v-model="item.Nav_DetailFiles" :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: column;" v-if="stepsPageList === 1" 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
	} from '../../../../utils/common'
	import {
		FMProductionUnit,
		CheckPeriods,
		CheckLevels,
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		getUserLists,
		getDepartmentLists,
		getProductionUnitLists,
		getClassLists,
	} from '../../../../services/safe';
	import {
		getUser,
		getLeaderWellRecord,
		fullFOLeaderWellRecord,
		getRiskArea
	} from '../../../../services/apply/FOServices/FOServices.js'
	import stepTitle from '@/components/custom/step-title.vue'
	import swipeActionItem from '../../../../uni_modules/uview-ui/libs/config/props/swipeActionItem';
	import {
		getEnum
	} from '../../../../services/common';
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				showDelModalIndex: undefined,
				showDelModalIndex1: undefined,
				subsectionList: ['无隐患', '有隐患', '不涉及'],
				isMultiple: false,
				defaultChecked: [],
				RiskLevel: ['一般', '重大'],
				showPopupUnit: false,
				UnitDefaultIndex: [0],
				RiskLevelDefaultIndex: [0],
				UnitLists: [],
				showPopupRiskLevel: false,
				TypeLists: [],
				showPopupType: false,
				TypeDefaultIndex: [0],
				PeriodLists: [],
				showPopupPeriod: false,
				PeriodDefaultIndex: [0],
				LevelLists: [],
				showPopupStep: false,
				showPopupLevel: false,
				curTotalStep: 0,
				stepLists: [],
				LevelDefaultIndex: [0],
				showPopupDate: false,
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				checkListData: {},
				monitorLists: [],
				currentOperateMonitor: {},
				showPopupMonitor: false,
				curTotalMonitor: 0,
				model: {
					Nav_ApplyUser: {
						NAME: ''
					},
					Nav_ApplyDepartment: {
						NAME: ''
					},
					Nav_ProductionUnit: {
						NAME: ''
					},
					Nav_Class: {
						NAME: ''
					},
					Nav_Details: [],
				},
				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();
		},
		methods: {
			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');
					getLeaderWellRecord(json).then(res => {
						this.stepLoad = false
						this.model = res;
						this.model.ID = this.ID

					})
				}
			},
			stepAdd() {
				this.stepsPageList = this.stepsPageList + 1
			},
			stepReduce() {
				this.stepsPageList = this.stepsPageList - 1
			},
			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_ApplyUser') {
					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_ApplyDepartment') {
					extendRule(json, 'ENABLE_STATUS', 1, '0')
					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_Class') {
					extendInclude(json, 'Nav_ClassDetail');
					getClassLists(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_ProductionUnit') {

					getProductionUnitLists(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_ApplyUser') {
					this.model.Nav_ApplyUser = val
					this.model.APPLY_USER_ID = val.ID
				} else if (this.currentOperateMonitor == 'Nav_ApplyDepartment') {
					this.model.Nav_ApplyDepartment = val
					this.model.APPLY_DEPARTMENT_ID = val.ID
				} else if (this.currentOperateMonitor == 'Nav_Class') {
					this.model.Nav_Class = val
					this.model.CLASS_ID = val.ID

				} else if (this.currentOperateMonitor == 'Nav_ProductionUnit') {
					this.model.Nav_ProductionUnit = val
					this.model.PRODUCTION_UNIT_ID = val.ID
				}
				this.currentOperateMonitor = val
			},
			handleNewCheckArea() {
				this.model.Nav_Details.push({
					ID: guid(),
					LEADER_WELL_RECORD_ID: this.model.ID,
					ORG_ID: uni.getStorageSync('orgId'),
					START_DATE: '',
					END_DATE: '',
					Nav_DetailAreas: [],
					DESCRIPTION: '',
					QUESTION: '',
					MEASURE: '',
					Nav_User: {
						NAME: ''
					},
					ITEM: '',
					Nav_DetailFiles: []

				})
			},
			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_Users') {
					this.selectorInfo.isMultiple = true


					// extendRule(json, 'DEVICE_STATUS', 1, '1');
					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
					})
					if (this.model.Nav_Users && this.model.Nav_Users.length > 0 && this.model.Nav_Users[0]
						.Nav_User != null) {
						// this.selectorInfo.defaultChecked = []
						this.model.Nav_Users.forEach(e => {
							defaultChecked.push(e.Nav_User)
						})
					} else {
						defaultChecked = null
					}
				} else if (p.name == 'Nav_AfterUsers') {
					this.selectorInfo.isMultiple = true


					// extendRule(json, 'DEVICE_STATUS', 1, '1');
					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
					})
					if (this.model.Nav_AfterUsers && this.model.Nav_AfterUsers.length > 0 && this.model.Nav_AfterUsers[0]
						.Nav_AfterUser != null) {
						// this.selectorInfo.defaultChecked = []
						this.model.Nav_AfterUsers.forEach(e => {
							defaultChecked.push(e.Nav_AfterUser)
						})
					} else {
						defaultChecked = null
					}
				} else if (p.name == 'Nav_DetailAreas') {

					this.selectorInfo.isMultiple = true
					json.Sort = 'NAME'
					// extendRule(json, 'CHECKOBJECT', 1, this.model.CHECKOBJECT);
					dataSelect = await getRiskArea(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
								// res[i].code = res[i].CODE
							}
						}
						return res.Data
					})
					// Nav_Law=> Nav_Standard
					if (p.itemData.Nav_DetailAreas && p.itemData.Nav_DetailAreas
						.length > 0 && p.itemData.Nav_DetailAreas[0]
						.Nav_Area != null) {
						p.itemData.Nav_DetailAreas.forEach(e => {
							if (e.Nav_Area != null && e.Nav_Area.NAME != null && e.Nav_Area.NAME
								.length > 0)
								defaultChecked.push(e.Nav_Area)
						})
					} else {
						defaultChecked = null
					}
				} else if (p.name == 'Nav_User') {
					json.Sort = 'NAME'
					extendRule(json, 'ENABLE_STATUS', 1, '0')
					// extendRule(json, 'CHECKOBJECT', 1, this.model.CHECKOBJECT);
					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
								// res[i].code = res[i].CODE
							}
						}
						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
				const validDetails = this.model.Nav_Details.filter(i => !i.IS_DELETED);
				const index = this.selectorInfo.index;
				const realIndex = this.model.Nav_Details.findIndex(item => item === validDetails[index]);
				if (this.selectorInfo.name == 'Nav_Users') {
					let listArea = []
					if (e.length > 0) {
						e.forEach((item, i) => {
							if (item.name != null || item.NAME != null) {
								listArea.push({
									ID: guid(),
									LEADER_WELL_RECORD_ID: this.model.ID,
									USER_ID: item.ID,
									ORG_ID: item.ORG_ID,
									Nav_User: item
								})
							}
						})
					}
					this.model.Nav_Users = listArea
					// this.model.RiskAreaNAME = areaShow
				} else if (this.selectorInfo.name == 'Nav_AfterUsers') {
					let listArea = []
					if (e.length > 0) {
						e.forEach((item, i) => {
							if (item.name != null || item.NAME != null) {
								listArea.push({
									ID: guid(),
									LEADER_WELL_RECORD_ID: this.model.ID,
									AFTER_USER_ID: item.ID,
									ORG_ID: item.ORG_ID,
									Nav_AfterUser: item
								})
							}
						})
					}
					this.model.Nav_AfterUsers = listArea
				} else if (this.selectorInfo.name == 'Nav_DetailAreas') {
					let listCheckProofs = []
					if (e.length > 0) {
						e.forEach((item, i) => {
							if (item.name != null) {
								listCheckProofs.push({
									ID: guid(),
									LEADER_WELL_RECORD_DETAIL_ID: this.selectorInfo.itemData.ID,
									AREA_ID: item.ID, //LAW_ID
									ORG_ID: item.ORG_ID,
									Nav_Area: item
								})
							}
						})
					}
					this.selectorInfo.itemData.Nav_DetailAreas = listCheckProofs
				} else if (this.selectorInfo.name == 'Nav_User') {
					this.selectorInfo.itemData.Nav_User = e
					this.selectorInfo.itemData.USER_ID = e.ID
				}


			},
			showCheckDate(dataIndex, item) {
				this.dateTimePickerInfo = {
					showCheckDate: true,
					defaultDateTime: dataIndex == 3 || dataIndex == 4 ? uni.$u.timeFormat(new Date(), 'hh:MM') : uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					dataIndex: dataIndex,
					item: item,
					mode: dataIndex == 3 || dataIndex == 4 ? 'time' : 'datetime'
				}
			},
			//隐藏控件 显示时间
			handleCheckDate(e) {
				if (this.dateTimePickerInfo.dataIndex == 1) {
					this.model.JOB_START_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')
				} else if (this.dateTimePickerInfo.dataIndex == 3) {
					this.dateTimePickerInfo.item.START_DATE = e.value
				} else if (this.dateTimePickerInfo.dataIndex == 4) {
					this.dateTimePickerInfo.item.END_DATE = e.value
				}
				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_Class
				delete this.modelEdit.Nav_ProductionUnit
				if (this.modelEdit.Nav_Details && this.modelEdit.Nav_Details.length > 0) {
					this.modelEdit.Nav_Details.map(item => {
						item.PUBLISH = type
						delete item.Nav_User
						if (item.Nav_DetailAreas && item.Nav_DetailAreas.length > 0) {
							item.Nav_DetailAreas.map(item1 => {
								delete item1.Nav_Area
							})
						}
					})
				}

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


			}

		}



	}
</script>

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