<template>
	<view class="todo-page">
		<step-title :stepPage="stepsPage" :stepText="stepsText"></step-title>
		<view class="allview">
			<view class="card">
				<u--form labelWidth="auto" :model="model" 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="model.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="(model.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="(model.Nav_ApplyUser||{}).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="model.Product_Unit" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>

					</u-form-item>
					<u-form-item label="发现区域:">
						<u--input v-model="(model.Nav_RiskArea||{}).NAME" placeholder="请选择检查区域" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>
					<u-form-item label="隐患地点:" prop="HIDDEN_PLACE">
						<u--input v-model="model.HIDDEN_PLACE" placeholder="请填写隐患地点" disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
					</u-form-item>
					<u-form-item label="隐患描述:" prop="HIDDEN_DESCRIPTION">
						<u--input v-model="model.HIDDEN_DESCRIPTION" placeholder="请填写隐患描述" disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
					</u-form-item>
					<view class="upload-title">隐患照片：</view>
					<full-upload v-model="model.Nav_ReportFiles" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>

				</u--form>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		extendIgnoreDataRule,
		guid,
		initFilter,
		initFilterGroup
	} from '../../../../utils/common'
	import {
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		GetHandRiskReportRecord,
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import stepTitle from '@/components/custom/step-title.vue'
	import {
		getEnum
	} from '../../../../services/common';
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				model: {
					Nav_ReportFiles: [],
					Product_Unit: '',
					Nav_RiskArea: {
						NAME: ''
					},
					HIDDEN_PLACE: '',
					HIDDEN_DESCRIPTION: '',
					Nav_ApplyDepartment: {
						NAME: ''
					},
					Nav_ApplyUser: {
						NAME: ''
					},
					CREATE_TIME: ''
				},
				stepsText: ['发起', '归档'],
				stepsPage: 0,
				stepsPageList: 0,
				TaskID: '',
				isLoadOK: false,
				isAudit: false,
				tableKey: 0,
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {} // 存储枚举文本列表（用于下拉选择等场景）


			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.model.ID = option.ID ? option.ID : '';
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.isAudit = option.isAudit
		this.fetchEnums(['SKProductionUnit'
		]);
		},
		methods: {
			async fetchEnums(enumNames) {
				try {
					// 存储所有枚举请求的Promise
					const enumPromises = enumNames.map(name => {
						return getEnum({
							name
						}).then(res => {
							// 统一处理枚举格式：添加name/code字段，便于后续映射
							return {
								enumName: name,
								data: res.map(item => ({
									...item,
									name: item.NAME, // 统一显示名称字段
									code: item.ID // 统一值字段
								}))
							};
						});
					});
			
					// 等待所有枚举请求完成
					const results = await Promise.all(enumPromises);
					// 存储枚举结果到data中（键为枚举名称，值为处理后的数据）
					results.forEach(({
						enumName,
						data
					}) => {
						this.enumsData[enumName] = data;
						// 生成文本列表（如需要）
						this.enumsText[enumName] = data.map(item => item.name);
					});
					// 所有枚举获取完成后，执行loadData
					this.loadData();
				} catch (error) {
					console.error('枚举请求失败:', error);
					uni.showToast({
						title: '枚举数据加载失败',
						icon: 'none'
					});
				}
			},
			loadData() {
				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_RiskArea');
				extendInclude(json, 'Nav_ReportFiles');
				extendInclude(json, 'Nav_ReportFiles.Nav_ImgFile');
				extendIgnoreDataRule(json)
				// extendRule(json, 'TASK_ID', 1, this.TaskID);
				GetHandRiskReportRecord(json).then(res => {
					this.isLoadOK = true
					this.model = res
					this.model.Product_Unit = res.MineType!==undefined  ? this.enumsData['SKProductionUnit'].find(item => item.code === res.MineType).name : '';
					this.stepsPage = res.STATUS == 0 ? 0 : 1
				})
				

			},

		}



	}
</script>

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

	.todo-page>>>.u-steps-item__line {
		width: 187.6px !important;
	}
</style>