<!-- 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="AUDIT_OPINION" borderBottom v-if="model.STATUS==40">
					<u--input disabled disabledColor="#ffffff" v-model="model.AUDIT_OPINION" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item class="subRequired" required label="项目名称" prop="Nav_Project.NAME" borderBottom @click="handleShowSheet({title: '项目名称', name: 'ProjectName'})">
					<u--input disabledColor="#fff" v-model="model.Nav_Project.NAME" 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.UNIT_NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>

				<u-form-item class="subRequired" required label="作业类别" prop="Nav_Type.NAME" borderBottom @click="handleShowSheet({title: '作业类别', name: 'TypeName'})">
					<u--input disabledColor="#fff" placeholder="请选择作业类别" v-model="model.Nav_Type.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="DANGEROUS_JOB_NAME" borderBottom>
					<u--input disabledColor="#ffffff" v-model="model.DANGEROUS_JOB_NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="危险作业具体事项" prop="DANGEROUS_JOB_ITEM" borderBottom>
					<u--input disabledColor="#ffffff" v-model="model.DANGEROUS_JOB_ITEM" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="作业风险辨识" prop="JOB_RISK_IDENTIFY" borderBottom>
					<u--input disabledColor="#ffffff" v-model="model.JOB_RISK_IDENTIFY" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>

				<u-form-item label="作业开始时间" prop="START_TIME" borderBottom @click="showCheckDate(1)">
					<u--input disabledColor="#fff" v-model="model.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 label="作业结束时间" prop="END_TIME" borderBottom @click="showCheckDate(2)">
					<u--input disabledColor="#fff" v-model="model.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="JOB_ADDRESS" borderBottom>
					<u--input disabledColor="#ffffff" v-model="model.JOB_ADDRESS" border="none" inputAlign="right" fontSize="14px"></u--input>
				</u-form-item>

				<u-form-item required label="作业人员" prop="UsersName" borderBottom @click="handleShowSheet({title: '作业人员', name: 'UsersName'})">
					<u--input disabledColor="#fff" placeholder="请选择作业人员" v-model="model.UsersName" 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 label="现场监护人" prop="USER_ID" borderBottom @click="handleShowSheet({title: '现场监护人', name: 'UserName'})">
					<u--input disabledColor="#fff" placeholder="请选择现场监护人" v-model="model.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>

				<view class="upload-title">附件</view>
				<full-upload v-model="model.Nav_Files" :isShowBtn='true' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>

			</u--form>

			<!-- </uni-card> -->
		</view>
		<view style="padding: 10px 16px;" v-if="stepsPageList === 0" class="bottom-button">
			<u-button type="primary" :loading="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_Detail.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+'.'+item.MEASURE}}
									</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">
								<u-form-item label="序号" prop="ROW_NUM" borderBottom>
									<u--input disabledColor="#fff" v-model="item.ROW_NUM" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
								<u-form-item label="安全措施" class="subRequired" required prop="MEASURE" borderBottom>
									<u--input disabledColor="#fff" v-model="item.MEASURE" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
								<!-- <u-form-item label="是否涉及" class="subRequired" required prop="ISORNOTShow" borderBottom @click="handleChange( item)">
									<u--input disabled disabledColor="#fff" v-model="item.ISORNOTShow" 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="REMARK" borderBottom>
									<u--input disabledColor="#fff" v-model="item.REMARK" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
							</view>


						</uni-collapse-item>
					</view>
				</uni-collapse>
				<!-- 	<view v-for="(item, index) in model.Nav_Detail" :key="index">
				<u-form-item label="序号" prop="ROW_NUM" borderBottom>
					<u--input disabled disabledColor="#fff" v-model="item.ROW_NUM" border="none" inputAlign="right"></u--input>
				</u-form-item>
				<u-form-item label="安全措施" class="subRequired" required prop="MEASURE" borderBottom>
					<u--input disabledColor="#fff" v-model="item.MEASURE" border="none" inputAlign="right"></u--input>
				</u-form-item>
				<u-form-item label="是否涉及" class="subRequired" required prop="ISORNOTShow" borderBottom @click="handleChange( item)">
					<u--input disabled disabledColor="#fff" v-model="item.ISORNOTShow" border="none" inputAlign="right"></u--input>
					<u-icon style="margin-left: 4px;"  name="arrow-down"></u-icon>
				</u-form-item>
				<u-form-item label="说明" prop="REMARK" borderBottom>
					<u--input disabledColor="#fff" v-model="item.REMARK" border="none" inputAlign="right"></u--input>
				</u-form-item>
				</view> -->
				<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 style="padding: 10px 16px;" v-if='isLoadOK' class="bottom-button">
			<u-button type="primary" @click="submit" color="#3d4b70">提交</u-button>
		</view> -->
		<!-- 		<view class="bottom-button">
			<button type="primary" v-if='isLoadOK' @click="submit">提交</button>
		</view> -->
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup
	} from '../../../../utils/common'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices';
	import {
		FullUpdateDangerApply,
		JobTypeDangerApply,
		OrderEntitiesJobSafeMeasureEnum,
		ProjectInputDangerApply,
		WBUserOrderPaged,
		GetProject,
		GetDangerousJob,
		GetReject
	} 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: [],
				indexShow: 0,
				model: {
					ID: '',
					ORG_ID: '',
					TaskID: null,
					Nav_Files: [],
					AUDIT_OPINION: '',
					PROJECT_ID: '',
					Nav_Project: {
						NAME: ''
					},
					UNIT_NAME: '',
					TYPE_ID: '',
					Nav_Type: {
						NAME: ''
					},
					DANGEROUS_JOB_NAME: '',
					DANGEROUS_JOB_ITEM: '',
					JOB_RISK_IDENTIFY: '',
					START_TIME: '',
					END_TIME: '',
					JOB_ADDRESS: '',
					UsersName: '',
					Nav_Users: [],
					USER_ID: '',
					Nav_User: {
						NAME: ''
					},
					Nav_Files: [],
					Nav_Detail: [{
						ID: '',
						ORG_ID: '',
						PARENT_ID: '',
						ROW_NUM: '',
						MEASURE: '安全措施',
						ISORNOT: '',
						ISORNOTShow: '',
						REMARK: '',
					}]
				},
				rules: {
					'Nav_Project.NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择【项目名称】'
					},
					'Nav_Type.NAME': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择【作业类别】'
					},
					// 'START_TIME': {
					// 	type: 'string',
					// 	required: true,
					// 	trigger: ['blur', 'change'],
					// 	message: '请选择【作业开始时间】'
					// },
					// 'END_TIME': {
					// 	type: 'string',
					// 	required: true,
					// 	trigger: ['blur', 'change'],
					// 	message: '请选择【作业结束时间】'
					// },
					'UsersName': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择【作业人员】'
					},
					'USER_ID': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '请选择【现场监护人】'
					}
				},
				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': "ISORNOT"
				}
				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()
				})
			},
			handleDelRowBefore(item) {
				item.IS_DELETED = true
				let indexNotDel = 1
				this.model.Nav_Detail.forEach((e, i) => {
					if (!e.IS_DELETED) {
						e.ROW_NO = indexNotDel
						indexNotDel++
					}
				})
				this.$forceUpdate()
			},
			stepAdd() {
				const ele = this.$refs
				ele['wForm'].validate().then(res => {
					this.stepsPageList = this.stepsPageList + 1
				}).catch(err => {
					uni.$showErrorInfo(err[0].message + '！')
				})

			},
			stepReduce() {
				this.stepsPageList = this.stepsPageList - 1
			},
			loadData() {
				if (this.model.ID == undefined || this.model.ID == '') {
					// this.isLoadOK = false
					this.model.Nav_Detail = []
					if (this.model.ID == undefined || this.model.ID == '')
						this.model.ID = guid()
					let userPro = uni.getStorageSync('appInfo').User.PROJECT_ID
					if (userPro && userPro !== null) {
						let json = initFilter();
						extendRule(json, 'ID', 1, userPro);
						GetProject(json).then(ret => {
							this.model.PROJECT_ID = ret.ID
							this.model.Nav_Project.NAME = ret.NAME
							this.model.UNIT_NAME = ret.UNIT_NAME
							this.model.DEPARTMENT_ID = ret.DEPARTMENT_ID

							this.isLoadOK = false
						});
					} else {
						this.isLoadOK = false
					}

				} else {

					let json = initFilter(this.ORG_ID);
					extendRule(json, 'ID', 1, this.model.ID);
					extendInclude(json, 'Nav_Files.Nav_ImgFile')
					extendInclude(json, 'Nav_Users.Nav_User')
					extendInclude(json, 'Nav_Project')
					extendInclude(json, 'Nav_Type')
					extendInclude(json, 'Nav_Users')
					extendInclude(json, 'Nav_User')
					extendInclude(json, 'Nav_Detail')


					GetDangerousJob(json).then(ret => {
						this.model = ret
						let listUsers = []
						let UsersName = ''
						if (ret.Nav_Users.length > 0) {
							ret.Nav_Users.forEach((item, i) => {
								if (item.Nav_User.NAME != null) {
									UsersName += item.Nav_User.NAME
								}
							})
						}
						this.model.UsersName = UsersName
						this.listPropValUpload.push(this.model.ID)

						this.isLoadOK = false
						if (ret.STATUS == 40) {
							let jsons = {
								ID: this.model.ID
							};
							// extendRule(jsons, 'ID', 1, this.model.ID);
							GetReject(jsons).then(ret => {
								this.model.AUDIT_OPINION = ret
								this.$forceUpdate();

							});
						}
					});
				}
				this.listPropValUpload.push(this.model.ID)
			},

			//显示时间控件
			showCheckDate(dataIndex) {
				this.dateTimePickerInfo.showCheckDate = true
				if (dataIndex == 1) {
					if (this.model.START_TIME == null)
						this.model.START_TIME = uni.$u.timeFormat(new Date(),
							'yyyy-mm-dd hh:MM:ss')
				} else {
					if (this.model.END_TIME == null)
						this.model.END_TIME = uni.$u.timeFormat(new Date(),
							'yyyy-mm-dd hh:MM:ss')
				}
				this.dateTimePickerInfo = {
					showCheckDate: true,
					dataIndex: dataIndex,
					defaultDateTime: dataIndex == 1 ? this.model.START_TIME : this.model.END_TIME
				}
			},
			//隐藏控件 显示时间
			handleCheckDate(e) {
				// let v = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss')
				// const {
				// 	name,
				// 	dataIndex
				// } = this.dateTimePickerInfo

				this.dateTimePickerInfo.showCheckDate = false
				if (this.dateTimePickerInfo.dataIndex == 1) {
					this.model.START_TIME = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				} else {
					this.model.END_TIME = uni.$u.timeFormat(e.value,
						'yyyy-mm-dd hh:MM:ss')
				}
			},


			async handleShowSheet(p) {
				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.Sort = "NAME"
				json.Order = 1
				json.Limit = 20
				if (p.pageIndex) {
					json.Start = (p.pageIndex - 1) * json.Limit;
				}
				if (p.name == 'ProjectName') { //项目名称
					// extendRule(json, 'CHECK_TYPE_ID', 1, this.model.CHECK_TYPE_ID);
					// json.Include.push("Nav_Enums")
					dataSelect = await ProjectInputDangerApply(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].UNIT_NAME
							}
						}
						return res.Data
					})
				} else if (p.name == 'TypeName') { //作业类别
					dataSelect = await JobTypeDangerApply(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
					})
				} else if (p.name == 'UsersName' || p.name == 'UserName') {
					if (this.model.PROJECT_ID == undefined || this.model.PROJECT_ID == '') {
						uni.$showErrorInfo('请先选择项目名称')
						return false
					}


					if (p.name == 'UsersName') { //作业人员
						this.selectorInfo.isMultiple = true

					}

					if (this.model.PROJECT_ID != undefined && this.model.PROJECT_ID != '')
						extendRule(json, 'PROJECT_ID', 1, this.model.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
					})
					let data = this.model.Nav_Users.filter(i => !i.IS_DELETED)
					if (data.length > 0 && data != null) {
						// this.selectorInfo.defaultChecked = []
						data.forEach(e => {
							if (e.Nav_User != null && e.Nav_User.NAME != null)
								defaultChecked.push(e.Nav_User)
						})
					} else {
						defaultChecked = null
					}
				}

				// else if (p.name == 'UsersName') { //作业人员
				// 	this.selectorInfo.isMultiple = false
				// } else if (p.name == 'UserName') { //现场监护人
				// }
				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
					}
				} else {
					// 暂无数据
				}
			},
			//数据加载
			handleSearch(val, pageIndex) {
				var p = {
					name: this.selectorInfo.name,
					title: this.selectorInfo.title,
					val: val,
					pageIndex: pageIndex
				}
				this.handleShowSheet(p)
			},

			handleSelected(e) {
				this.selectorInfo.showPopup = false
				if (this.selectorInfo.name == 'ProjectName') { //项目名称
					this.model.PROJECT_ID = e.ID
					this.model.Nav_Project = e
					this.model.UNIT_NAME = e.UNIT_NAME
				} else if (this.selectorInfo.name == 'TypeName') { //作业类别
					this.model.TYPE_ID = e.ID
					this.model.Nav_Type = e
					const json = initFilter(this.ORG_ID, "", "", 0, this.selectorInfo.pageIndex ?? 1)
					json.Sort = "Nav_Type.NAME"
					json.Order = 1
					extendInclude(json, 'Nav_Detail')
					extendRule(json, 'TYPE_ID', 1, this.model.TYPE_ID);
					OrderEntitiesJobSafeMeasureEnum(json).then(res => {
						this.model.Nav_Detail = []
						if (res == undefined || res.length == 0 || res[0].Nav_Detail == undefined || res[0]
							.Nav_Detail
							.length < 1) {
							uni.$showErrorInfo('该作业类别未配置安全措施，请先配置安全措施！')
						} else {
							res[0].Nav_Detail.forEach((e, index) => {
								this.model.Nav_Detail.push({
									ID: guid(),
									ORG_ID: this.ORG_ID,
									PARENT_ID: this.model.ID,
									ROW_NUM: e.ROW_NUM, // index + 1,
									MEASURE: e.SAFE_MEASURE,
									ISORNOT: 1,
									ISORNOTShow: '是',
									IS_DELETED: e.IS_DELETED,
								})
							})
						}
					})
				} else if (this.selectorInfo.name == 'UsersName') { //作业人员
					let listUsers = []
					let UsersName = ''

					if (this.model.Nav_Users != null && this.model.Nav_Users.length > 0) {
						//如果有数据 数据删除
						this.model.Nav_Users.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({
									ID: guid(),
									PARENT_ID: this.model.ID,
									USER_ID: item.ID,
									ORG_ID: this.ORG_ID,
									Nav_User: e[i],
									IS_DELETED:false,
								})
								UsersName += item.NAME
							}
						})
					}
					this.model.Nav_Users = listUsers
					this.model.UsersName = UsersName


				} else if (this.selectorInfo.name == 'UserName') { //现场监护人
					this.model.Nav_User = e
					this.model.USER_ID = e.ID
				}

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

			submit() {
				this.modelEdit = JSON.parse(JSON.stringify(this.model))
				this.modelEdit.Nav_Project = null
				this.modelEdit.Nav_Type = null
				this.modelEdit.Nav_User = null
				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)
						e.Nav_User = null
				})
				this.modelEdit.PUBLISH = 'SaveAndNotify'
				// console.log(this.modelEdit,'this.modelEdit')
				FullUpdateDangerApply(this.modelEdit).then(res => {
					uni.$showMsgFunc('操作成功!', () => {
						uni.navigateBack()
					}, 'success', 1000)
				})
			},
			handleAdd() {
				if (this.model.Nav_Detail == null) {
					this.model.Nav_Detail = []
				}

				var ROW_NO = 1;
				if (this.model.Nav_Detail.length > 0) {
					this.model.Nav_Detail.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,
					ROW_NUM: ROW_NO,
					MEASURE: '',
					ISORNOT: 1,
					ISORNOTShow: '是',
					REMARK: '',
					IS_DELETED: false,
				}
				this.model.Nav_Detail.push(modelAdd)
				this.indexShow = ROW_NO
			},

			handleChange(item) {
				this.comPickerInfo = {
					showSheet: true,
					columns: [this.listISORNOTText],
					dataItem: item
				}
			},
			onConfirmPicker(e) {
				this.comPickerInfo = {
					showSheet: false,
					dataItem: this.comPickerInfo.dataItem,
					columns: [],
					title: '',
					name: '',
					formIndex: undefined
				}
				this.comPickerInfo.dataItem.ISORNOTShow = e.value[0]
				this.comPickerInfo.dataItem.ISORNOT = this.listISORNOT[e.indexs[0]].code
			}
		}
	}
</script>

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

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