<!-- WB013 外包工程危险作业申请编辑 -->
<template>
	<view class="todo-page">
		<view class="background"></view>
		<view class="card" v-if="stepsPageList === 0">
			<!-- <uni-card margin="0" :is-shadow="true"> -->
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" :rules="rules" ref="wForm" errorType="border-bottom" class="demo-ruleForm">

				<!-- <u-form-item label="驳回理由" prop="AUDIT_OPINION" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.AUDIT_OPINION" border="none"
							 inputAlign="right"></u--input>
					</u-form-item> -->
				<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_Parent.Nav_Project.NAME" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.Nav_Parent.Nav_Project.NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="外包单位名称" prop="Nav_Parent.Nav_Project.UNIT_NAME" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.Nav_Parent.Nav_Project.UNIT_NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="课程名称" prop="Nav_Parent.NAME" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.Nav_Parent.NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="培训部门" prop="Nav_Parent.Nav_Department.NAME" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.Nav_Parent.Nav_Department.NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="培训讲师" prop="Nav_Parent.Nav_User.NAME" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.Nav_Parent.Nav_User.NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="最迟培训时间" prop="Nav_Parent.END_TIME" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.Nav_Parent.END_TIME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="培训总时长" prop="TOTAL_TIME" borderBottom>
					<u--input disabled disabledColor="#ffffff" v-model="model.TOTAL_TIME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="培训形式">
					<!-- <u--input disabled disabledColor="#ffffff" v-model="model.TRAIN_TYPE_SHOW" border="none" inputAlign="right" fontSize="14px"></u--input> -->
				</u-form-item>
				<u-checkbox-group v-model="model.TRAIN_TYPE_SHOW" shape="square" @change="checkboxChange($event)" style="display: flex;flex-wrap: wrap;">
					<u-checkbox :customStyle="{marginRight: '16px'}" v-for="(item, index) in checkboxList1" :key="index" :label="item.name" :name="item.name">
					</u-checkbox>
				</u-checkbox-group>
				<u-form-item label="培训内容">
					<!-- <u--input disabled disabledColor="#ffffff" v-model="model.TRAIN_CONTENT" border="none" inputAlign="right" fontSize="14px"></u--input> -->
				</u-form-item>
				<u--textarea v-model="model.TRAIN_CONTENT" placeholder="请输入培训内容"></u--textarea>
				<view class="upload-title">附件</view>
				<full-upload v-model="model.Nav_Photos" :isShowBtn='true' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>
				<uni-collapse :border="false">
					<uni-collapse-item :border="false" :open="isOnline" title="线上培训记录">
						<view class="content" style="margin: 0px 10px;">
							<!-- <u-form-item :required="isOnline" label="线上培训开始时间" prop="ONLINE_START_TIME" borderBottom @click="showCheckDate(1)">
								<u--input disabledColor="#fff" v-model="model.ONLINE_START_TIME" placeholder="请选择开始时间" border="none" inputAlign="right" fontSize="14px"></u--input>
								<u-icon style="margin-left: 4px;" name="arrow-down" size="12"></u-icon>
							</u-form-item>
							<u-form-item :required="isOnline" label="线上培训结束时间" prop="ONLINE_END_TIME" borderBottom @click="showCheckDate(2)">
								<u--input disabledColor="#fff" v-model="model.ONLINE_END_TIME" 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_Project.UNIT_NAME" borderBottom>
								<u--input disabled disabledColor="#ffffff" v-model="model.ONLINE_TOTAL_TIME" border="none" inputAlign="right" fontSize="14px"></u--input>
							</u-form-item> -->
							<u-form-item label="线上课件:" prop="Nav_ListSourceOn" @click="handleShowSheet({title: '线上课件', name: 'Nav_ListSourceOn'})">
								<u-icon style="margin-left: 4px;" name="arrow-down" size="12" slot="right"></u-icon>
							</u-form-item>
							<u-textarea v-model="model.Nav_ListSourceOns" disabled autoHeight placeholder="请选择线上课件"></u-textarea>
						</view>
					</uni-collapse-item>
					<uni-collapse-item :border="false" :open="isOffline" title="线下培训记录">
						<view class="content" style="margin: 0px 10px;">
							<u-form-item :required="isOffline" label="线下培训开始时间" prop="OFFLINE_START_TIME" borderBottom @click="showCheckDate(3)">
								<u--input disabledColor="#fff" v-model="model.OFFLINE_START_TIME" placeholder="请选择开始时间" border="none" inputAlign="right" fontSize="14px"></u--input>
								<u-icon style="margin-left: 4px;" name="arrow-down" size="12"></u-icon>
							</u-form-item>
							<u-form-item :required="isOffline" label="线下培训结束时间" prop="OFFLINE_END_TIME" borderBottom @click="showCheckDate(4)">
								<u--input disabledColor="#fff" v-model="model.OFFLINE_END_TIME" 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_Project.UNIT_NAME" borderBottom>
								<u--input disabled disabledColor="#ffffff" v-model="model.OFFLINE_TOTAL_TIME" border="none" inputAlign="right" fontSize="14px"></u--input>
							</u-form-item>
							<u-form-item label="线下课程:" prop="Nav_ListSourceOn" @click="handleShowSheet({title: '线下课程', name: 'Nav_ListSourceOff'})">
								<u-icon style="margin-left: 4px;" name="arrow-down" size="12" slot="right"></u-icon>
							</u-form-item>
							<u-textarea v-model="model.Nav_ListSourceOffs" disabled autoHeight placeholder="请选择线下课程"></u-textarea>
							<u-form-item :required="isOffline" label="培训地点" prop="TRAIN_ADDR" borderBottom>
								<u--input placeholder="请填写培训地点" disabledColor="#ffffff" v-model="model.TRAIN_ADDR" border="none" inputAlign="right" fontSize="14px"></u--input>
							</u-form-item>
							<u-form-item label="是否触发在线考试" prop="ISNEEDDEAL" borderBottom>
								<u-switch v-model="model.IS_CREATE_TEST" slot="right"></u-switch>
								<!-- @change="change" -->
								<!-- <u--input disabledColor="#fff" v-model="item.ISNEEDDEAL" border="none"
									inputAlign="right"></u--input> -->
							</u-form-item>
						</view>
					</uni-collapse-item>
				</uni-collapse>
			</u--form>

			<!-- </uni-card> -->
		</view>
		<view style="padding: 10px 16px;" v-if="stepsPageList === 0" class="bottom-button">
			<u-button type="primary" :disabled="isLoadOK" @click="stepAdd" color="#3d4b70">下一步</u-button>
		</view>
		<view class="card" v-if="stepsPageList === 1">
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm" class="sub-form">
				<uni-collapse :border="false" accordion>
					<view v-for="(item, index) in model.Nav_Users.filter(i => !i.IS_DELETED)" :key="index">
						<uni-collapse-item title-border="none" :border="false" :open="true">
							<template v-slot:title>
								<view class="uni-collapse-item__title-box">
									<view class="uni-collapse-item__title-text">
										{{index+1+'.'+item.Nav_User.NAME}}
									</view>
									<view @click.stop>
										<u-icon @click="handleDelRowBefore(item)" name="trash" color="#ff4d4f" size="21" style="margin-right: 10px;"></u-icon>
										<!-- <u-icon name="arrow-down" size="12"></u-icon> -->
									</view>
								</view>
							</template>
							<view class="content" style="margin: 0px 10px;">
								<u-form-item label="姓名" prop="Nav_User.NAME" borderBottom @click="handleShowSheetForArea(item,{title: '姓名', name: 'UserName'})">
									<u--input disabled disabledColor="#fff" v-model="item.Nav_User.NAME" 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_User.SEX_SHOW" borderBottom>
									<u--input disabled disabledColor="#fff" v-model="item.Nav_User.SEX_SHOW" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
								<u-form-item label="手机号码" prop="ID_CARD" borderBottom>
									<u--input disabled disabledColor="#fff" v-model="item.Nav_User.PHONE" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
								<view v-if="isOffline&&!isOnline&&!model.IS_CREATE_TEST">
									<u-form-item label="分数" prop="SCORE" borderBottom>
										<u--input disabledColor="#fff" v-model="item.SCORE" border="none" inputAlign="right" fontSize="14px"></u--input>
									</u-form-item>
									<u-form-item label="考核结果" prop="EXAMINATION_RESULTS" borderBottom @click="handleChange( item)">
										<u--input disabledColor="#fff" v-model="item.EXAMINATION_RESULTS_SHOW" border="none" inputAlign="right" fontSize="14px"></u--input>
										<u-icon style="margin-left: 4px;" name="arrow-down" size="12"></u-icon>
									</u-form-item>
									<view class="upload-title">附件</view>
									<full-upload v-model="item.Nav_Files" :isShowBtn='true' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>
								</view>
							</view>


						</uni-collapse-item>
					</view>
				</uni-collapse>
				<u-button text="新增" type="primary" @click="handleAdd"></u-button>
			</u--form>

		</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-datetime-picker :show="dateTimePickerInfo.showCheckDate" v-model='dateTimePickerInfo.defaultDateTime' @confirm="handleCheckDate" @close="dateTimePickerInfo.showCheckDate = false"
			@cancel="dateTimePickerInfo.showCheckDate = false"></u-datetime-picker>
		<u-picker :show="comPickerInfo.showSheet" :columns="comPickerInfo.columns" @confirm="onConfirmPicker" @close="comPickerInfo.showSheet=false" @cancel="comPickerInfo.showSheet=false" keyName="NAME"></u-picker>
		<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>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup,
		getProductionUnitValue,
		getRealIndex
	} from '../../../../utils/common'
	import {
		FMProductionUnits,
	} from '../../../../utils/enums.js'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices';
	import {
		WBOTFull,
		OrderEntitiesJobSafeMeasureEnum,
		ProjectInputDangerApply,
		WBOutSource,
		WBUserOrderPaged,
		WBSafeCheckTask,
		CheckTypeApply,
		CheckAreaEnumApply,
		CheckUseful,
		GetIni
	} from '../../../../services/apply/subPages/scWB';

	import {
		getEnum
	} from '../../../../services/common';

	import config from '../../../../config/common'
	export default {
		data() {
			return {
				tableKey: '0',
				TaskID: '',
				ORG_ID: uni.getStorageSync('orgId'),
				isLoadOK: true,
				stepsPageList: 0,
				listISORNOT: [], //是否涉及
				listISORNOTText: [],
				listPropUpload: ['PARENT_ID'],
				listPropValUpload: [],
				checkboxValue1: [],
				checkboxList1: [{
						name: '线上',
					},
					{
						name: '线下',
					},
				],
				indexShow: 0,
				UnitLists: [],
				isOnline: false,
				isOffline: false,
				model: {
					ID: '',
					ORG_ID: '',
					TaskID: null,
					START_TIME: '',
					END_TIME: '',
					TOTAL_TIME: '',
					TRAIN_TYPE: '',
					TRAIN_CONTENT: '',
					ONLINE_START_TIME: '',
					ONLINE_END_TIME: '',
					ONLINE_TOTAL_TIME: '',
					OFFLINE_START_TIME: '',
					OFFLINE_END_TIME: '',
					OFFLINE_TOTAL_TIME: '',
					TRAIN_ADDR: '',
					IS_CREATE_TEST: '',
					Nav_Files: [],
					Nav_Parent: {
						NAME: '',
						END_TIME: '',
						Nav_Project: {
							NAME: '',
							UNIT_NAME: ''
						},
						Nav_Department: {
							NAME: ''
						},
						Nav_User: {
							NAME: ''
						},
					},
					Nav_Users: [{
						listPropValSubUpload: [],
						SCORE: 0,
						EXAMINATION_RESULTS: '',
						EXAMINATION_RESULTS_SHOW: '',
						Nav_User: {
							NAME: '',
							SEX: '',
							SEX_SHOW: '',
							ID_CARD: ''
						},
						Nav_Files: []
					}],
				},
				rules: {},
				comPickerInfo: {
					showSheet: false,
					dataItem: {},
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},

				selectorInfo: {
					name: 'user',
					isMultiple: false,
					showPopup: false,
					totalCount: 0,
					title: '考核结果选择',
					dataItem: {},
					index: 0,
					columns: [],
					dataLists: [],
					defaultText: '',
					defaultChecked: []
				},

				dateTimePickerInfo: {
					showCheckDate: false,
					dataIndex: undefined,
					defaultDateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					value: '',
					name: ''
				},
			}
		},
		onLoad(option) {
			// this.TaskID = option.taskID ? option.taskID : '';
			// this.model.ID = option.ID ? option.ID : '';
			// this.JOBID = option.ID ? option.ID : '';
			// this.tableKey = option.tableKey ? option.tableKey : '0'
			// this.loadData();

			this.model.ID = option.ID
			this.TaskID = option.taskID
			this.tableKey = option.tableKey
			if (option.taskID != null && option.taskID != '')
				this.model.TaskID = option.taskID
			this.getEnums()
			// this.loadData()
		},
		methods: {
			getEnums() {
				var dataParm = {
					'name': "SEExaminationResultsEnum"
				}
				getEnum(dataParm).then(res => {
					this.listISORNOT = res
					this.listISORNOTText = []
					this.listISORNOT.forEach(e => {
						e.name = e.NAME
						e.code = e.ID
						this.listISORNOTText.push(e.NAME)
					})
					this.loadData()
				})
			},
			checkboxChange(arr) {
				let tempModel = "_" + arr.join("_") + "_";
				tempModel = tempModel.replaceAll("线上", 1);
				tempModel = tempModel.replaceAll("线下", 2);
				this.model.TRAIN_TYPE = tempModel;
				if (tempModel.indexOf('1') > -1) {
					this.isOnline = true
				} else {
					this.isOnline = false
				}
				if (tempModel.indexOf('2') > -1) {
					this.isOffline = true
				} else {
					this.isOffline = false
				}
			},
			handleDelRowBefore(item) {
				item.IS_DELETED = true
				let indexNotDel = 1
				this.model.Nav_Users.forEach((e, i) => {
					if (!e.IS_DELETED) {
						e.ROW_NO = indexNotDel
						indexNotDel++
					}
				})
				this.$forceUpdate()
			},
			stepAdd() {
				if (!this.isOnline && !this.isOffline) {
					uni.$showErrorInfo('请选择培训形式！')
					return
				}
				// if (this.isOnline && !this.isOffline) {
				// 	if (!this.model.ONLINE_START_TIME) {
				// 		uni.$showErrorInfo('请选择线上培训开始时间！')
				// 		return
				// 	}
				// 	if (!this.model.ONLINE_END_TIME) {
				// 		uni.$showErrorInfo('请选择线上培训结束时间！')
				// 		return
				// 	}
				// }
				if (!this.isOnline && this.isOffline) {
					if (!this.model.OFFLINE_START_TIME) {
						uni.$showErrorInfo('请选择线下培训开始时间！')
						return
					}
					if (!this.model.OFFLINE_END_TIME) {
						uni.$showErrorInfo('请选择线下培训结束时间！')
						return
					}
					if (!this.model.TRAIN_ADDR) {
						uni.$showErrorInfo('请填写培训地点！')
						return
					}
				}
				if (this.isOnline && this.isOffline) {
					// if (!this.model.ONLINE_START_TIME) {
					// 	uni.$showErrorInfo('请选择线上培训开始时间！')
					// 	return
					// }
					// if (!this.model.ONLINE_END_TIME) {
					// 	uni.$showErrorInfo('请选择线上培训结束时间！')
					// 	return
					// }
					if (!this.model.OFFLINE_START_TIME) {
						uni.$showErrorInfo('请选择线下培训开始时间！')
						return
					}
					if (!this.model.OFFLINE_END_TIME) {
						uni.$showErrorInfo('请选择线下培训结束时间！')
						return
					}
					if (!this.model.TRAIN_ADDR) {
						uni.$showErrorInfo('请填写培训地点！')
						return
					}
				}
				this.stepsPageList = this.stepsPageList + 1
			},
			stepReduce() {
				this.stepsPageList = this.stepsPageList - 1
			},
			loadData() {
				let json = initFilter(this.ORG_ID);
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_Parent.Nav_Project')
				extendInclude(json, 'Nav_Parent')
				extendInclude(json, 'Nav_Parent.Nav_Department')
				extendInclude(json, 'Nav_Parent.Nav_User')
				extendInclude(json, 'Nav_Users.Nav_User')
				extendInclude(json, 'Nav_Users.Nav_Files.Nav_ImgFile')

				GetIni(json).then(ret => {
					this.isLoadOK = false
					this.model = ret
					if (this.model.TRAIN_TYPE != null || this.model.TRAIN_TYPE != undefined) {
						if (this.model.TRAIN_TYPE.indexOf(1) > -1) {
							this.model.TRAIN_TYPE_SHOW = "线上";
						} else if (this.model.TRAIN_TYPE.indexOf(2) > -1) {
							this.model.TRAIN_TYPE_SHOW = "线下";
						}
					}
					this.model.Nav_Users.map(item => {
						item.Nav_User.SEX_SHOW = item.Nav_User.SEX == 0 ? '女' : '男'
					})
					this.listPropValUpload.push(this.model.ID)
				})
			},

			//显示时间控件
			showCheckDate(dataIndex) {
				this.dateTimePickerInfo.showCheckDate = true

				this.dateTimePickerInfo = {
					showCheckDate: true,
					dataIndex: dataIndex,
				}
			},
			//隐藏控件 显示时间
			handleCheckDate(e) {
				if (this.dateTimePickerInfo.dataIndex == 1) {
					this.model.ONLINE_START_TIME = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				} else if (this.dateTimePickerInfo.dataIndex == 2) {
					this.model.ONLINE_END_TIME = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				} else if (this.dateTimePickerInfo.dataIndex == 3) {
					this.model.OFFLINE_START_TIME = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				} else {
					this.model.OFFLINE_END_TIME = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				}
				if (this.model.ONLINE_START_TIME && this.model.ONLINE_END_TIME) {
					let totalTime = (new Date(this.model.ONLINE_END_TIME).getTime() - new Date(this.model.ONLINE_START_TIME).getTime()) * 1.0 / 1000 / 60 / 60
					this.model.ONLINE_TOTAL_TIME = totalTime.toFixed(0)
				}
				if (this.model.OFFLINE_START_TIME && this.model.OFFLINE_END_TIME) {
					let totalTimes = (new Date(this.model.OFFLINE_END_TIME).getTime() - new Date(this.model.OFFLINE_START_TIME).getTime()) * 1.0 / 1000 / 60 / 60
					this.model.OFFLINE_TOTAL_TIME = totalTimes.toFixed(0)
				}

				this.dateTimePickerInfo.showCheckDate = false

			},

			handleShowSheetForArea(item, todo) {
				const validDetails = this.model.Nav_Users.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


				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.Sort = "NAME"
				// json.Order = 1
				if (p.name == 'UserName') {
					if (this.model.Nav_Parent.PROJECT_ID != undefined && this.model.Nav_Parent.PROJECT_ID != '')
						extendRule(json, 'PROJECT_ID', 1, this.model.Nav_Parent.PROJECT_ID);
					dataSelect = await WBUserOrderPaged(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.Data[i].code = res.Data[i].CODE
							}
						}
						return res.Data
					})
				} else if (p.name == 'Nav_ListSourceOn' || p.name == 'Nav_ListSourceOff') {
					this.selectorInfo.isMultiple = true
					json.Sort = 'ID'
					dataSelect = await WBOutSource(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.Data[i].code = res.Data[i].CODE
							}
						}
						return res.Data
					})
					let datas = p.name == 'Nav_ListSourceOn' ? this.model.Nav_ListSourceOn: this.model.Nav_ListSourceOff
					if (datas && datas.length > 0) {
						
						datas.filter(i => !i.IS_DELETED).map(item => {
							let newId = item.OUTSOURCE_ID;
							// 创建一个新对象，ID 为 item.LAW_ID，其他属性和 item 相同
							let newItem = {
								...item,
								ID: newId
							};
							// 将新对象添加到 this.defaultChecked 数组中
							defaultChecked.push(newItem);
						})
					} else {
						defaultChecked = []
					}

				}
				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
				this.selectorInfo.dataLists = []
				const validDetails = this.model.Nav_Users.filter(i => !i.IS_DELETED);
				const index = this.selectorInfo.index;
				const realIndex = this.model.Nav_Users.findIndex(item => item === validDetails[index]);
				if (this.selectorInfo.name == 'Nav_ListSourceOn' || this.selectorInfo.name == 'Nav_ListSourceOff') {
					let listUsers = []
					let UsersName = ''
					if (this.model.Nav_ListSourceOn != null && this.model.Nav_ListSourceOn.length > 0) {
						//如果有数据 数据删除
						this.model.Nav_ListSourceOn.forEach(e => {
							e.IS_DELETED = true
							listUsers.push(e)
						})
					}
					if (e.length > 0) {
						e.forEach((item, i) => {
							if (item.NAME != null) {
								if (i > 0) {
									UsersName += ' '
								}
								listUsers.push({
									// ...item,
									ID: guid(),
									Nav_Outsource:{
										NAME:item.NAME,
										ID:item.ID
									},
									NAME:item.NAME,
									PARENT_ID: this.model.ID,
									OUTSOURCE_ID:item.ID,
									ORG_ID: this.ORG_ID,
									IS_DELETED: false,
								})
								UsersName += item.NAME
							}
						})
					}
					if (this.selectorInfo.name == 'Nav_ListSourceOn') {
						this.model.Nav_ListSourceOn = listUsers
						this.model.Nav_ListSourceOns = UsersName
					} else {
						this.model.Nav_ListSourceOff = listUsers
						this.model.Nav_ListSourceOffs = UsersName
					}


				} else if (this.selectorInfo.name == 'UserName') {
					this.model.Nav_Users[realIndex].Nav_User = e;
					this.model.Nav_Users[realIndex].USER_ID = e.ID;
					this.model.Nav_Users[realIndex].Nav_User.SEX_SHOW = e.SEX == 0 ? '女' : '男'
				}

			},
			closePicker() {
				this.comPickerInfo = {
					showSheet: false,
					columns: [],
					title: '',
					name: '',
					formIndex: undefined
				}
			},

			submit() {
				this.modelEdit = JSON.parse(JSON.stringify(this.model))
				// delete this.modelEdit.Nav_Task
				// delete this.modelEdit.Nav_ListAreas
				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.Nav_Users.forEach(e => {

					if (e.Nav_User != null)
						delete e.Nav_User

				})
				this.modelEdit.PUBLISH = 'SaveAndNotify'
				WBOTFull(this.modelEdit).then(res => {
					uni.$showMsgFunc('操作成功!', () => {
						uni.navigateBack()
					}, 'success', 1000)
				})
			},
			handleAdd() {
				if (this.model.Nav_Users == null) {
					this.model.Nav_Users = []
				}

				var ROW_NO = 1;
				if (this.model.Nav_Users.length > 0) {
					this.model.Nav_Users.forEach(e => {
						if (e.IS_DELETED == undefined || e.IS_DELETED == false)
							ROW_NO++
					})
				}
				var modelAdd = {
					ID: guid(),
					ORG_ID: this.ORG_ID,
					PARENT_ID: this.model.ID,
					Nav_User: {
						NAME: '',
						SEX: '',
						ID_CARD: '',
					},
					USER_ID: '',
					SCORE: '',
					EXAMINATION_RESULTS: '',
					Nav_Files: [],
					IS_DELETED: false,
				}
				this.model.Nav_Users.push(modelAdd)
				this.indexShow = ROW_NO
			},

			handleChange(item, name) {
				// let arr = this.listISORNOTText
				this.comPickerInfo = {
					showSheet: true,
					columns: [this.listISORNOTText],
					dataItem: item,
					name: name
				}
			},
			onConfirmPicker(e) {

				this.comPickerInfo = {
					showSheet: false,
					dataItem: this.comPickerInfo.dataItem,
					columns: [],
					title: '',
					name: this.comPickerInfo.name,
					formIndex: undefined
				}
				this.comPickerInfo.dataItem.EXAMINATION_RESULTS_SHOW = e.value[0]
				this.comPickerInfo.dataItem.EXAMINATION_RESULTS = this.listISORNOT[e.indexs[0]].code

				// this.model.Nav_Users[this.comPickerInfo.dataItem.index].MineType = codeMapping[e.value]
				// this.model.Nav_Users[this.comPickerInfo.dataItem.index].MineTypes = String(e.value)
			}
		}
	}
</script>

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

	/* .todo-page {
		padding: 16px 16px 70px;
	} */
</style>