<template>
	<view class="page-wrap">
		<uni-card margin="0" :is-shadow="true">
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" ref="wForm"
				:rules="rules">
				<u-form-item label="审核意见：" prop="AUDIT_OPINION" borderBottom v-if="model.STATUS==9">
				</u-form-item>
				<u--textarea v-html="AUDIT_OPINION" border="surround" v-if="model.STATUS==9" disabled></u--textarea>
				<u-form-item label="评价类型：" prop="EVALUATE_TYPE_SHOW" borderBottom>
					<u--input v-model="model.EVALUATE_TYPE_SHOW" border="none" slot="right" inputAlign="right" disabled
						disabledColor="fff"></u--input>
				</u-form-item>
				<u-form-item label="开始时间：" prop="START_TIME" borderBottom>
					<u--input v-model="model.START_TIME" border="none" slot="right" inputAlign="right" disabled
						disabledColor="fff"></u--input>
				</u-form-item>
				<u-form-item label="结束时间：" prop="END_TIME" borderBottom>
					<u--input v-model="model.END_TIME" border="none" slot="right" inputAlign="right" disabled
						disabledColor="fff"></u--input>
				</u-form-item>
				<u-form-item label="发起部门：" prop="Nav_InitiatingDepartment.NAME" borderBottom>
					<u--input v-if="model.Nav_InitiatingDepartment" v-model="model.Nav_InitiatingDepartment.NAME"
						border="none" slot="right" inputAlign="right" disabled disabledColor="fff"></u--input>
				</u-form-item>
				<u-form-item label="评价要求：" prop="Nav_Requirement.NAME" borderBottom>
				</u-form-item>
				<u--textarea autoHeight v-if="model.Nav_Requirement" v-model="model.Nav_Requirement.NAME" border="none"
					inputAlign="right" disabled disabledColor="#fff"></u--textarea>
				<u-form-item label="评价人员：" prop="Nav_NoteTaker.NAME" borderBottom>
					<u--input v-if="model.Nav_NoteTaker" v-model="model.Nav_NoteTaker.NAME" border="none" slot="right"
						inputAlign="right" disabled disabledColor="fff"></u--input>
				</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 class="sub-form" v-if="model.EVALUATE_TYPE==2">
			<view class="sub-form-wrap">
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
					ref="sForm">
					<u-collapse :border="false" accordion>
						<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
							v-for="(item, index) in model.Nav_Risks.filter(i => !i.IS_DELETED)">
							<u-collapse-item :title="index + 1 + '. ' + item.Nav_Area.NAME">
								<u-form-item label="区域：" prop="Nav_Area.NAME" borderBottom>
									<u--input v-model="item.Nav_Area.NAME" placeholder="请选择区域" border="none"
										inputAlign="right" disabled disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="辨识对象：" prop="Nav_Identifying.NAME" borderBottom
									@click="handleChange('Nav_Identifying',item)">
									<u--input v-model="item.Nav_Identifying.NAME" placeholder="辨识对象" border="none"
										inputAlign="right" disabled disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="风险类别：" prop="Nav_Type.NAME" borderBottom
									@click="handleChange('Nav_Type',item)">
									<u--input v-model="item.Nav_Type.NAME" placeholder="风险类别" border="none"
										inputAlign="right" disabled disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="风险名称：" prop="NAME" borderBottom>
									<u--input v-model="item.NAME" placeholder="风险名称" border="none" inputAlign="right"
										disabled disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="风险地点：" prop="RISK_PLACE" borderBottom>
									<u--input v-model="item.RISK_PLACE" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="岗位：" prop="Posts" borderBottom>
									<u--input :value="item.Posts" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="设备设施：" prop="Equs" borderBottom>
									<u--input :value="item.Equs" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="作业环节：" prop="Nav_OperationStep.NAME" borderBottom>
									<u--input v-if="item.Nav_OperationStep" v-model="item.Nav_OperationStep.NAME"
										placeholder="作业环节" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="风险评价L：" prop="EVALUATE_L" borderBottom>
									<u--input v-model="item.EVALUATE_L" type="number" border="none"
										@change="caclScore(item)" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="风险评价E：" prop="EVALUATE_E" borderBottom>
									<u--input v-model="item.EVALUATE_E" type="number" border="none"
										@change="caclScore(item)" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="风险评价C：" prop="EVALUATE_C" borderBottom>
									<u--input v-model="item.EVALUATE_C" type="number" border="none"
										@change="caclScore(item)" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="分值D：" prop="EVALUATE_SCORE" borderBottom>
									<u--input :value="item.EVALUATE_SCORE" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="风险等级：" prop="EVALUATE_LEVEL_SHOW" borderBottom>
									<u--input :value="item.EVALUATE_LEVEL_SHOW" border="none" inputAlign="right"
										disabled disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item class="custom-form-item" label="个体防护措施" :borderBottom="false"
									@click="handleQuerySelect({ formIndex: 'Individual', isMultiple: true,itemIndex:index})">
									<view slot="right" class="custom-form-item-right">
										<view class="multi">
											<u--text v-for="(i, k) in item.Nav_EvaluateRiskIndividualMeasures" :key="k"
												class="item"
												:text="k + 1 + '. ' + i.Nav_IndividualMeasures.NAME"></u--text>
										</view>
										<u-icon class="icon" name="arrow-down">
										</u-icon>
									</view>
								</u-form-item>

								<u-form-item class="custom-form-item" label="工程控制措施" :borderBottom="false"
									@click="handleQuerySelect({ formIndex: 'Engineering', isMultiple: true,itemIndex:index})">
									<view slot="right" class="custom-form-item-right">
										<view class="multi">
											<u--text v-for="(i, k) in item.Nav_EvaluateRiskEngineeringMeasures" :key="k"
												class="item"
												:text="k + 1 + '. ' + i.Nav_EngineeringMeasures.NAME"></u--text>
										</view>
										<u-icon class="icon" name="arrow-down">
										</u-icon>
									</view>
								</u-form-item>

								<u-form-item class="custom-form-item" label="管理控制措施" :borderBottom="false"
									@click="handleQuerySelect({ formIndex: 'Management', isMultiple: true,itemIndex:index})">
									<view slot="right" class="custom-form-item-right">
										<view class="multi">
											<u--text v-for="(i, k) in item.Nav_EvaluateRiskManagementMeasures" :key="k"
												class="item"
												:text="k + 1 + '. ' + i.Nav_ManagementMeasures.NAME"></u--text>
										</view>
										<u-icon class="icon" name="arrow-down">
										</u-icon>
									</view>
								</u-form-item>

								<u-form-item class="custom-form-item" label="教育培训措施" :borderBottom="false"
									@click="handleQuerySelect({ formIndex: 'Education', isMultiple: true,itemIndex:index})">
									<view slot="right" class="custom-form-item-right">
										<view class="multi">
											<u--text v-for="(i, k) in item.Nav_EvaluateRiskEducationMeasures" :key="k"
												class="item"
												:text="k + 1 + '. ' + i.Nav_EducationMeasures.NAME"></u--text>
										</view>
										<u-icon class="icon" name="arrow-down">
										</u-icon>
									</view>
								</u-form-item>

								<u-form-item class="custom-form-item" label="应急处置措施" :borderBottom="false"
									@click="handleQuerySelect({ formIndex: 'Emergency', isMultiple: true,itemIndex:index})">
									<view slot="right" class="custom-form-item-right">
										<view class="multi">
											<u--text v-for="(i, k) in item.Nav_EvaluateRiskEmergencyMeasures" :key="k"
												class="item"
												:text="k + 1 + '. ' + i.Nav_EmergencyMeasures.NAME"></u--text>
										</view>
										<u-icon class="icon" name="arrow-down">
										</u-icon>
									</view>
								</u-form-item>
								<u-form-item label="责任部门：" prop="Nav_DepartmentLiable.NAME" borderBottom
									@click="handleChange('Nav_DepartmentLiable',item)">
									<u--input v-if="item.Nav_DepartmentLiable" v-model="item.Nav_DepartmentLiable.NAME"
										placeholder="责任部门" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
									<u-icon style="margin-left: 4px;" slot="right" name="arrow-down">
									</u-icon>
								</u-form-item>
								<u-form-item label="责任岗位：" prop="Nav_PostLiable.NAME" borderBottom
									@click="handleChange('Nav_PostLiable',item)">
									<u--input v-if="item.Nav_PostLiable" v-model="item.Nav_PostLiable.NAME"
										placeholder="责任岗位" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
									<u-icon style="margin-left: 4px;" slot="right" name="arrow-down">
									</u-icon>
								</u-form-item>
								<u-form-item label="责任人：" prop="Nav_LiableUser.NAME" borderBottom>
									<u--input v-if="item.Nav_LiableUser" :value="item.Nav_LiableUser.NAME" border="none"
										inputAlign="right" disabled disabledColor="#fff"></u--input>
								</u-form-item>
							</u-collapse-item>
						</uni-card>
					</u-collapse>
				</u--form>
			</view>
		</view>
		<view class="sub-form" v-if="model.EVALUATE_TYPE==1">
			<view class="sub-form-wrap">
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
					ref="sForm">
					<u-collapse :border="false" accordion>
						<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
							v-for="(item, index) in model.Nav_Hazards.filter(i => !i.IS_DELETED)">
							<u-collapse-item :title="index + 1 + '. ' + item.Nav_Area.NAME">
								<u-form-item label="区域：" prop="Nav_Area.NAME" borderBottom>
									<u--input v-model="item.Nav_Area.NAME" placeholder="请选择区域" border="none"
										inputAlign="right" disabled disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="辨识对象：" prop="Nav_Identifying.NAME" borderBottom
									@click="handleChange('Nav_Identifying',item)">
									<u--input v-model="item.Nav_Identifying.NAME" placeholder="辨识对象" border="none"
										inputAlign="right" disabled disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="风险类别：" prop="Nav_Type.NAME" borderBottom
									@click="handleChange('Nav_Type',item)">
									<u--input v-model="item.Nav_Type.NAME" placeholder="风险类别" border="none"
										inputAlign="right" disabled disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="职业危害位置：" prop="HAZARD_POSITION" borderBottom>
									<u--input v-model="item.HAZARD_POSITION" placeholder="职业危害位置" border="none"
										inputAlign="right" disabled disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="风险地点：" prop="RISK_PLACE" borderBottom>
									<u--input v-model="item.RISK_PLACE" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="岗位：" prop="Posts" borderBottom>
									<u--input :value="item.Posts" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="设备设施：" prop="Equs" borderBottom>
									<u--input :value="item.Equs" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
								</u-form-item>
								<!-- <u-form-item label="作业环节：" prop="Nav_OperationStep.NAME" borderBottom>
									<u--input v-if="item.Nav_OperationStep" v-model="item.Nav_OperationStep.NAME"
										placeholder="作业环节" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
								</u-form-item> -->
								<u-form-item label="风险评价L：" prop="EVALUATE_L" borderBottom>
									<u--input v-model="item.EVALUATE_L" type="number" border="none"
										@change="caclScore(item)" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="风险评价E：" prop="EVALUATE_E" borderBottom>
									<u--input v-model="item.EVALUATE_E" type="number" border="none"
										@change="caclScore(item)" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="风险评价C：" prop="EVALUATE_C" borderBottom>
									<u--input v-model="item.EVALUATE_C" type="number" border="none"
										@change="caclScore(item)" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="分值D：" prop="EVALUATE_SCORE" borderBottom>
									<u--input :value="item.EVALUATE_SCORE" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item label="风险等级：" prop="EVALUATE_LEVEL_SHOW" borderBottom>
									<u--input :value="item.EVALUATE_LEVEL_SHOW" border="none" inputAlign="right"
										disabled disabledColor="#fff"></u--input>
								</u-form-item>
								<u-form-item class="custom-form-item" label="个体防护措施" :borderBottom="false"
									@click="handleQuerySelect({ formIndex: 'Individual', isMultiple: true,itemIndex:index})">
									<view slot="right" class="custom-form-item-right">
										<view class="multi">
											<u--text v-for="(i, k) in item.Nav_EvaluateRiskIndividualMeasures" :key="k"
												class="item"
												:text="k + 1 + '. ' + i.Nav_IndividualMeasures.NAME"></u--text>
										</view>
										<u-icon class="icon" name="arrow-down">
										</u-icon>
									</view>
								</u-form-item>

								<u-form-item class="custom-form-item" label="工程控制措施" :borderBottom="false"
									@click="handleQuerySelect({ formIndex: 'Engineering', isMultiple: true,itemIndex:index})">
									<view slot="right" class="custom-form-item-right">
										<view class="multi">
											<u--text v-for="(i, k) in item.Nav_EvaluateRiskEngineeringMeasures" :key="k"
												class="item"
												:text="k + 1 + '. ' + i.Nav_EngineeringMeasures.NAME"></u--text>
										</view>
										<u-icon class="icon" name="arrow-down">
										</u-icon>
									</view>
								</u-form-item>

								<u-form-item class="custom-form-item" label="管理控制措施" :borderBottom="false"
									@click="handleQuerySelect({ formIndex: 'Management', isMultiple: true,itemIndex:index})">
									<view slot="right" class="custom-form-item-right">
										<view class="multi">
											<u--text v-for="(i, k) in item.Nav_EvaluateRiskManagementMeasures" :key="k"
												class="item"
												:text="k + 1 + '. ' + i.Nav_ManagementMeasures.NAME"></u--text>
										</view>
										<u-icon class="icon" name="arrow-down">
										</u-icon>
									</view>
								</u-form-item>

								<u-form-item class="custom-form-item" label="教育培训措施" :borderBottom="false"
									@click="handleQuerySelect({ formIndex: 'Education', isMultiple: true,itemIndex:index})">
									<view slot="right" class="custom-form-item-right">
										<view class="multi">
											<u--text v-for="(i, k) in item.Nav_EvaluateRiskEducationMeasures" :key="k"
												class="item"
												:text="k + 1 + '. ' + i.Nav_EducationMeasures.NAME"></u--text>
										</view>
										<u-icon class="icon" name="arrow-down">
										</u-icon>
									</view>
								</u-form-item>

								<u-form-item class="custom-form-item" label="应急处置措施" :borderBottom="false"
									@click="handleQuerySelect({ formIndex: 'Emergency', isMultiple: true,itemIndex:index})">
									<view slot="right" class="custom-form-item-right">
										<view class="multi">
											<u--text v-for="(i, k) in item.Nav_EvaluateRiskEmergencyMeasures" :key="k"
												class="item"
												:text="k + 1 + '. ' + i.Nav_EmergencyMeasures.NAME"></u--text>
										</view>
										<u-icon class="icon" name="arrow-down">
										</u-icon>
									</view>
								</u-form-item>
								<u-form-item label="责任部门：" prop="Nav_DepartmentLiable.NAME" borderBottom
									@click="handleChange('Nav_DepartmentLiable',item)">
									<u--input v-if="item.Nav_DepartmentLiable" v-model="item.Nav_DepartmentLiable.NAME"
										placeholder="责任部门" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
									<u-icon style="margin-left: 4px;" slot="right" name="arrow-down">
									</u-icon>
								</u-form-item>
								<u-form-item label="责任岗位：" prop="Nav_PostLiable.NAME" borderBottom
									@click="handleChange('Nav_PostLiable',item)">
									<u--input v-if="item.Nav_PostLiable" v-model="item.Nav_PostLiable.NAME"
										placeholder="责任岗位" border="none" inputAlign="right" disabled
										disabledColor="#fff"></u--input>
									<u-icon style="margin-left: 4px;" slot="right" name="arrow-down">
									</u-icon>
								</u-form-item>
								<u-form-item label="责任人：" prop="Nav_LiableUser.NAME" borderBottom>
									<u--input v-if="item.Nav_LiableUser" :value="item.Nav_LiableUser.NAME" border="none"
										inputAlign="right" disabled disabledColor="#fff"></u--input>
								</u-form-item>
							</u-collapse-item>
						</uni-card>
					</u-collapse>
				</u--form>
			</view>
		</view>

		<query-selector :multiple="qsCom.isMultiple" :total="curTotal" :show="qsCom.show" :lists="qsCom.lists"
			@close="onCloseQS" @search="onSearchQS" @select="onSelectedQS" :defaultChecked="qsCom.defaultChecked" />
		<view class="bottom-button">
			<button type="primary" @click="submit">提交</button>
		</view>
	</view>
