<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" 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" disabled 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>
					<view style="margin-top: 20px;">
						<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>
						<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">

								<view style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;flex: 1;">
									<view style="flex: 1;">
										{{index+1+'.辨识区域：'+item.Nav_Area.NAME}}
									</view>
									<view class="action" 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(index)"></u-icon>
										<u-icon name="arrow-down" size="12" v-if="!item.showPack" @click="handlePack(index)"></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" 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" border-bottom>
									<u--input v-model="item.RISK_DESCRIPTION" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
									</u--input>
								</u-form-item>
								<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.MEASURE" 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.EMERGENCY" 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.MARK_NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
									</u--input>
								</u-form-item>
							</view>
						</view>
					</view>

				</u--form>

			</view>
			<!-- <view style="padding: 10px 16px;display: flex;flex-direction: row;" class="bottom-button" v-if="isLoadOK&&tableKey==='1'&&!isAudit">
				<u-button type="primary" @click="submit" color="#3d4b70">确认</u-button>
			</view> -->
			<check-action v-if="isLoadOK && tableKey === '1'&&isAudit==='true' " :okApi="okApi" :TASK_ORGID="TASK_ORGID" :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,
		CheckPeriods,
		CheckLevels,
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		EvaIdentifyPlanGet,
		SKRiskIdentifyFullUpdate,
		getUserLists,
		GetSKRequestInfo,
		GetRiskAreaInfo,
		GetRiskTypeInfo
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import {
		getEnum,
		GetEnumAnyOrder
	} from '../../../../services/common';
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices';
	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 {
				isAudit: false,
				isLoadOK: false,
				tableKey: 0,
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				TASK_ORGID:'',
				stepLoad: true,
				dataModel: {
					Nav_ApplyDepartment: {
						NAME: '',
					},
					Nav_ApplyUser: {
						NAME: ''
					},
					CREATE_TIME:'',
					YEAR: '',
					START_DATE: '',
					END_DATE: '',
					CONTENTS: '',
					Nav_Require: {
						NAME: ''
					},
					RequireName: '',
					Nav_Files: [],
					Nav_Details: [{
						showPack: false,
						MineType: '',
						Nav_Area: {
							NAME: ''
						},
						RISK_NAME: '',
						RISK_DESCRIPTION: '',
						Nav_Type: {
							NAME: ''
						},
						MEASURE: '',
						EMERGENCY: '',
						ENABLE_STATUS: '',
					}]
				},
				model: {
					ORG_ID: '',
					YEAR: '',
					START_DATE: '',
					END_DATE: '',
					CONTENTS: '',
					Nav_Require: {
						NAME: ''
					},
					RequireName: '',
					Nav_Files: [],
					Nav_Details: [{
						MineType: '',
						Nav_Area: {
							NAME: ''
						},
						RISK_NAME: '',
						RISK_DESCRIPTION: '',
						Nav_Type: {
							NAME: ''
						},
						MEASURE: '',
						EMERGENCY: '',
						ENABLE_STATUS: '',
					}]

				},
				dateRecitifyTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd'),
				stepsText: ['发起', '审批', '归档'],
				stepsPage: 0,
				stepsPageList: 0,
				TaskID: '',
				nowName: '',
				nowIndex: 0,
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {} // 存储枚举文本列表（用于下拉选择等场景）
			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.ID = option.ID? option.ID:''
			this.TASK_ORGID = option.TASK_ORGID? option.TASK_ORGID:''
			this.model.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(['SKMarkEnum', 'SKEnableStatusEnum']);
		},
		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.model.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_Files');
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				extendIgnoreDataRule(json)
				if(this.TASK_ORGID&& this.TASK_ORGID!=null){
					json.Parameter22 = this.TASK_ORGID
				}
				// extendRule(json, 'TASK_ID', 1, this.TaskID);
				EvaIdentifyPlanGet(json).then(res => {
					this.dataModel = res;
					this.stepsPage = res.STATUS == 0 ? 0 : res.STATUS == 20 ? 1 : 2
					this.dataModel.CREATE_TIME = uni.$u.timeFormat(res.CREATE_TIME, 'yyyy-mm-dd')
					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')
					this.dataModel.RequireName = res.Nav_Require.NAME
					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.ENABLE_STATUS_NAME = item.ENABLE_STATUS !== undefined ? this.enumsData['SKEnableStatusEnum'].find(item1 => item1.code === item.ENABLE_STATUS).name : '';
						item.MARK_NAME = item.MARK !== undefined ? this.enumsData['SKMarkEnum'].find(item1 => item1.code === item.MARK).name : '';
					})
					this.stepLoad = false

				})
				this.isLoadOK = true
			},
			handlePack(index) {
				this.dataModel.Nav_Details[index].showPack = this.dataModel.Nav_Details[index].showPack == false ? true : false
				this.dataModel.Nav_Details = [...this.dataModel.Nav_Details]

			},
			submit() {
				let json = {};
				json.ID = this.ID;
				json.TaskID = this.TaskID;
				SKRectifyNoticeShow(json).then(res => {
					uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						},
						'success', 1000)
				})
			}

		}



	}
</script>

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