<template>
	<view class="page-wrap">
		<view class="card">
			<uni-card margin="0" :is-shadow="true">
				<u--form
				  labelPosition="left"
				  labelWidth="auto"
				  labelAlign="center"
				  :model="dataModel"
				  :rules="rules"
				  ref="wForm"
				  errorType="border-bottom"
				>
				<u-form-item label="审核意见：" prop="CONTEXT" borderBottom v-if="dataModel.FORM_STATUS==4">
				</u-form-item>
				<u--textarea v-html="dataModel.CONTEXT" border="surround" v-if="dataModel.FORM_STATUS==4"
					disabled></u--textarea>
					<u-form-item label="编号" prop="CODE" borderBottom>
						<u--input v-model="dataModel.CODE" placeholder="请输入编号" disabled disabledColor="#ffffff" border="none" inputAlign="right">
						</u--input>
					</u-form-item>
					<u-form-item label="作业名称" prop="stepName" borderBottom>
						<u--input v-model="dataModel.Nav_OperationStep.NAME" disabled disabledColor="#ffffff" placeholder="请输入作业名称" border="none"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="作业地点" prop="JOB_LOCATION" borderBottom>
						<u--input v-model="dataModel.JOB_LOCATION" placeholder="请输入作业地点" border="none"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="作业时间" prop="JOB_DATE" borderBottom>
						<u--input v-html="dataModel.JOB_DATE" placeholder="请输入作业时间" disabled disabledColor="#ffffff" border="none" inputAlign="right"
						style="text-align: right;display:block">
						</u--input>
					</u-form-item>
				</u--form>
			</uni-card>
		</view>
		<view class="sub-form">
			<view class="sub-form-wrap">
				<view class="sub-form-btns">
					<view class="sub-form-btn" @click="handleAddUser">
						<!-- <u-icon class="icon" name="plus" color="#2979ff" size="14"></u-icon> -->
						<u--text type="primary" text="新增作业人员+"></u--text>
					</view>
				</view>
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
								 ref="sForm">
					<uni-collapse :border="false" accordion>
						<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
											v-for="(item, index) in dataModel.Nav_JobEventPerson" :key="index">
							<uni-collapse-item title-border="none" :show-arrow="false">
								<!-- <view slot="right-icon" class="row-action"></view> -->
								<!-- <view slot="value" class="row-action">
									<text @click.stop="handleOkRow">
										<u--text type="primary" text="确认"></u--text>
									</text>
									<text @click.stop="handleDelRowBefore(index)">
										<u--text type="error" text="删除"></u--text>
									</text>
								</view> -->
								<view slot="title" class="collapse-title">
									<view class="down">
										<uni-icons type="bottom"></uni-icons>
									</view>
									<view class="text">{{index + 1 + '. ' +item.Nav_User.NAME}}</view>
									<!-- <view class="action">
										<text @click.stop="handleOkRowDetail(index)">
											<u--text type="primary" text="确认"></u--text>
										</text>
									</view> -->
								</view>
								<u-form-item label="人员姓名" prop="personName" borderBottom
														 @click="handleChangeUser(item['Nav_User'])">
									<u--input disabled disabledColor="#fff" v-model="item['Nav_User'].NAME"
														placeholder="请选择人员姓名" border="none" inputAlign="right"></u--input>
									<u-icon style="margin-left: 4px;" slot="right" name="arrow-down">
									</u-icon>
								</u-form-item>
								<u-form-item label="人员编号" prop="personNo" borderBottom>
									<u--input disabled disabledColor="#fff" v-model="item['Nav_User'].CODE"
														border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="部门" prop="job" borderBottom>
									<u--input disabled disabledColor="#fff"
														v-model="item['Nav_User']['Nav_Department'].NAME" border="none"
														inputAlign="right"></u--input>
									<u-icon style="margin-left: 4px;" slot="right" name="arrow-down"></u-icon>
								</u-form-item>
								<u-form-item>
									<button :disabled="!isLoadOK" type="primary" style="height: 100%;background-color: darkorange;width: 60%;font-size:12px"
										@click="handleDelRowBefore(index)">删除</button>
								</u-form-item>
							</uni-collapse-item>
						</uni-card>
					</uni-collapse>
				</u--form>
			</view>
		</view>
		<view class="sub-form">
			<view class="sub-form-wrap">
				<view class="sub-form-btns">
					<view class="sub-form-btn" @click="handleAddDetail">
						<!-- <u-icon class="icon" name="plus" color="#2979ff" size="14"></u-icon> -->
						<u--text type="primary" text="新增作业前确认+"></u--text>
					</view>
				</view>
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
								 ref="sForm">
					<uni-collapse :border="false" accordion>
						<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
											v-for="(item, index) in dataModel.Nav_Details" :key="index">
							<uni-collapse-item title-border="none" :show-arrow="false">
								<view slot="title" class="collapse-title">
									<view class="down">
										<uni-icons type="bottom"></uni-icons>
									</view>
									<view class="text">{{index + 1 + '. ' + item.SafeConfirmsStr}}</view>
									<view class="action">
										<text @click.stop="handleOkRowDetail(index)">
											<u--text type="primary" text="确认"></u--text>
										</text>
									</view>
								</view>
								<u-form-item label="顺序" prop="NUM" borderBottom>
									<u-number-box v-model="item.NUM" @change="valChangeDetail" :min="0" style="margin-left: auto;"></u-number-box>
									<!-- <u--input disabledColor="#fff"
										v-model="item.NUM" border="none"
										inputAlign="right"></u--input> -->
								</u-form-item>
								<u-form-item label="名称" prop="SafeConfirmsStr" borderBottom>
									<u--input disabledColor="#fff"
														v-model="item.SafeConfirmsStr"
														border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="是否确认" prop="IS_CONFIRM_SHOW" borderBottom
								@click="handleShowSheet({title: '是否确认', name: 'IS_CONFIRM_SAFE',index})">
									<u--input disabled disabledColor="#fff"
														v-model="item.IS_CONFIRM_SHOW"
														border="none"
														inputAlign="right"></u--input>
									<u-icon style="margin-left: 4px;" slot="right" name="arrow-down"></u-icon>
								</u-form-item>
								<view class="upload-title">附件</view>
								<full-upload v-model="item.Nav_Files"></full-upload>
								<u-form-item>
									<button :disabled="!isLoadOK" type="primary" style="height: 100%;background-color: darkorange;width: 60%;font-size:12px"
										@click="handleDelRowBeforeDetail(index)">删除</button>
								</u-form-item>
							</uni-collapse-item>
						</uni-card>
					</uni-collapse>
				</u--form>
			</view>
		</view>
		<view class="sub-form">
			<view class="sub-form-wrap">
				<view class="sub-form-btns">
					<view class="sub-form-btn" @click="handleAddFlow">
						<!-- <u-icon class="icon" name="plus" color="#2979ff" size="14"></u-icon> -->
						<u--text type="primary" text="新增作业流程及安全措施+"></u--text>
					</view>
				</view>
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
								 ref="sForm">
					<uni-collapse :border="false" accordion>
						<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
											v-for="(item, index) in dataModel.Nav_Flow" :key="index">
							<uni-collapse-item  title-border="none" :show-arrow="false">
								<view slot="title" class="collapse-title">
									<view class="down">
										<uni-icons type="bottom"></uni-icons>
									</view>
									<view class="text">{{index + 1 + '. ' + item.SafeMeasuresStr}}</view>
									<view class="action">
										<text @click.stop="handleOkRowFlow(index)">
											<u--text type="primary" text="确认"></u--text>
										</text>
									</view>
								</view>
								<u-form-item label="顺序" prop="NUM" borderBottom>
									<u-number-box v-model="item.NUM" @change="valChangeFlow" :min="0" style="margin-left: auto;"></u-number-box>
									<!-- <u--input disabledColor="#fff"
										v-model="item.NUM" border="none"
										inputAlign="right"></u--input> -->
								</u-form-item>
								<u-form-item label="名称" prop="SafeMeasuresStr" borderBottom>
									<u--input disabledColor="#fff"
														v-model="item.SafeMeasuresStr"
														border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="是否确认" prop="IS_CONFIRM_SHOW" borderBottom
								@click="handleShowSheet({title: '是否确认', name: 'IS_CONFIRM_MEAS',index})">
									<u--input disabled disabledColor="#fff"
														v-model="item.IS_CONFIRM_SHOW"
														border="none"
														inputAlign="right"></u--input>
									<u-icon style="margin-left: 4px;" slot="right" name="arrow-down"></u-icon>
								</u-form-item>
								<view class="upload-title">附件</view>
								<full-upload v-model="item.Nav_Files"></full-upload>
								<u-form-item>
									<button :disabled="!isLoadOK" type="primary" style="height: 100%;background-color: darkorange;width: 60%;font-size:12px" 
										@click="handleDelRowBeforeFlow(index)">删除</button>
								</u-form-item>
							</uni-collapse-item>
						</uni-card>
					</uni-collapse>
				</u--form>
			</view>
		</view>
		<view class="sub-form">
			<view class="sub-form-wrap">
				<view class="sub-form-btns">
					<view class="sub-form-btn" @click="handleAddDeal">
						<!-- <u-icon class="icon" name="plus" color="#2979ff" size="14"></u-icon> -->
						<u--text type="primary" text="新增作业后处理措施+"></u--text>
					</view>
				</view>
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
								 ref="sForm">
					<uni-collapse :border="false" accordion>
						<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
											v-for="(item, index) in dataModel.Nav_Measure" :key="index">
							<uni-collapse-item title-border="none" :show-arrow="false">
								<view slot="title" class="collapse-title">
									<view class="down">
										<uni-icons type="bottom"></uni-icons>
									</view>
									<view class="text">{{index + 1 + '. ' + item.DealMeasuresStr}}</view>
									<view class="action">
										<text @click.stop="handleOkRowDeal(index)">
											<u--text type="primary" text="确认"></u--text>
										</text>
									</view>
								</view>
								<u-form-item label="顺序" prop="NUM" borderBottom>
									<u-number-box v-model="item.NUM" @change="valChangeDeal" :min="0" style="margin-left: auto;"></u-number-box>
									<!-- <u--input disabledColor="#fff"
										v-model="item.NUM" border="none"
										inputAlign="right"></u--input> -->
								</u-form-item>
								<u-form-item label="名称" prop="SafeMeasuresStr" borderBottom>
									<u--input disabledColor="#fff"
														v-model="item.DealMeasuresStr"
														border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="是否确认" prop="IS_CONFIRM_SHOW" borderBottom
								@click="handleShowSheet({title: '是否确认', name: 'IS_CONFIRM_DEAL',index})">
									<u--input disabled disabledColor="#fff"
														v-model="item.IS_CONFIRM_SHOW"
														border="none"
														inputAlign="right"></u--input>
								</u-form-item>
								<view class="upload-title">附件</view>
								<full-upload v-model="item.Nav_Files"></full-upload>
								<u-form-item> 
									<button :disabled="!isLoadOK" type="primary" style="height: 100%;background-color: darkorange;width: 60%;font-size:12px"
										@click="handleDelRowBeforeDeal(index)">删除</button>
								</u-form-item>
							</uni-collapse-item>
						</uni-card>
					</uni-collapse>
				</u--form>
			</view>
		</view>

	<query-selector
	  :show="showPopup"
	  :total="curTotal" 
	  :lists="userLists"
	  :defaultValue="currentOperateUser.NAME"
	  @close="handleClosePopup"
	  @search="handleSearchUser"
	  @select="handleSelectedUser"
	/>
	<u-modal :show="showDelModalIndex >= 0" @confirm="confirmDel" title="确认删除？"></u-modal>
	<u-modal :show="showDelModalDetail >= 0" @confirm="confirmDelDetail" title="确认删除？"></u-modal>
	<u-modal :show="showDelModalFlow >= 0" @confirm="confirmDelFlow" title="确认删除？"></u-modal>
	<u-modal :show="showDelModalDeal >= 0" @confirm="confirmDelDeal" title="确认删除？"></u-modal>
		<u-picker :show="comPickerInfo.showSheet" :columns="comPickerInfo.columns" @confirm="onConfirmPicker"
			@close="closePicker" @cancel="closePicker" keyName="NAME"></u-picker>
		<view class="bottom-button">
			<button type="primary" @click="submit">提交</button>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup,
		extendIgnoreDataRule
	} from '../../../../utils/common'
	import {
		getRequest,
		getUserLists,
		saveJobEventRecord
	} from '../../../../services/apply/FOServices/FOServices.js'
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				ID:'',
				tableKey: 0,
				curTotal: 0,
				showDelModalIndex: undefined,
				showDelModalDetail: undefined,
				showDelModalFlow: undefined,
				showDelModalDeal: undefined,
				isLoadOK: false,
				userLists: [],
				dataModel: {
					CODE: '',
					Nav_OperationStep:{},
					JOB_LOCATION:'',
					JOB_DATE:'',
					Nav_JobEventPerson:{
						Nav_User: {
							NAME: '',
							CODE: '',
						}}
				},
				subDataModel: {
					Nav_JobEventPerson:{
						Nav_User: {
							NAME: '',
							CODE: '',
						}},
					Nav_User: {
						Nav_Department: {
							NAME: ''
						},
						NAME: '',
						CODE: '',
					},
					Nav_Details:{
						NUM:0,
						IS_CONFIRM:false,
						IS_CONFIRM_SHOW:'否',
						Nav_Files:[]
					},
					Nav_Flow:{NUM:0,IS_CONFIRM:false,IS_CONFIRM_SHOW:'否',Nav_Files:[]},
					Nav_Measure:{NUM:0,IS_CONFIRM:false,IS_CONFIRM_SHOW:'否',Nav_Files:[]}
				},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				rules: {
					'JOB_LOCATION': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'JOB_DATE': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					}
				},
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				currentOperateUser: {},
				showPopup: false,
				TaskID: '',
			}
		},
		onLoad(opt) {
			this.handleGetJobEventGet(opt)
		},
		methods: {
			handleGetJobEventGet(opt) {
				this.TaskID = opt.taskID ? opt.taskID : '';
				this.ID = opt.ID ? opt.ID : '';
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				 extendRule(json, 'ID', 1, opt.ID)
					    // extendInclude(json, 'Nav_Meeting');
					    // extendInclude(json, 'Nav_CreateUser');
					    // extendInclude(json, 'Nav_OperationStep');
					    // extendInclude(json, 'Nav_JobEventPerson');
					    // extendInclude(json, 'Nav_JobEventPerson.Nav_User.Nav_Department');
					    // extendInclude(json, 'Nav_Details.Nav_Files.Nav_ImgFile');
					    // extendInclude(json, 'Nav_Flow.Nav_Files.Nav_ImgFile');
					    // extendInclude(json, 'Nav_Measure.Nav_Files.Nav_ImgFile');
					    // extendIgnoreDataRule(json)
				// TODO: id 未获取
				getRequest(json,"/FO/FOJobEventRecord/GetEdit").then(res => {
					this.dataModel = res
					if(res.JOB_DATE.indexOf("-"))
					{
						let jobDate=res.JOB_DATE.replace("-","<br/>")
						res.JOB_DATE = jobDate
					}
					//数据组装
					let strUserName = ''
					if (res.Nav_JobEventPerson && res.Nav_JobEventPerson.length > 0) {
						for (let i = 0; i < res.Nav_JobEventPerson.length; i++) {
							if (res.Nav_JobEventPerson[i].DEAL_STATUS == 0) {
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + "<text style='color:red'>" +
									res.Nav_JobEventPerson[i].Nav_User.NAME + "</text>";
							} else {
								let user=res.Nav_JobEventPerson[i].USER_ID!=null?res.Nav_JobEventPerson[i].Nav_User.NAME:'';
									strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + user;
							}

						}
					}
					//数据组装
					if (res.Nav_Details && res.Nav_Details.length > 0) {
						for (let i = 0; i < res.Nav_Details.length; i++) {
							res.Nav_Details[i].NUM = i+1;
							if (res.Nav_Details[i].IS_CONFIRM == true) {
								res.Nav_Details[i].IS_CONFIRM =true
								res.Nav_Details[i].IS_CONFIRM_SHOW ="是"
								} else {
								res.Nav_Details[i].IS_CONFIRM =false
								res.Nav_Details[i].IS_CONFIRM_SHOW ="否"
							}

						}
					}
					//数据组装
					if (res.Nav_Flow && res.Nav_Flow.length > 0) {
						for (let i = 0; i < res.Nav_Flow.length; i++) {
							res.Nav_Flow[i].NUM = i+1;
							if (res.Nav_Flow[i].IS_CONFIRM == true) {
								res.Nav_Flow[i].IS_CONFIRM =true
								res.Nav_Flow[i].IS_CONFIRM_SHOW ="是"
								} else {
								res.Nav_Flow[i].IS_CONFIRM_SHOW ="否"
								res.Nav_Flow[i].IS_CONFIRM =false
							}
						}
					}
					//数据组装
					if (res.Nav_Measure && res.Nav_Measure.length > 0) {

						for (let i = 0; i < res.Nav_Measure.length; i++) {
							res.Nav_Measure[i].NUM = i+1;
							if (res.Nav_Measure[i].IS_CONFIRM == true) {
								res.Nav_Measure[i].IS_CONFIRM =true
								res.Nav_Measure[i].IS_CONFIRM_SHOW ="是"
								} else {
								res.Nav_Measure[i].IS_CONFIRM =false
								res.Nav_Measure[i].IS_CONFIRM_SHOW ="否"
							}
						}
					}
					this.dataModel.UserNames = strUserName
					this.isLoadOK = true
				})
			},
			async handleShowSheet(p) {
				let column = []
				if (p.name === 'IS_CONFIRM_SAFE' || p.name === 'IS_CONFIRM_MEAS' ||p.name === 'IS_CONFIRM_DEAL')
					{
						column = [{
								NAME: '否',
								ID: false
							},
							{
								NAME: '是',
								ID: true
							}
						]
					}
				if (column.length) {
					this.comPickerInfo = {
						showSheet: true,
						title: p.title,
						name: p.name,
						dataIndex:p.index,
						formIndex: p.formIndex,
						columns: [column]
					}
				} else {
					// 暂无数据
				}
			},
			valChangeDetail(e){
				// this.dataModel.Nav_Details[index].NUM=e.value;
			},
			valChangeFlow(e) {
				// this.dataModel.Nav_Flow[index].NUM=e.value;
			},
			valChangeDeal(e) {
				// this.dataModel.Nav_Measure[index].NUM=e.value;
			},
			handleOkRowDetail(index) {
				// this.dataModel.Nav_Details[index].IS_CONFIRM=true;
				this.dataModel.Nav_Details[index].IS_CONFIRM=true;
				this.dataModel.Nav_Details[index].IS_CONFIRM_SHOW="是";
				let column = [{
						NAME: '是',
						ID: true
					}
				]
				this.comPickerInfo = {
					name: "是",
					dataIndex:index,
					columns: [column]
				}
			},
			handleOkRowFlow(index) {
				this.dataModel.Nav_Flow[index].IS_CONFIRM=true;
				this.dataModel.Nav_Flow[index].IS_CONFIRM_SHOW="是";
				let column = [{
						NAME: '是',
						ID: true
					}
				]
				this.comPickerInfo = {
					name: "是",
					dataIndex:index,
					columns: [column]
				}
			},
			handleOkRowDeal(index) {
				this.dataModel.Nav_Measure[index].IS_CONFIRM_SHOW="是";
				this.dataModel.Nav_Measure[index].IS_CONFIRM=true;
				let column = [{
						NAME: '是',
						ID: true
					}
				]
				this.comPickerInfo = {
					name: "是",
					dataIndex:index,
					columns: [column]
				}
			},
			handleAddUser() {
				this.dataModel.Nav_JobEventPerson.unshift(this.subDataModel)
			},
			handleAddDetail() {
				this.dataModel.Nav_Details.unshift(this.subDataModel.Nav_Details)
			},
			handleAddFlow() {
				this.dataModel.Nav_Flow.unshift(this.subDataModel.Nav_Flow)
			},
			handleAddDeal() {
				this.dataModel.Nav_Measure.unshift(this.subDataModel.Nav_Measure)
			},
			handleDelRowBefore(index) {
				this.showDelModalIndex = index
			},
			handleDelRowBeforeDetail(index) {
				this.showDelModalDetail = index
			},
			handleDelRowBeforeFlow(index) {
				this.showDelModalFlow = index
			},
			handleDelRowBeforeDeal(index) {
				this.showDelModalDeal = index
			},
			confirmDel() {
				this.dataModel.Nav_JobEventPerson.splice(this.showDelModalIndex, 1)
				this.showDelModalIndex = undefined
			},
			confirmDelDetail() {
				this.dataModel.Nav_Details.splice(this.showDelModalDetail, 1)
				this.showDelModalDetail = undefined
			},
			confirmDelFlow() {
				this.dataModel.Nav_Flow.splice(this.showDelModalFlow, 1)
				this.showDelModalFlow = undefined
			},
			confirmDelDeal() {
				this.dataModel.Nav_Measure.splice(this.showDelModalDeal, 1)
				this.showDelModalDeal = undefined
			},
			handleSearchUser(val, pageIndex) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "NAME", '', pageIndex)
				extendInclude(json, "Nav_Department")
				extendRule(json, 'ENABLE_STATUS', 1, '0')
				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;
				}
			
				getUserLists(json).then(res => {
					if (res.IsSuccessful) {
						this.userLists = res.Data.map(i => {
							return {
								...i,
								name: i.NAME,
								code: i.CODE
							}
						})
						this.curTotal = res.TotalCount
					}
				})
			},
			handleSelectedUser(val) {
				this.showPopup = false
				this.lists = []
				const result = this.dataModel.Nav_JobEventPerson.map((obj) => {
					const {
						Nav_User
					} = obj
					if (Nav_User.CODE === this.currentOperateUser.CODE) {
						return Object.assign({}, obj, {
							Nav_User: val,
							USER_ID:val.ID,
						})
					}
					return obj
				})

				this.dataModel.Nav_JobEventPerson = result
			},
			handleClosePopup() {
				this.showPopup = false
			},
			handleChangeUser(user) {
				this.currentOperateUser = user
				this.showPopup = true
				this.handleSearchUser('init')
			},
			onConfirmPicker(e) {
				const {
					name,
					dataIndex,
					formIndex
				} = this.comPickerInfo
				if (formIndex === "sForm1") {
					const result = this.dataModel.Nav_JobEventPerson.map((obj, index) => {
						if (index === dataIndex) {
							return Object.assign({}, obj, {
								// ATTEND_STATUS: e.value[0].ID,
							})
						}
						return obj
					})
					this.dataModel.Nav_JobEventPerson = result
				} else {

				}
				if(name==="IS_CONFIRM_SAFE")
				{
					this.dataModel.Nav_Details[dataIndex].IS_CONFIRM = e.value[0].ID
					this.dataModel.Nav_Details[dataIndex].IS_CONFIRM_SHOW = e.value[0].NAME
				}
				if(name==="IS_CONFIRM_MEAS")
				{
					this.dataModel.Nav_Flow[dataIndex].IS_CONFIRM = e.value[0].ID
					this.dataModel.Nav_Flow[dataIndex].IS_CONFIRM_SHOW = e.value[0].NAME
				}
				if(name==="IS_CONFIRM_DEAL")
				{
					this.dataModel.Nav_Measure[dataIndex].IS_CONFIRM = e.value[0].ID
					this.dataModel.Nav_Measure[dataIndex].IS_CONFIRM_SHOW = e.value[0].NAME
				}
				this.comPickerInfo.showSheet = false
			},
			closePicker() {
				this.comPickerInfo = {
					showSheet: false,
					columns: [],
					title: '',
					name: '',
					dataIndex: undefined,
					formIndex: undefined
				}
			},
			handleDelAction({
				name
			}) {
				uni.showModal({
					title: '是否删除数据？',
					success: (res) => {
						if (res.confirm) {

						}
					}
				})
			},
			submit() {
				const ele = this.$refs
				ele['wForm'].validate().then(res => {
					this.dataModel.PUBLISH = "SaveAndNotify";
					this.dataModel.TaskID = this.TaskID;
					this.dataModel.ID = this.ID;
					this.dataModel.ORG_ID =uni.getStorageSync('orgId')
					if(this.dataModel.JOB_DATE.indexOf("<br/>"))
					{
						let jobDate=this.dataModel.JOB_DATE.replace("<br/>","-")
						this.dataModel.JOB_DATE = jobDate
					}
					const resultDetail = this.dataModel.Nav_Details.map((obj, index) => {
						let navFiles=[];
						obj.Nav_Files.map(item=>{
							navFiles.push({
								IMG_FILE_ID: item.responseText.imgFileID,
								T_FO_JOB_EVENT_MEASURE_ID:obj.ID,
								ORG_ID:uni.getStorageSync('orgId')
							})
						})
					// if (obj.IS_CONFIRM === "是") {
					// 	return Object.assign({}, obj, {
					// 		IS_CONFIRM: true,
					// 		Nav_Files:navFiles
					// 	})
					// }
					// else
					// {
						return Object.assign({}, obj, {
							IS_CONFIRM: obj.IS_CONFIRM,
							Nav_Files:navFiles
						})
					// }
					return obj
					})
					this.dataModel.Nav_Details = resultDetail
					const resultFlow = this.dataModel.Nav_Flow.map((obj, index) => {
						let navFiles=[];
						obj.Nav_Files.map(item=>{
							navFiles.push({
								IMG_FILE_ID: item.responseText.imgFileID,
								T_FO_JOB_EVENT_MEASURE_ID:obj.ID,
								ORG_ID:uni.getStorageSync('orgId')
							})
						})
						// if (obj.IS_CONFIRM === "是") {
						// 	return Object.assign({}, obj, {
						// 		IS_CONFIRM: true,
						// 		Nav_Files:navFiles
						// 	})
						// }
						// else
						// {
							return Object.assign({}, obj, {
								IS_CONFIRM: obj.IS_CONFIRM,
								Nav_Files:navFiles
							})
						// }
						return obj
					})
					this.dataModel.Nav_Flow = resultFlow
					const resultDeal = this.dataModel.Nav_Measure.map((obj, index) => {
						let navFiles=[];
						obj.Nav_Files.map(item=>{
							navFiles.push({
								IMG_FILE_ID: item.responseText.imgFileID,
								T_FO_JOB_EVENT_MEASURE_ID:obj.ID,
								ORG_ID:uni.getStorageSync('orgId')
							})
						})
						// if (obj.IS_CONFIRM === "是") {
						// 	return Object.assign({}, obj, {
						// 		IS_CONFIRM: true,
						// 		Nav_Files:navFiles
						// 	})
						// }
						// else
						// {
							return Object.assign({}, obj, {
								IS_CONFIRM: obj.IS_CONFIRM,
								Nav_Files:navFiles
							})
						// }
						return obj
					})
					this.dataModel.Nav_Measure = resultDeal
					saveJobEventRecord(this.dataModel).then(res => {
						uni.$showMsgFunc('操作成功!', () => {
							if (this.tableKey == null || this.tableKey == 0) {
								uni.navigateTo({
									url: 'jobEventRecord'
								})
							} else {
								uni.navigateBack()
							}
						}, 'success', 1000)
					})
				}).catch(err => {
					uni.$showErrorInfo('请检查必填项，必填项不能为空')
				})
			},
			uploadFilePromise(url) {
				const appInfoData = uni.getStorageSync('appInfo')
				const userId = appInfoData?.User?.ID || ''
				const orgId = uni.getStorageSync('orgId')
				const tenant = uni.getStorageSync('Tenant') || ''
				const remoteUrl = config.serviceHost('/PF/File/UploadFile')
				return new Promise((resolve, reject) => {
					uni.uploadFile({
						url: remoteUrl,
						filePath: url,
						fileList: url,
						name: 'file',
						formData: {
							OrgId: orgId
						},
						header: {
							Tenant: tenant,
							userid: userId
						},
						success: (res) => {
							if (res.statusCode === 200) {
								const uploadResult = JSON.parse(res.data)
								if (uploadResult.IsSuccessful) {
									resolve(uploadResult.Data)
								}
							}
						}
					});
				})
			},
		}
	}
</script>

<style scoped>
	.page-wrap {
		padding: 16px 16px 66px;
	}

	.card {
		margin-bottom: 18px;
	}

	.sub-form {
		margin-bottom: 16px;
	}
	.sub-form-btn {
		margin-bottom: 8px;
	}
	.bottom-button {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 10px 16px;
		box-sizing: border-box;
		background: #fff;
		z-index: 999;
	}

	.upload-title {
		color: #303133;
		font-size: 15px;
		line-height: 22px;
		padding: 8px 0;
	}
	
	.collapse-title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
	}
	.collapse-title .down {
		width: 20px;
		flex: 0 0 auto;
	}
	.collapse-title .text {
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
		flex: 1;
		width: calc(100% - 60px);
	}
	.collapse-title .action {
		width: 40px;
		flex: 0 0 auto;
	}

	.page-wrap>>>.u-upload__button {
		margin-bottom: 0;
	}
</style>
