<template>
	<view>
		<!-- <step-title :stepPage = "stepsPage" :stepText = "stepsText"></step-title> -->
		<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="CODE" borderBottom>
							<u--input v-model="dataModel.CODE" disabled disabledColor="#ffffff" placeholder="请输入编号" 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" disabled disabledColor="#ffffff" placeholder="请输入作业地点" border="none" inputAlign="right"></u--input>
						</u-form-item>
						<u-form-item label="开始时间" prop="JOB_DATE" borderBottom>
							<u--input v-model="dataModel.JOB_DATE" disabled disabledColor="#ffffff" placeholder="请输入作业时间" border="none" inputAlign="right">
							</u--input>
						</u-form-item>
						<u-form-item label="结束时间" prop="JOB_END_DATE" borderBottom>
							<u--input v-model="dataModel.JOB_END_DATE" disabled disabledColor="#ffffff" placeholder="请输入作业时间" border="none" inputAlign="right">
							</u--input>
						</u-form-item>
						<u-form-item label="采取有效风险控制措施" prop="IS_EFFECTIVE_SHOW" borderBottom @click="handleShowSheet({title: '控制措施', name: 'IS_EFFECTIVE'})">
							<u--input :value="dataModel.IS_EFFECTIVE_SHOW" disabled disabledColor="#fff" 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="EFFECTIVE" borderBottom v-if="dataModel.IS_EFFECTIVE==0" required>
						</u-form-item>
						<u--textarea v-model="dataModel.EFFECTIVE" placeholder="请输入描述内容" border="surround" inputAlign="left" v-if="dataModel.IS_EFFECTIVE==0" :required="dataModel.IS_EFFECTIVE==0">
						</u--textarea>
						<u-form-item label="人员未存在违规行为" prop="IS_EXIST_SHOW" borderBottom @click="handleShowSheet({title: '违规行为', name: 'IS_EXIST'})">
							<u--input v-model="dataModel.IS_EXIST_SHOW" 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="EXIST" borderBottom v-if="dataModel.IS_EXIST==0" required>
						</u-form-item>
						<u--textarea v-model="dataModel.EXIST" placeholder="请输入描述内容" border="surround" inputAlign="left" v-if="dataModel.IS_EXIST==0" :required="dataModel.IS_EXIST==0">
						</u--textarea>
						<u-form-item label="作业人员习惯合适" prop="IS_SUITABLE_SHOW" borderBottom @click="handleShowSheet({title: '习惯合适', name: 'IS_SUITABLE'})">
							<u--input v-model="dataModel.IS_SUITABLE_SHOW" 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="SUITABLE" borderBottom v-if="dataModel.IS_SUITABLE==0" required>
						</u-form-item>
						<u--textarea v-model="dataModel.SUITABLE" placeholder="请输入描述内容" border="surround" inputAlign="left" v-if="dataModel.IS_SUITABLE==0" :required="dataModel.IS_SUITABLE==0">
						</u--textarea>
						<u-form-item label="作业人员无需再培训" prop="IS_NEED_SHOW" borderBottom @click="handleShowSheet({title: '需再培训', name: 'IS_NEED'})">
							<u--input v-model="dataModel.IS_NEED_SHOW" 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="NEED" borderBottom v-if="dataModel.IS_NEED==0" required>
						</u-form-item>
						<u--textarea v-model="dataModel.NEED" placeholder="请输入描述内容" border="surround" inputAlign="left" v-if="dataModel.IS_NEED==0" :required="dataModel.IS_NEED==0">
						</u--textarea>
						<u-form-item label="操作规程无需再改进" prop="IS_REQUIRES_SHOW" borderBottom @click="handleShowSheet({title: '需再改进', name: 'IS_REQUIRES'})">
							<u--input v-model="dataModel.IS_REQUIRES_SHOW" 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="REQUIRES" borderBottom v-if="dataModel.IS_REQUIRES==0" required>
						</u-form-item>
						<u--textarea v-model="dataModel.REQUIRES" placeholder="请输入描述内容" border="surround" inputAlign="left" v-if="dataModel.IS_REQUIRES==0" :required="dataModel.IS_REQUIRES==0">
						</u--textarea>
					</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-circle" color="#3c9cff" size="21"></u-icon>
							<u--text type="primary" text="增加作业人员"></u--text>
						</view>
					</view>
					<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm1">
						<uni-collapse accordion>
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false" v-for="(item, index) in dataModel.Nav_JobActivityPerson">
								<uni-collapse-item title-border="none" :show-arrow="false" :border="false" :open="true">
									<view slot="title" class="custom-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" @click.stop>
											<u-icon @click="handleDelRowBefore(index)" class="icon" name="trash" color="#ff4d4f" size="21"></u-icon>
										</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-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-circle" color="#3c9cff" size="21"></u-icon>
							<u--text type="primary" text="新增作业前确认"></u--text>
						</view>
					</view>
					<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm2">
						<uni-collapse accordion>
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false" v-for="(item, index) in dataModel.Nav_Details">
								<uni-collapse-item title-border="none" :show-arrow="false" :border="false" :open="true">
									<view slot="title" class="custom-collapse-title">
										<view class="down">
											<uni-icons type="bottom"></uni-icons>
										</view>
										<view class="text">{{index + 1 + '. ' +item.SafeConfirmsStr}}</view>
										<text @click.stop="handleOkRowDetail(index)">
											<!-- 										<u--text type="primary" text="确认"></u--text> -->
											<u-icon name="checkmark-circle" size="20" color="#3C9CFF" v-if="dataModel.Nav_Details[index].IS_CONFIRM===false"></u-icon>
											<u-icon name="checkmark-circle" size="20" color="#55aa00" v-if="dataModel.Nav_Details[index].IS_CONFIRM===true"></u-icon>
										</text>
										<view class="action" @click.stop>
											<u-icon @click="handleDelRowBeforeDetail(index)" class="icon" name="trash" color="#ff4d4f" size="21"></u-icon>
										</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-circle" color="#3c9cff" size="21"></u-icon>
							<u--text type="primary" text="新增作业流程及安全措施"></u--text>
						</view>
					</view>
					<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm3">
						<uni-collapse accordion>
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false" v-for="(item, index) in dataModel.Nav_Flow">
								<uni-collapse-item title-border="none" :show-arrow="false" :border="false" :open="true">
									<view slot="title" class="custom-collapse-title">
										<view class="down">
											<uni-icons type="bottom"></uni-icons>
										</view>
										<view class="text">{{index + 1 + '. ' +item.SafeMeasuresStr}}</view>
										<text @click.stop="handleOkRowFlow(index)">
											<u-icon name="checkmark-circle" size="20" color="#3C9CFF" v-if="dataModel.Nav_Flow[index].IS_CONFIRM===false"></u-icon>
											<u-icon name="checkmark-circle" size="20" color="#55aa00" v-if="dataModel.Nav_Flow[index].IS_CONFIRM===true"></u-icon>
										</text>
										<view class="action" @click.stop>
											<u-icon @click="handleDelRowBeforeFlow(index)" class="icon" name="trash" color="#ff4d4f" size="21"></u-icon>
										</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_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="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-circle" color="#3c9cff" size="21"></u-icon>
							<u--text type="primary" text="新增作业后处理措施"></u--text>
						</view>
					</view>
					<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm4">
						<uni-collapse accordion>
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false" v-for="(item, index) in dataModel.Nav_Measure">
								<uni-collapse-item title-border="none" :show-arrow="false" :border="false" :open="true">
									<view slot="title" class="custom-collapse-title">
										<view class="down">
											<uni-icons type="bottom"></uni-icons>
										</view>
										<view class="text">{{index + 1 + '. ' +item.DealMeasuresStr}}</view>
										<text @click.stop="handleOkRowDeal(index)">
											<u-icon name="checkmark-circle" size="20" color="#3C9CFF" v-if="dataModel.Nav_Measure[index].IS_CONFIRM===false"></u-icon>
											<u-icon name="checkmark-circle" size="20" color="#55aa00" v-if="dataModel.Nav_Measure[index].IS_CONFIRM===true"></u-icon>
										</text>
										<view class="action" @click.stop>
											<u-icon @click="handleDelRowBeforeDeal(index)" class="icon" name="trash" color="#ff4d4f" size="21"></u-icon>
										</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_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="handleDelRowBeforeDeal(index)">删除</button>
								</u-form-item> -->
								</uni-collapse-item>
							</uni-card>
						</uni-collapse>
					</u--form>
				</view>
			</view>
			<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>
			<query-selector :show="showPopup" :total="curTotal" :lists="userLists" :defaultValue="currentOperateUser.NAME" @close="handleClosePopup" @search="handleSearchUser" @select="handleSelectedUser" />
			<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>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup,
		extendIgnoreDataRule
	} from '../../../../utils/common'
	import {
		getRequest,
		getUserLists,
		saveJobActivityRecord
	} from '../../../../services/apply/FOServices/FOServices.js'
	import config from '../../../../config/common'
	import stepTitle from '@/components/custom/step-title.vue'

	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				ID: '',
				TaskID: '',
				curTotal: 0,
				showDelModalIndex: undefined,
				showDelModalDetail: undefined,
				showDelModalFlow: undefined,
				showDelModalDeal: undefined,
				isLoadOK: false,
				tableKey: 0,
				userLists: [],
				stepsText:['基本信息','作业人员','作业前期','作业中期','作业后期'],
				dataModel: {
					Nav_OperationStep: {},
					CODE: '',
					JOB_LOCATION: '',
					JOB_DATE: '',
					Nav_Details: {
						NUM: 0,
						SafeConfirmsStr: '',
						IS_CONFIRM: false,
						IS_CONFIRM_SHOW: '否',
						Nav_Files: []
					},
					Nav_Flow: {
						NUM: 0,
						SafeMeasuresStr: '',
						IS_CONFIRM: false,
						IS_CONFIRM_SHOW: '否',
						Nav_Files: []
					},
					Nav_Measure: {
						NUM: 0,
						DealMeasuresStr: '',
						IS_CONFIRM: false,
						IS_CONFIRM_SHOW: '否',
						Nav_Files: []
					}
				},
				subDataModel: {
					Nav_User: {
						Nav_Department: {
							NAME: ''
						},
						NAME: '',
						CODE: '',
					},
					Nav_Details: {
						NUM: 0,
						SafeConfirmsStr: '',
						IS_CONFIRM: false,
						IS_CONFIRM_SHOW: '否',
						Nav_Files: []
					},
					Nav_Flow: {
						NUM: 0,
						SafeMeasuresStr: '',
						IS_CONFIRM: false,
						IS_CONFIRM_SHOW: '否',
						Nav_Files: []
					},
					Nav_Measure: {
						NUM: 0,
						DealMeasuresStr: '',
						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']
					},
					'EFFECTIVE': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'EXIST': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'SUITABLE': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'NEED': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
					'REQUIRES': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
				},

				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				currentOperateUser: {},
				showPopup: false,
				stepsPage:0,
			}
		},
		onLoad(opt) {
			this.handleGetJobActivityGet(opt)
		},
		methods: {
			handleGetJobActivityGet(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_TechDisclosure');
				//    extendInclude(json, 'Nav_JobName');
				//    extendInclude(json, 'Nav_OperationStep');
				//    extendInclude(json, 'Nav_JobActivityPerson');
				// extendInclude(json, 'Nav_JobActivityPerson.Nav_User.Nav_Department');
				//     extendInclude(json, 'Nav_Details.Nav_Files');
				//     extendInclude(json, 'Nav_Flow.Nav_Files');
				//     extendInclude(json, 'Nav_Measure.Nav_Files');
				// TODO: id 未获取
				getRequest(json, "/FO/FOJobActivityRecord/GetEdit").then(res => {
					this.dataModel = res
					this.dataModel.IS_EFFECTIVE == 0 ? this.dataModel.IS_EFFECTIVE_SHOW = "否" : this.dataModel
						.IS_EFFECTIVE_SHOW = "是";
					this.dataModel.IS_EXIST == 0 ? this.dataModel.IS_EXIST_SHOW = "否" : this.dataModel
						.IS_EXIST_SHOW = "是";
					this.dataModel.IS_SUITABLE == 0 ? this.dataModel.IS_SUITABLE_SHOW = "否" : this.dataModel
						.IS_SUITABLE_SHOW = "是";
					this.dataModel.IS_NEED == 0 ? this.dataModel.IS_NEED_SHOW = "否" : this.dataModel
						.IS_NEED_SHOW = "是";
					this.dataModel.IS_REQUIRES == 0 ? this.dataModel.IS_REQUIRES_SHOW = "否" : this.dataModel
						.IS_REQUIRES_SHOW = "是";
					if (res.JOB_DATE) {
						res.JOB_DATE = uni.$u.timeFormat(res.JOB_DATE, 'yyyy-mm-dd hh:MM')
					}
					if (res.JOB_END_DATE) {
						res.JOB_END_DATE = uni.$u.timeFormat(res.JOB_END_DATE, 'yyyy-mm-dd hh:MM')
					}
					//数据组装
					let strUserName = ''
					if (res.Nav_JobActivityPerson && res.Nav_JobActivityPerson.length > 0) {
						for (let i = 0; i < res.Nav_JobActivityPerson.length; i++) {
							if (res.Nav_JobActivityPerson[i].DEAL_STATUS == 0) {
								strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + "<text style='color:red'>" +
									res.Nav_JobActivityPerson[i].Nav_User.NAME + "</text>";
							} else {
								let user = res.Nav_JobActivityPerson[i].USER_ID != null ? res.Nav_JobActivityPerson[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_EFFECTIVE' || p.name === 'IS_EXIST' || p.name ===
					'IS_SUITABLE' || p.name === 'IS_NEED' || p.name === 'IS_REQUIRES' ||
					p.name === 'IS_CONFIRM_SAFE' || p.name === 'IS_CONFIRM_MEAS' || p.name === 'IS_CONFIRM_DEAL') {
					column = [{
							NAME: '否',
							ID: 0
						},
						{
							NAME: '是',
							ID: 1
						}
					]
				}
				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_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() {
				const identifyUser = JSON.parse(JSON.stringify(this.subDataModel.Nav_JobActivityPerson))
				this.dataModel.Nav_JobActivityPerson.unshift(identifyUser)
				// this.dataModel.Nav_JobActivityPerson.unshift(this.subDataModel)
			},
			handleAddDetail() {
				const identifyUser = JSON.parse(JSON.stringify(this.subDataModel.Nav_Details))
				this.dataModel.Nav_Details.unshift(identifyUser)
				// this.dataModel.Nav_Details.unshift(this.subDataModel.Nav_Details)
			},
			handleAddFlow() {
				const identifyUser = JSON.parse(JSON.stringify(this.subDataModel.Nav_Flow))
				this.dataModel.Nav_Flow.unshift(identifyUser)
				// 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_JobActivityPerson.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_JobActivityPerson.map((obj) => {
					const {
						Nav_User
					} = obj
					if (Nav_User.CODE === this.currentOperateUser.CODE) {
						return Object.assign({}, obj, {
							Nav_User: val,
						})
					}
					return obj
				})

				this.dataModel.Nav_JobActivityPerson = 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 (name === 'IS_EFFECTIVE') {
					this.dataModel.IS_EFFECTIVE = e.value[0].ID
					this.dataModel.IS_EFFECTIVE_SHOW = e.value[0].NAME
				} else if (name === 'IS_EXIST') {
					this.dataModel.IS_EXIST = e.value[0].ID
					this.dataModel.IS_EXIST_SHOW = e.value[0].NAME
				} else if (name === 'IS_SUITABLE') {
					this.dataModel.IS_SUITABLE = e.value[0].ID
					this.dataModel.IS_SUITABLE_SHOW = e.value[0].NAME
				} else if (name === 'IS_NEED') {
					this.dataModel.IS_NEED = e.value[0].ID
					this.dataModel.IS_NEED_SHOW = e.value[0].NAME
				} else if (name === 'IS_REQUIRES') {
					this.dataModel.IS_REQUIRES = e.value[0].ID
					this.dataModel.IS_REQUIRES_SHOW = e.value[0].NAME
				} 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
				} else 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
				} else 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
				}
				if (formIndex === "sForm1") {
					const result = this.dataModel.Nav_JobActivityPerson.map((obj, index) => {
						if (index === dataIndex) {
							return Object.assign({}, obj, {
								// ATTEND_STATUS: e.value[0].ID,
							})
						}
						return obj
					})
					this.dataModel.Nav_JobActivityPerson = result
				} else {

				}
				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')
					const resultDetail = this.dataModel.Nav_Details.map((obj, index) => {
						let navFiles = [];
						obj.Nav_Files.map(item => {
							navFiles.push({
								IMG_FILE_ID: item.responseText.imgFileID,
								JOB_ACTIVITY_RECORD_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,
								JOB_ACTIVITY_RECORD_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,
								JOB_ACTIVITY_RECORD_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
					saveJobActivityRecord(this.dataModel).then(res => {
						uni.$showMsgFunc('操作成功!', () => {
							// if (this.tableKey == null || this.tableKey == 0) {
							// 	uni.navigateTo({
							// 		url: 'jobActivityRecord'
							// 	})
							// } else {
							uni.navigateBack()
							// }
						}, 'success', 1000)
					})
				}).catch(err => {
					uni.$showErrorInfo('请检查必填项，必填项不能为空') //err[0].message
				})
			},
			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>
	@import url("../../../../style/css/editTemplate.css");

	.page-wrap {
		padding: 16px 16px 166px;
	}

	.card {
		margin-bottom: 18px;
	}

	.sub-form {
		margin-bottom: 16px;
	}

	.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;
	}

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