<template>
	<view class="todo-page">
		<step-title :stepPage="stepsPage" :stepText="stepsText"></step-title>
		<view class="allview">
			<view class="card">
				<u--form labelWidth="auto" :model="dataModel" ref="wForm" class="demo-ruleForm">
					<view style="position: relative;">
						<view style="position: absolute;left: -10px;color: #3d4b70;top: -3px;">*</view>
					</view>

					<view style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;">基本信息填写</view>
					<u-form-item label="发起时间：" prop="Product_Unit">
						<u--input v-model="dataModel.CREATE_TIME" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>

					</u-form-item>
					<u-form-item label="发起部门：" prop="Product_Unit">
						<u--input v-model="(dataModel.Nav_ApplyDepartment||{}).NAME" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>

					</u-form-item>
					<u-form-item label="发起人员：" prop="Product_Unit">
						<u--input v-model="(dataModel.Nav_ApplyUser||{}).NAME" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>

					</u-form-item>
					<u-form-item label="评估年度：" prop="YEAR">
						<u--input v-model="dataModel.YEAR" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>
					<!-- <u-form-item label="辨识与评估内容:">
					</u-form-item>
					<u--textarea v-model="dataModel.CONTENTS" placeholder="请输入内容" autoHeight></u--textarea> -->
					<u-form-item label="开始时间:">
						<u--input v-model="dataModel.START_DATE" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
					</u-form-item>
					<u-form-item label="结束时间:">
						<u--input v-model="dataModel.END_DATE" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
					</u-form-item>
					<u-form-item label="评价要求:">
					</u-form-item>
					<u--textarea v-model="dataModel.Nav_RequiresName" disabled autoHeight ></u--textarea>
					<view class="upload-title">附件：</view>
					<full-upload v-model="dataModel.Nav_Files" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>

				</u--form>
				<u--form labelWidth="auto" :model="dataModel" ref="wForm" class="sub-form">


					<view style="position: relative;">

						<view style="position: absolute;left: -10px;color: #3d4b70;top: -3px;">*</view>
					</view>

					<view style="font-size: 15px; font-weight: bold;color: #3d4b70;margin-bottom: 10px;margin-top: 20px;">辨识内容</view>
					<view v-for="(item,index) in dataModel.Nav_Details" :key="index" style="border-bottom: #ceccca 1px solid;margin-bottom: 10px;padding-bottom: 10px;">
						<u-form-item prop="Nav_Contents" :label="index+1+'.辨识区域：'">

							<view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;flex: 1;">
								<u--input v-model="(item.Nav_Area||{}).NAME" disabled disabledColor="#ffffff" border="none" fontSize="14px">
								</u--input>
								<view class="action" @click.stop style="display: flex;flex-direction: row;align-items: center;justify-content: space-around;">
									<u-icon name="arrow-up" size="12" v-if="item.showPack" @click="handlePack(item)"></u-icon>
									<u-icon name="arrow-down" size="12" v-if="!item.showPack" @click="handlePack(item)"></u-icon>
								</view>
							</view>

						</u-form-item>
						<view v-if="item.showPack==true">
							<u-form-item label="生产单元：" border-bottom>
								<u--input v-model="(item.Nav_ProductionUnit||{}).NAME" disabled disabledColor="#ffffff" placeholder="请选择生产单元" border="none" inputAlign="right" fontSize="14px">
								</u--input>
							</u-form-item>
							<u-form-item label="风险名称" prop="CHECKSTANDARD" border-bottom>
								<u--input v-model="item.RISK_NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item>
							<u-form-item label="风险描述" prop="HIDDEN_DESCRIPTION">
							</u-form-item>
							<u--textarea v-model="item.RISK_DESCRIPTION" disabled autoHeight maxlength="-1"></u--textarea>
							<u-form-item label="风险类别" prop="HIDDEN_LEVEL" border-bottom>
								<u--input v-model="(item.Nav_Type||{}).NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item>
							<u-form-item label="风险等级" prop="HIDDEN_PLACE" border-bottom>
								<u--input v-model="item.EVALUATE_LEVELName" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item>
							<u-form-item label="风险评价L" border-bottom>
								<u--input v-model="(item.Nav_SCOREL||{}).SCORE" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item>
							<u-form-item label="风险评价E" border-bottom>
								<u--input v-model="(item.Nav_SCOREE||{}).SCORE" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item>
							<u-form-item label="风险评价C" border-bottom>
								<u--input v-model="(item.Nav_SCOREC||{}).SCORE" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item>
							<u-form-item label="分值D" border-bottom>
								<u--input v-model="item.EVALUATE_SCORE" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item>
							<u-form-item label="应急处理" prop="EMERGENCY" borderBottom>
								<u--input disabledColor="#ffffff" disabled v-model="item.EMERGENCY" border="none" inputAlign="right"></u--input>
							</u-form-item>
							<u-form-item label="新增标识" prop="HIDDEN_PLACE" border-bottom>
								<u--input v-model="item.MARK_NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
								</u--input>
							</u-form-item>
							<uni-collapse class="collapse" ref="collapse">
							
								<uni-collapse-item title="管控措施" name="Variety components">
							
									<view v-if="item.Nav_DetailMeasures&&item.Nav_DetailMeasures.length!==0">
										<view v-for="item1 in item.Nav_DetailMeasures.filter(i => !i.IS_DELETED)" style="margin: 5px 5px;padding: 0px 10px;">
											<u-form-item label="序号" prop="HIDDEN_DESCRIPTION" border-bottom>
												<view slot="right" style="display: flex;flex-direction: row;align-items: center;">
													<u-number-box v-model="item1.NUM" disabled integer></u-number-box>
							
												</view>
							
											</u-form-item>
											<u-form-item label="措施" prop="HIDDEN_DESCRIPTION">
							
											</u-form-item>
											<u--textarea v-model="item1.MEASURES_NAME" disabled autoHeight></u--textarea>
										</view>
									</view>
								</uni-collapse-item>
								<uni-collapse-item title="辨识岗位" name="Detail Posts">
							
									<view v-if="item.Nav_DetailPosts&&item.Nav_DetailPosts.length>0">
							
										<view v-for="(item1,index1) in item.Nav_DetailPosts.filter(i => !i.IS_DELETED)" style="padding: 10px;">
							
											<u-form-item :label="(index1+1)+' . '+'辨识部门'" prop="HIDDEN_PLACE" border-bottom>
												<u--input v-model="(item1.Nav_Department||{}).NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
												</u--input>
							
											</u-form-item>
											<u-form-item label="辨识岗位" prop="HIDDEN_PLACE" border-bottom>
							
											</u-form-item>
											<u-textarea v-model="item1.Nav_ResultPostDetsName" disabled autoHeight></u-textarea>
										</view>
									</view>
								</uni-collapse-item>
								<uni-collapse-item title="管控层级" name="Docs guide">
							
									<view v-if="item.Nav_DetailDeparts&&item.Nav_DetailDeparts.length>0">
							
										<view v-for="(item1,index1) in item.Nav_DetailDeparts.filter(i => !i.IS_DELETED)" style="padding: 10px;">
											<u-form-item borderBottom>
												<view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;flex: 1;">
													<view style="flex: 1;display: flex;flex-direction: row;align-items: center;">
														<view style="flex: 1;">
															{{item1.Nav_Department?index1+1+'.管控部门 : ' +item1.Nav_Department.NAME:index1+1+'.'}}
														</view>
							
													</view>
							
												</view>
											</u-form-item>
											<u-form-item borderBottom label="管控层级：" prop="Check_Level">
												<u--input v-model="item1.DEPARTMENT_TYPEName" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
												</u--input>
											</u-form-item>
											<u-form-item borderBottom label="管控责任人" prop="HIDDEN_PLACE" border-bottom>
												<u--input v-model="((item1.Nav_Department||{}).Nav_User||{}).NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
												</u--input>
											</u-form-item>
										</view>
									</view>
								</uni-collapse-item>
							</uni-collapse>
						</view>
					</view>
				</u--form>
			</view>
			<check-action v-if="isLoadOK && tableKey === '1'&&isAudit==='true' " :okApi="okApi" :refuseApi="refuseApi" :dataSource="$store.state.auditModel"></check-action>
		</view>
	</view>
