<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.IS_PUBLISH==9">
					</u-form-item>
					<u--textarea v-html="dataModel.CONTEXT" border="surround" v-if="dataModel.IS_PUBLISH==9"
						disabled></u--textarea>
					<u-form-item label="编号" prop="CODE" borderBottom>
						<u--input v-model="dataModel.CODE" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="发起人" prop="userName" borderBottom>
						<u--input v-model="dataModel.Nav_CreateUser.NAME" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="发起时间" prop="CREATE_TIME" borderBottom>
						<u--input v-model="dataModel.CREATE_TIME" disabled  border="none" disabledColor="#ffffff"
							inputAlign="right"></u--input>
					</u-form-item>
					<view class="upload-title">附件</view>
					<full-upload v-model="dataModel.Nav_AnalyzeFiles"></full-upload>
				</u--form>
			</uni-card>
		</view>
		<u-sticky offset-top="20">
			<view class="sub-form">
				<view class="sub-form-wrap">
					<view class="sub-form-btns">
						<view class="sub-form-btn" @click="handleAdd">
							<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_Users">
								<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>
										<button 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>
		</u-sticky>
		
		<u-sticky offset-top="20">
			<view class="sub-form">
				<view class="sub-form-wrap">
					<view class="sub-form-btns">
						<view class="sub-form-btn">
							<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_AnalyzeDetails">
								<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_OperationStep'].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="OperationStepName" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item['Nav_OperationStep'].NAME"
															border="none" inputAlign="right"></u--input>
										
									</u-form-item>
									<u-form-item label="作业周期" prop="CYCLE_TYPE_SHOW" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.CYCLE_TYPE_SHOW"
															border="none" inputAlign="right"></u--input>
										
									</u-form-item>
									<u-form-item label="伤害" prop="AnalyzeH" borderBottom 
									@click="handleShowSheet({title: '伤害', name: 'AnalyzeH', dataIndex: index})">
										<u--input v-model="item['Nav_DistinguishAnalyzeH'].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 label="损失" prop="AnalyzeL" borderBottom
									@click="handleShowSheet({title: '损失', name: 'AnalyzeL', dataIndex: index})">
										<u--input v-model="item['Nav_DistinguishAnalyzeL'].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 label="环境污染" prop="AnalyzeE" borderBottom
									@click="handleShowSheet({title: '环境污染', name: 'AnalyzeE', dataIndex: index})">
										<u--input  v-model="item['Nav_DistinguishAnalyzeE'].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 label="概率" prop="AnalyzeP" borderBottom
									@click="handleShowSheet({title: '概率', name: 'AnalyzeP', dataIndex: index})">
										<u--input  v-model="item['Nav_DistinguishAnalyzeP'].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 label="重复发生率" prop="AnalyzeR" borderBottom
									@click="handleShowSheet({title: '重复发生率', name: 'AnalyzeR', dataIndex: index})">
										<u--input v-model="item['Nav_DistinguishAnalyzeR'].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 label="总得分" prop="AnalyzeR" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.SCORE"
															border="none" inputAlign="right"></u--input>
										
									</u-form-item>
									<u-form-item label="关键任务" prop="IS_MAINTASK_SHOW" borderBottom
									@click="handleShowSheet({title: '关键任务', name: 'IS_MAINTASK', dataIndex: index})">
										<u--input disabled disabledColor="#fff" v-model="item.IS_MAINTASK_SHOW"
															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="WorkPermitType" borderBottom
									@click="handleShowSheet({title: '许可类别', name: 'WorkPermitType', dataIndex: index})">
										<u--input v-model="item['Nav_WorkPermitType'].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 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>
		</u-sticky>
		<u-modal :show="showDelModalIndex >= 0" @confirm="confirmDel" title="确认删除？"></u-modal>
		<u-picker :show="comPickerInfo.showSheet" :columns="comPickerInfo.columns" @confirm="onConfirmPicker"
			@close="closePicker" @cancel="closePicker" keyName="NAME"></u-picker>
		<query-selector :show="showPopup"  :total="curTotal" :lists="userLists" :defaultValue="currentOperateUser.NAME"
			@close="handleClosePopup" @search="handleSearchUser" @select="handleSelectedUser" />
		<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 {
		getAnalyzeGet,
		getAnalyzeSign,
		getAnalyzeHLists,
		getAnalyzeLLists,
		getAnalyzeELists,
		getAnalyzePLists,
		getAnalyzeRLists,
		getWorkPermitTypeLists,
		saveAnalyzeRecord
	} from '../../../../services/apply/HMServices/HMServices.js'
	import {
		getUserLists,
	} from '../../../../services/apply/FOServices/FOServices.js'
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				ID:null,
				TaskID:null,
				tableKey:0,
				curTotal: 0,
				isLoadOK :false,
				showDelModalIndex: undefined,
				userLists: [],
				dataModel: {
					CODE:'',
					Nav_AnalyzeDetails:[],
					Nav_AnalyzeFiles:[],
					Nav_Users:[],
					Nav_CreateUser:[],
					CREATE_TIME:null,
					COMPLETION_TIME:null,
				},
				subDataModel: {
					Nav_Users:{
						Nav_User: {
							NAME: '',
							CODE: '',
						},
					},
					Nav_AnalyzeDetails:{
						CYCLE_TYPE:0,
						CYCLE_TYPE_SHOW:"需求作业",
						IS_MAINTASK:0,
						IS_MAINTASK_SHOW:"否",
						Nav_DistinguishAnalyzeH:{NAME:'',SCORE:0},
						Nav_DistinguishAnalyzeL:{NAME:'',SCORE:0},
						Nav_DistinguishAnalyzeE:{NAME:'',SCORE:0},
						Nav_DistinguishAnalyzeP:{NAME:'',SCORE:0},
						Nav_DistinguishAnalyzeR:{NAME:'',SCORE:0},
						Nav_WorkPermitType:{NAME:''},
						Nav_OperationStep:{NAME:''},
						SCORE:0
					}
				},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				currentOperateUser: {},
				showPopup: false,
				rules: {
					'CODE': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change']
					},
				},
			}
		},
		onLoad(opt) {
			this.handleGetAnalyzeGet(opt)
		},
		methods: {
			handleGetAnalyzeGet(opt) {
				this.TaskID = opt.taskID ? opt.taskID : null;
				this.ID = opt.ID ? opt.ID : null;
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				 extendRule(json, 'ID', 1, opt.ID)
				// TODO: id 未获取
				getAnalyzeGet(json).then(res => {
					this.dataModel = res.Data
					// //数据组装
					// let strUserFiles = [{
					// 	url: '',
					// 	name:''
					// }]
					// if (res.Data.Nav_AnalyzeFiles && res.Data.Nav_AnalyzeFiles.length > 0) {
					// 	for (let i = 0; i < res.Data.Nav_AnalyzeFiles.length; i++) {
					// 		strUserFiles.push({
					// 			url: config.uni_app_web_local_api_url+res.Data.Nav_AnalyzeFiles[i].Nav_ImgFile.Nav_File.FILE_PATH,
					// 			name:res.Data.Nav_AnalyzeFiles[i].Nav_ImgFile.FILE_NAME
					// 		})
					// 	}
					// }
					// //数据组装
					// let strUserName = ''
					// if (res.Data.Nav_Users && res.Data.Nav_Users.length > 0) {
					// 	for (let i = 0; i < res.Data.Nav_Users.length; i++) {
					// 		if (res.Data.Nav_Users[i].DEAL_STATUS == 0) {
					// 			strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + "<text style='color:red'>" +
					// 				res.Data.Nav_Users[i].Nav_User.NAME + "</text>";
					// 		} else {
					// 			let user=res.Data.Nav_Users[i].USER_ID!=null?res.Data.Nav_Users[i].Nav_User.NAME:'';
					// 			strUserName += (strUserName.length > 0 ? "&nbsp;&nbsp;" : "") + user;
					// 		}
					
					// 	}
					// }
					if (res.Data.Nav_AnalyzeDetails && res.Data.Nav_AnalyzeDetails.length > 0) {
						for (let i = 0; i < res.Data.Nav_AnalyzeDetails.length; i++) {
							if (res.Data.Nav_AnalyzeDetails[i].CYCLE_TYPE == 0) {
								res.Data.Nav_AnalyzeDetails[i].CYCLE_TYPE_SHOW = "需求作业"
							} else {
								res.Data.Nav_AnalyzeDetails[i].CYCLE_TYPE_SHOW="每日作业"
							}
							if(res.Data.Nav_AnalyzeDetails[i].IS_MAINTASK == 0){
								res.Data.Nav_AnalyzeDetails[i].IS_MAINTASK_SHOW = "否"
							}else {
								res.Data.Nav_AnalyzeDetails[i].IS_MAINTASK_SHOW="是"
							}
							if(res.Data.Nav_AnalyzeDetails[i].ANALYZE_H_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_DistinguishAnalyzeH={CODE:'',NAME:'',SCORE:0}
							}
							if(res.Data.Nav_AnalyzeDetails[i].ANALYZE_E_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_DistinguishAnalyzeE={CODE:'',NAME:'',SCORE:0}
							}
							if(res.Data.Nav_AnalyzeDetails[i].ANALYZE_P_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_DistinguishAnalyzeP={CODE:'',NAME:'',SCORE:0}
							}
							if(res.Data.Nav_AnalyzeDetails[i].ANALYZE_R_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_DistinguishAnalyzeR={CODE:'',NAME:'',SCORE:0}
							}
							if(res.Data.Nav_AnalyzeDetails[i].ANALYZE_L_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_DistinguishAnalyzeL={CODE:'',NAME:'',SCORE:0}
							}
							if(res.Data.Nav_AnalyzeDetails[i].WORK_PERMIT_TYPE_ID ===null)
							{
								res.Data.Nav_AnalyzeDetails[i].Nav_WorkPermitType={CODE:'',NAME:''}
							}
						}
					}
					// this.dataModel.UserNames = strUserName
					// this.dataModel.UserFiles = strUserFiles
					this.isLoadOK = true
				})
			},
			handleDelRowBefore(index) {
				this.showDelModalIndex = index
			},
			confirmDel() {
				this.dataModel.Nav_Users.splice(this.showDelModalIndex, 1)
				this.showDelModalIndex = undefined
			},
			handleAdd() {
				const identifyUser = JSON.parse(JSON.stringify(this.subDataModel.Nav_Users))
				this.dataModel.Nav_Users.unshift(identifyUser)
			},
			handleSearchUser(val, pageIndex) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "NAME", '', pageIndex)
				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_Users.map((obj) => {
					const {
						Nav_User,USER_ID,
					} = obj
					if (Nav_User.CODE === this.currentOperateUser.CODE) {
						return Object.assign({}, obj, {
							Nav_User: val,
							USER_ID:val.ID,
						})
					}
					return obj
				})
				
				this.dataModel.Nav_Users=result
			},
			handleClosePopup() {
				this.showPopup = false
			},
			handleChangeUser(user) {
				this.currentOperateUser = user
				this.showPopup = true
				this.handleSearchUser('init')
			},
			//下拉数据加载
			async handleShowSheet(p) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "", 0)
				let dataSelect = []
				if (p.name === 'IS_MAINTASK') {
					dataSelect = [{
							NAME: '否',
							ID: 0
						},
						{
							NAME: '是',
							ID: 1
						}
					]
				}else if (p.name === 'AnalyzeH') {
					dataSelect = await getAnalyzeHLists(json).then(res => {
						return res
					})
				} 
				else if(p.name === 'AnalyzeL')
				{
					dataSelect = await getAnalyzeLLists(json).then(res => {
						return res
					})
				}
				else if(p.name === 'AnalyzeE')
				{
					dataSelect = await getAnalyzeELists(json).then(res => {
						return res
					})
				}
				else if(p.name === 'AnalyzeP')
				{
					dataSelect = await getAnalyzePLists(json).then(res => {
						return res
					})
				}
				else if(p.name === 'AnalyzeR')
				{
					dataSelect = await getAnalyzeRLists(json).then(res => {
						return res
					})
				}
				else if(p.name === 'WorkPermitType')
				{
					dataSelect = await getWorkPermitTypeLists(json).then(res => {
						return res
					})
				}
				if (dataSelect.length) {
					this.comPickerInfo = {
						showSheet: true,
						title: p.title,
						name: p.name,
						dataIndex:p.dataIndex,	
						formIndex: p.formIndex,
						columns: [dataSelect]
					}
				} else {
					// 暂无数据
				}
			},
			closePicker() {
				this.comPickerInfo = {
					showSheet: false,
					columns: [],
					title: '',
					name: '',
					dataIndex: undefined,
					formIndex: undefined
				}
			},
			onConfirmPicker(e) {
				const {
					name,
					dataIndex,
					formIndex
				} = this.comPickerInfo
				if(name === "IS_MAINTASK")
				{
					this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = e.value[0].ID
					this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = e.value[0].NAME
				}
				else if (name === "AnalyzeH") {
					this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeH = e.value[0];
					this.dataModel.Nav_AnalyzeDetails[dataIndex].ANALYZE_H_ID = e.value[0].ID;
					let a=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeH.SCORE;
					let b=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeL.SCORE;
					let c=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeE.SCORE;
					let d=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeP.SCORE;
					let x=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeR.SCORE;
					a=a==undefined?0:a;
					b=b==undefined?0:b;
					c=c==undefined?0:c;
					d=d==undefined?0:d;
					x=x==undefined?0:x;
					if(a*b*c*d*x > 15)
					{this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = 1
					this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = "是"}
					else
					{
						this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = 0
						this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = "否"
					}
					this.dataModel.Nav_AnalyzeDetails[dataIndex].SCORE = a*b*c*d*x
				} 
				else if(name === "AnalyzeL")
				{
					this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeL = e.value[0]
					this.dataModel.Nav_AnalyzeDetails[dataIndex].ANALYZE_L_ID = e.value[0].ID
					let a=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeH.SCORE;
					let b=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeL.SCORE;
					let c=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeE.SCORE;
					let d=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeP.SCORE;
					let x=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeR.SCORE;
					a=a==undefined?0:a;
					b=b==undefined?0:b;
					c=c==undefined?0:c;
					d=d==undefined?0:d;
					x=x==undefined?0:x;
					if(a*b*c*d*x > 15)
					{this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = 1
					this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = "是"}
					else
					{
						this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = 0
						this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = "否"
					}
					this.dataModel.Nav_AnalyzeDetails[dataIndex].SCORE = a*b*c*d*x 
				}
				else if(name === "AnalyzeE")
				{
					this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeE = e.value[0]
					this.dataModel.Nav_AnalyzeDetails[dataIndex].ANALYZE_E_ID = e.value[0].ID
					let a=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeH.SCORE;
					let b=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeL.SCORE;
					let c=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeE.SCORE;
					let d=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeP.SCORE;
					let x=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeR.SCORE;
					a=a==undefined?0:a;
					b=b==undefined?0:b;
					c=c==undefined?0:c;
					d=d==undefined?0:d;
					x=x==undefined?0:x;
					if(a*b*c*d*x > 15)
					{this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = 1
					this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = "是"}
					else
					{
						this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = 0
						this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = "否"
					}
					this.dataModel.Nav_AnalyzeDetails[dataIndex].SCORE = a*b*c*d*x
				}
				else if(name === "AnalyzeP")
				{
					this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeP = e.value[0]
					this.dataModel.Nav_AnalyzeDetails[dataIndex].ANALYZE_P_ID = e.value[0].ID
					let a=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeH.SCORE;
					let b=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeL.SCORE;
					let c=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeE.SCORE;
					let d=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeP.SCORE;
					let x=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeR.SCORE;
					a=a==undefined?0:a;
					b=b==undefined?0:b;
					c=c==undefined?0:c;
					d=d==undefined?0:d;
					x=x==undefined?0:x;
					if(a*b*c*d*x > 15)
					{this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = 1
					this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = "是"}
					else
					{
						this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = 0
						this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = "否"
					}
					this.dataModel.Nav_AnalyzeDetails[dataIndex].SCORE = a*b*c*d*x
				}
				else if(name === "AnalyzeR")
				{
					this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeR = e.value[0]
					this.dataModel.Nav_AnalyzeDetails[dataIndex].ANALYZE_R_ID = e.value[0].ID
					let a=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeH.SCORE;
					let b=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeL.SCORE;
					let c=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeE.SCORE;
					let d=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeP.SCORE;
					let x=this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_DistinguishAnalyzeR.SCORE;
					a=a==undefined?0:a;
					b=b==undefined?0:b;
					c=c==undefined?0:c;
					d=d==undefined?0:d;
					x=x==undefined?0:x;
					if(a*b*c*d*x > 15)
					{this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = 1
					this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = "是"}
					else
					{
						this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK = 0
						this.dataModel.Nav_AnalyzeDetails[dataIndex].IS_MAINTASK_SHOW = "否"
					}
					this.dataModel.Nav_AnalyzeDetails[dataIndex].SCORE = a*b*c*d*x
				}
				else if(name === "WorkPermitType")
				{
					this.dataModel.Nav_AnalyzeDetails[dataIndex].Nav_WorkPermitType = e.value[0]
					this.dataModel.Nav_AnalyzeDetails[dataIndex].WORK_PERMIT_TYPE_ID = e.value[0].ID
				}
				this.comPickerInfo.showSheet = false
			},
			submit() {
				const ele = this.$refs
				ele['wForm'].validate().then(res => {
					this.dataModel.PUBLISH = "SaveAndNotify";
					if (this.TaskID != "") {
						this.dataModel.TaskID = this.TaskID;
					}
					this.dataModel.ID = this.ID;
					this.dataModel.ORG_ID =uni.getStorageSync('orgId')
					if(this.dataModel.Nav_AnalyzeFiles)
					{
						const result = this.dataModel.Nav_AnalyzeFiles.map((obj) => {
							// const {
							// 	IMG_FILE_ID,PRE_OPER_SCH_ID,ORG_ID
							// } = obj
								return Object.assign({}, obj, {
									IMG_FILE_ID: obj.IMG_FILE_ID ===null?obj.responseText.imgFileID:obj.IMG_FILE_ID,
									OPERATION_TASK_DISTINGUISH_ANALYZE_ID:this.dataModel.ID,
									ORG_ID:uni.getStorageSync('orgId')
								})
							return obj
						})
						this.dataModel.Nav_AnalyzeFiles = result
					}
					
					saveAnalyzeRecord(this.dataModel).then(res => {
						uni.$showMsgFunc('操作成功!', () => {
							// if (this.tableKey == null || this.tableKey == 0) {
							// 	uni.navigateTo({
							// 		url: 'jobTaskAnalyzeRecord'
							// 	})
							// } 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>
	@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>