</template>

<script>
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		guid,
		initFilter,
		initFilterGroup
	} from '../../../../utils/common'

	import {
		getAreaLists,
		getRiskRecordRefus,
		getIdentifying,
		getOperationStep
	} from '../../../../services/apply/HMServices/HMServices'
	import {
		getRequest,
		getUserLists,
	} from '../../../../services/apply/FOServices/FOServices.js'
	import '../../../../utils/showMsg.js'
	import color from '../../../../uni_modules/uview-ui/libs/config/color'
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				listPropUpload: ['RECORD_ID'],
				listPropValUpload: [],
				model: {
					Nav_Request: {
						NAME: ""
					},
					Nav_LiableUser: {
						NAME: "",
					},
					Nav_InitiatingDepartment: {
						NAME: "",
					},
				},
				qsCom: {
					show: false,
					lists: [],
					formIndex: undefined,
					itemIndex: undefined,
					isMultiple: false,
					defaultChecked: []
				},
				curTotal: 0,
				rules: {
					'LEVEL': {
						type: 'string',
						required: false,
						trigger: ['blur', 'change']
					}
				},
				Lists: [],
				showPopup: false,
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				AUDIT_OPINION: "",
				ORG_ID: uni.getStorageSync('orgId'),
			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.model.ID = option.ID ? option.ID : '';
			this.tableKey = option.tableKey ? option.tableKey : '0';
			this.loadData();
		},
		methods: {
			//多选开始
			async handleQuerySelect(opt) {
				let column = await this.handleGet(opt, 'init')
				if (column && column.length) {
					this.qsCom = {
						show: true,
						formIndex: opt.formIndex,
						itemIndex: opt.itemIndex,
						isMultiple: opt.isMultiple,
						lists: column
					}
				}
			},
			async onSearchQS(val, pi) {
				const result = await this.handleGet(this.qsCom, val, pi)
				this.qsCom.lists = result.map(i => {
					return {
						...i,
						name: i.NAME,
						NAME: i.NAME,
						id: i.ID
					}
				})
			},
			async handleGet(opt, value, pageIndex) {
				const json = initFilter(this.ORG_ID, '', "", 0, pageIndex || 1)
				if (value !== 'init') {
					const tempGroup = initFilterGroup(false);
					extendGroupRule(tempGroup, 'NAME', 9, value)
					extendFilterGroup(json, tempGroup);
				}
				json.Limit = 20
				json.SelectField = ["ID", "NAME"];
				if (pageIndex) {
					json.Start = (pageIndex - 1) * 20;
				}
				let result = [];
				let raw = [];
				if (opt.formIndex == "Individual") {
					raw = await getRequest(json, "/HM/IndividualMeasures/OrderPaged").then(res => {
						this.curTotal = res.TotalCount
						return res
					})
				} else if (opt.formIndex == "Engineering") {
					raw = await getRequest(json, "/HM/EngineeringMeasures/OrderPaged").then(res => {
						this.curTotal = res.TotalCount
						return res
					})
				} else if (opt.formIndex == "Management") {
					raw = await getRequest(json, "/HM/ManagementMeasures/OrderPaged").then(res => {
						this.curTotal = res.TotalCount
						return res
					})
				} else if (opt.formIndex == "Education") {
					raw = await getRequest(json, "/HM/EducationMeasures/OrderPaged").then(res => {
						this.curTotal = res.TotalCount
						return res
					})
				} else if (opt.formIndex == "Emergency") {
					raw = await getRequest(json, "/HM/EmergencyMeasures/OrderPaged").then(res => {
						this.curTotal = res.TotalCount
						return res
					})
				}

				result = raw.map(item => {
					return {
						...item,
					}
				})
				return result
			},
			onSelectedQS(val) {
				const {
					formIndex,
					itemIndex,
				} = this.qsCom
				if (formIndex == "Individual") {
					this.model.Nav_Risks[itemIndex].Nav_EvaluateRiskIndividualMeasures = [];
					val.forEach(item => {
						let obj = {
							INDIVIDUAL_MEASURES_ID: item.ID,
							Nav_IndividualMeasures: {
								NAME: item.NAME
							},
							ID: guid(),
							EVALUATION_RESULT_RISK_ID: this.model.Nav_Risks[itemIndex].ID,
							ORG_ID: this.ORG_ID,
							IS_DELETED: false,
						}
						this.model.Nav_Risks[itemIndex].Nav_EvaluateRiskIndividualMeasures.push(obj);
					})
				} else if (formIndex == "Engineering") {
					this.model.Nav_Risks[itemIndex].Nav_EvaluateRiskEngineeringMeasures = [];
					val.forEach(item => {
						let obj = {
							ENGINEERING_MEASURES_ID: item.ID,
							Nav_EngineeringMeasures: {
								NAME: item.NAME
							},
							ID: guid(),
							EVALUATION_RESULT_RISK_ID: this.model.Nav_Risks[itemIndex].ID,
							ORG_ID: this.ORG_ID,
							IS_DELETED: false,
						}
						this.model.Nav_Risks[itemIndex].Nav_EvaluateRiskEngineeringMeasures.push(obj);
					})
				} else if (formIndex == "Management") {
					this.model.Nav_Risks[itemIndex].Nav_EvaluateRiskManagementMeasures = [];
					val.forEach(item => {
						let obj = {
							MANAGEMENT_MEASURES_ID: item.ID,
							Nav_ManagementMeasures: {
								NAME: item.NAME
							},
							ID: guid(),
							EVALUATION_RESULT_RISK_ID: this.model.Nav_Risks[itemIndex].ID,
							ORG_ID: this.ORG_ID,
							IS_DELETED: false,
						}
						this.model.Nav_Risks[itemIndex].Nav_EvaluateRiskManagementMeasures.push(obj);
					})
				} else if (formIndex == "Education") {
					this.model.Nav_Risks[itemIndex].Nav_EvaluateRiskEducationMeasures = [];
					val.forEach(item => {
						let obj = {
							EDUCATION_MEASURES_ID: item.ID,
							Nav_EducationMeasures: {
								NAME: item.NAME
							},
							ID: guid(),
							EVALUATION_RESULT_RISK_ID: this.model.Nav_Risks[itemIndex].ID,
							ORG_ID: this.ORG_ID,
							IS_DELETED: false,
						}
						this.model.Nav_Risks[itemIndex].Nav_EvaluateRiskEducationMeasures.push(obj);
					})
				} else if (formIndex == "Emergency") {
					this.model.Nav_Risks[itemIndex].Nav_EvaluateRiskEmergencyMeasures = [];
					val.forEach(item => {
						let obj = {
							EMERGENCY_MEASURES_ID: item.ID,
							Nav_EmergencyMeasures: {
								NAME: item.NAME
							},
							ID: guid(),
							EVALUATION_RESULT_RISK_ID: this.model.Nav_Risks[itemIndex].ID,
							ORG_ID: this.ORG_ID,
							IS_DELETED: false,
						}
						this.model.Nav_Risks[itemIndex].Nav_EvaluateRiskEmergencyMeasures.push(obj);
					})
				}
				this.qsCom.defaultChecked = [];
				this.qsCom.show = false;
			},
			onCloseQS() {
				this.qsCom = {
					show: false,
					lists: [],
					formIndex: undefined,
					isMultiple: false,
					dataIndex: undefined
				}
			},
			//多选结束
			loadData() {
				const json = initFilter(this.ORG_ID, "", "CODE", 1)
				if (this.listPropValUpload.length == 0) {
					this.listPropValUpload.push(this.model.ID)
				}
				extendRule(json, 'ID', 1, this.model.ID);
				getRequest(json, "/HM/HMEvaluateResult/FullGet").then(res => {
					this.model = res
					if (res.STATUS == 9) {
						const json = initFilter(this.ORG_ID);
						json.ID = this.model.ID;
						getRiskRecordRefus(json).then(refusRes => {
							this.AUDIT_OPINION = refusRes;
						})
					}
					if (res.Nav_Risks && res.Nav_Risks.length > 0) {
						for (let i = 0; i < res.Nav_Risks.length; i++) {
							let strPosts = ''
							for (let j = 0; j < res.Nav_Risks[i].Nav_EvaluateRiskWorkduty.length; j++) {
								strPosts += (strPosts.length > 0 ? " " : "") + res.Nav_Risks[i]
									.Nav_EvaluateRiskWorkduty[
										j].Nav_Post.NAME;
							}
							this.model.Nav_Risks[i].EVALUATE_L = this.model.Nav_Risks[i].EVALUATE_L == 0 ? "" :
								this.model.Nav_Risks[i].EVALUATE_L;
							this.model.Nav_Risks[i].EVALUATE_E = this.model.Nav_Risks[i].EVALUATE_E == 0 ? "" :
								this.model.Nav_Risks[i].EVALUATE_E;
							this.model.Nav_Risks[i].EVALUATE_C = this.model.Nav_Risks[i].EVALUATE_C == 0 ? "" :
								this.model.Nav_Risks[i].EVALUATE_C;
							this.model.Nav_Risks[i].EVALUATE_SCORE = this.model.Nav_Risks[i].EVALUATE_SCORE == 0 ?
								"" :
								this.model.Nav_Risks[i].EVALUATE_SCORE;
							this.caclScore(this.model.Nav_Risks[i]);
							this.model.Nav_Risks[i].Posts = strPosts;
						}
					}
					if (res.Nav_Risks && res.Nav_Risks.length > 0) {
						for (let i = 0; i < res.Nav_Risks.length; i++) {
							let strEqus = ''
							for (let j = 0; j < res.Nav_Risks[i].Nav_EvaluateRiskEquipment.length; j++) {
								strEqus += (strEqus.length > 0 ? " " : "") + res.Nav_Risks[i]
									.Nav_EvaluateRiskEquipment[
										j].Nav_Equipment.NAME;
							}
							this.model.Nav_Risks[i].Equs = strEqus;
						}
					}
					if (this.model.Nav_Files && this.model.Nav_Files.length > 0) {
						for (let i = 0; i < this.model.Nav_Files.length; i++) {
							this.model.Nav_Files[i].url = config.uni_app_web_source_url + this.model.Nav_Files[
									i]
								.Nav_ImgFile.FILE_PATH;
							this.model.Nav_Files[i].name = this.model.Nav_Files[i].Nav_ImgFile.FILE_NAME
						}
					}
					this.model.START_TIME = uni.$u.timeFormat(this.model.START_TIME, 'yyyy-mm-dd');
					this.model.END_TIME = uni.$u.timeFormat(this.model.END_TIME, 'yyyy-mm-dd');
					this.model.EVALUATE_TYPE_SHOW = this.model.EVALUATE_TYPE == 1 ? "职业危害辨识" : "危险源辨识";
					this.isLoadOK = true;
				})
			},
			caclScore(item) {
				let score = item.EVALUATE_L * item.EVALUATE_E * item.EVALUATE_C;
				if (score > 320) {
					item.EVALUATE_LEVEL = "10";
					item.EVALUATE_LEVEL_SHOW = "一级";
				} else if (160 < score && score <= 320) {
					item.EVALUATE_LEVEL = "20";
					item.EVALUATE_LEVEL_SHOW = "二级";
				} else if (70 < score && score <= 160) {
					item.EVALUATE_LEVEL = "30";
					item.EVALUATE_LEVEL_SHOW = "三级";
				} else if (score <= 70) {
					item.EVALUATE_LEVEL = "40";
					item.EVALUATE_LEVEL_SHOW = "四级";
				}
				item.EVALUATE_SCORE = score.toFixed(2);
			},
			submit() {
				if (this.model.MODIFY_TYPE == 0) {
					this.model.MODIFY_TYPE = 1;
				}
				this.model.PUBLISH = "SaveAndNotify";
				this.model.TaskID = this.TaskID;
				if (this.model.ORG_ID == "") {
					this.model.ORG_ID = this.ORG_ID;
				}
				this.model.Nav_Files = null;

				this.model.Nav_Risks.forEach(item => {
					item.Nav_EvaluateRiskWorkduty.forEach(item1 => {
						item1.Nav_Post = null;
					});
					item.Nav_EvaluateRiskEquipment.forEach(item1 => {
						item1.Nav_Equipment = null;
					});
					item.Nav_EvaluateRiskIndividualMeasures.forEach(item1 => {
						item1.Nav_IndividualMeasures = null;
					});
					item.Nav_EvaluateRiskEngineeringMeasures.forEach(item1 => {
						item1.Nav_EngineeringMeasures = null;
					});
					item.Nav_EvaluateRiskManagementMeasures.forEach(item1 => {
						item1.Nav_ManagementMeasures = null;
					});
					item.Nav_EvaluateRiskEducationMeasures.forEach(item1 => {
						item1.Nav_EducationMeasures = null;
					});
					item.Nav_EvaluateRiskEmergencyMeasures.forEach(item1 => {
						item1.Nav_EmergencyMeasures = null;
					});
				});
				this.model.Nav_Hazards.forEach(item => {
					item.Nav_EvaluateHazardIndividualMeasures.forEach(item1 => {
						item1.Nav_IndividualMeasures = null;
					});
					item.Nav_EvaluateHazardEngineeringMeasures.forEach(item1 => {
						item1.Nav_EngineeringMeasures = null;
					});
					item.Nav_EvaluateHazardManagementMeasures.forEach(item1 => {
						item1.Nav_ManagementMeasures = null;
					});
					item.Nav_EvaluateHazardEducationMeasures.forEach(item1 => {
						item1.Nav_EducationMeasures = null;
					});
					item.Nav_EvaluateHazardEmergencyMeasures.forEach(item1 => {
						item1.Nav_EmergencyMeasures = null;
					});
				});
				const ele = this.$refs
				//ele['wForm'].validate().then(res => {
				getRequest(this.model, "/HM/HMEvaluateResult/FullUpdate").then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
				// }).catch(err => {
				// 	uni.$showErrorInfo('请检查必填项，必填项不能为空')
				// })
			},
		},

	}
</script>

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