</template>

<script>
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		extendIgnoreDataRule,
		guid,
		initFilter,
		initFilterGroup,
		handleOriginalArray,
		transformData
	} from '../../../../utils/common'
	import {
		FMProductionUnit,
		SKEffective,
		SKMarkEnum,
		SKLevelEnum,
		CheckPeriods,
		CheckLevels,
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		EvaluationSumGet,
		EvaluationFullUpdate,
		getUserLists,
		GetSKRequestInfo,
		GetRiskAreaInfo,
		GetRiskTypeInfo,
		GetDepartmentInfo
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices';
	import {
		getEnum,
		GetEnumAnyOrder
	} from '../../../../services/common';
	import stepTitle from '@/components/custom/step-title.vue'
	import swipeActionItem from '../../../../uni_modules/uview-ui/libs/config/props/swipeActionItem';
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				stepLoad: true,
				dataModel: {
					CREATE_TIME: '',
					Nav_ApplyDepartment: {
						NAME: ''
					},
					Nav_ApplyUser: {
						NAME: ''
					},
					YEAR: '',
					START_DATE: '',
					END_DATE: '',
					Nav_Require: {
						NAME: ''
					},
					RequireName: '',
					Nav_Files: [],
					Nav_Details: [{
						showPack: false,
						MineType: '',
						Nav_Area: {
							NAME: ''
						},
						RISK_NAME: '',
						Nav_RiskName: {
							NAME: ''
						},
						RISK_DESCRIPTION: '',
						Nav_Type: {
							NAME: ''
						},
						EVALUATE_L: 0,
						EVALUATE_E: 0,
						EVALUATE_C: 0,
						EVALUATE_SCORE: 0,
						EVALUATE_LEVEL: '',
						Nav_DetailDeparts: [],
						Nav_DetailMeasures: [],
						isShowControl: false,
					}]
				},
				dateRecitifyTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd'),
				stepsText: ['发起', '审批', '归档'],
				stepsPage: 0,
				stepsPageList: 0,
				TaskID: '',
				nowName: '',
				nowIndex: 0,
				childList: ['管控措施', '管控层级'],
				curNow: 0,
				isAudit: false,
				isLoadOK: false,
				tableKey: 0,
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {} // 存储枚举文本列表（用于下拉选择等场景）
			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.ID = option.ID ? option.ID : '';
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.isAudit = option.isAudit
			this.okApi = option.okApi
			this.refuseApi = option.refuseApi
			this.auditModel = {
				...this.$store.state.auditModel,
				TaskID: option.taskID ? option.taskID : ''
			}
			this.fetchEnums(['SKProductionUnit', 'SKEvaluateLevelEnum', 'SKDepartmentTypeEnum', 'SKMarkEnum']);
		},
		methods: {
			fetchEnums(enumNames) {
				var dataParm = {
					'name': enumNames.join('|')
				}
				GetEnumAnyOrder(dataParm).then(res => {
					let newd = transformData(res, enumNames)
					this.enumsData = newd[0];
					// 生成文本列表（如需要）
					this.enumsText = newd[1]
					this.loadData();
				})
			},
			loadData() {
				// const json = {}
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				extendRule(json, 'ID', 1, this.ID);
				extendInclude(json, 'Nav_ApplyUser');
				extendInclude(json, 'Nav_ApplyDepartment');
				extendInclude(json, 'Nav_Require');
				extendInclude(json, 'Nav_Details');
				extendInclude(json, 'Nav_Details.Nav_Area');
				extendInclude(json, 'Nav_Details.Nav_ProductionUnit');
				extendInclude(json, 'Nav_Details.Nav_Type');
				extendInclude(json, 'Nav_Details.Nav_RiskName');
				extendInclude(json, 'Nav_Details.Nav_DetailMeasures');
				extendInclude(json, 'Nav_Details.Nav_DetailDeparts.Nav_Department');
				extendInclude(json, 'Nav_Details.Nav_DetailDeparts.Nav_User');
				extendInclude(json, 'Nav_Details.Nav_DetailPosts.Nav_Post');
				extendInclude(json, 'Nav_Files');
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				extendIgnoreDataRule(json)
				// extendRule(json, 'TASK_ID', 1, this.TaskID);
				EvaluationSumGet(json).then(res => {
					this.dataModel = res;
					this.dataModel.CREATE_TIME = uni.$u.timeFormat(res.CREATE_TIME, 'yyyy-mm-dd')
					this.stepsPage = res.STATUS == 0 ? 0 : res.STATUS == 20 ? 1 : 2
					this.dataModel.START_DATE = uni.$u.timeFormat(res.START_DATE, 'yyyy-mm-dd')
					this.dataModel.END_DATE = uni.$u.timeFormat(res.END_DATE, 'yyyy-mm-dd')
					let Nav_RequiresName = ''
					if (this.dataModel.Nav_Requires && this.dataModel.Nav_Requires.length > 0) {
						this.dataModel.Nav_Requires.map(item => {
							if (item.Nav_Require&&item.Nav_Require.NAME !== null) {
								Nav_RequiresName += item.Nav_Require.NAME + ' ';
							}
						})
					}
					this.dataModel.Nav_RequiresName = Nav_RequiresName
					this.dataModel.Nav_Details.map(item => {
						item['showPack'] = false
						item.MARK_NAME = item.MARK !== undefined ? this.enumsData['SKMarkEnum'].find(item1 => item1.code === item.MARK).name : '';
						item.EVALUATE_LEVELName = item.EVALUATE_LEVEL !== undefined ? this.enumsData['SKEvaluateLevelEnum'].find(item1 => item1.code === item.EVALUATE_LEVEL).name : '';
						item.Nav_DetailDeparts.map(item1 => {
							item1.DEPARTMENT_TYPEName = item1.DEPARTMENT_TYPE !== undefined ? this.enumsData['SKDepartmentTypeEnum'].find(item2 => item2.code === item1.DEPARTMENT_TYPE).name : '';
						})
						if (item.Nav_DetailPosts && item.Nav_DetailPosts.length > 0) {
							item.Nav_DetailPosts.map(item1 => {
								if (item1.Nav_PostDetails && item1.Nav_PostDetails.length > 0) {
									let Nav_ResultPostDetsName = ''
									item1.Nav_PostDetails.map(item2 => {
										if (item2.Nav_Post && item2.Nav_Post.NAME !== null) {
											Nav_ResultPostDetsName += item2.Nav_Post.NAME + ' ';
										}
									})
									item1.Nav_ResultPostDetsName = Nav_ResultPostDetsName
								}
							})
						
						}
					})
					this.stepLoad = false

				})
				this.isLoadOK = true
			},
			handlePack(item) {
				item.showPack = item.showPack == false ? true : false
				this.$forceUpdate()

			},


		},
	}
</script>

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

	.sub-form>>>.u-form-item__body__right__content__slot {
		display: flex;
		justify-content: flex-end;
	}
</style>