<template>
	<view class="todo-page" style="padding-bottom: 10px;">
		<view class="background"></view>

		<view class="card" style="padding-bottom: 20px;">
			<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>
				<uni-collapse :border="false" accordion>
					<view v-for="(item, index) in showData" :key="index">
						<uni-collapse-item title-border="none" :border="false">
							<template v-slot:title>
								<view class="uni-collapse-item__title-box">
									<view class="uni-collapse-item__title-text">
										{{item.Nav_Area?index+1+'.'+item.Nav_Area.NAME:index+1+'.'}}
									</view>
								</view>
							</template>
							<view class="content" style="padding: 0px 0px 0px 10px;">
								<u-form-item label="生产单元" borderBottom>
									<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item.MINE_NAME" border="none" inputAlign="right"></u--input>

								</u-form-item>
								<u-form-item label="辨识区域" prop="Nav_Contents.CHECKCONTENT" borderBottom>
									<u--input fontSize="14px" disabled disabledColor="#fff" v-model="(item.Nav_Area||{}).NAME" border="none" inputAlign="right"></u--input>

								</u-form-item>
								<u-form-item label="风险名称" prop="HIDDEN_PLACE" borderBottom>
									<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item.RISK_NAME" border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="风险描述" prop="HIDDEN_PLACE" borderBottom>
								</u-form-item>
								<u--textarea fontSize="14px" disabled disabledColor="#fff" v-model="item.RISK_DESCRIPTION" border="none" inputAlign="right" autoHeight></u--textarea>
								<u-form-item label="风险类别" prop="HIDDEN_PLACE" borderBottom>
									<u--input fontSize="14px" disabled disabledColor="#fff" v-model="(item.Nav_Type||{}).NAME" border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="风险等级" prop="HIDDEN_PLACE" borderBottom>
									<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item.EVALUATE_LEVELName" border="none" inputAlign="right"></u--input>
								</u-form-item>

								<u-form-item label="管控层级" prop="HIDDEN_PLACE" borderBottom>
									<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item.CONTROLLEVEL" border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="管控部门" prop="HIDDEN_PLACE" borderBottom>
									<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item.CONTROLDEPT" border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="管控责任人" prop="HIDDEN_PLACE" borderBottom>
									<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item.CONTROLUSER" border="none" inputAlign="right"></u--input>
								</u-form-item>
								<u-form-item label="管控措施" prop="HIDDEN_PLACE" borderBottom>

								</u-form-item>
								<u--textarea fontSize="14px" disabled disabledColor="#fff" v-model="item.MEASURE" border="none" inputAlign="right" autoHeight></u--textarea>
								<u-form-item label="应急处置" prop="HIDDEN_PLACE" borderBottom>
								</u-form-item>
								<u--textarea fontSize="14px" disabled disabledColor="#fff" v-model="item.EMERGENCY" border="none" inputAlign="right" autoHeight></u--textarea>
								<u-form-item label="检查内容" prop="HIDDEN_PLACE" borderBottom>

								</u-form-item>
								<u--textarea fontSize="14px" disabled disabledColor="#fff" v-model="item.CHECKCONTENTS" border="none" inputAlign="right" autoHeight></u--textarea>
								<u-form-item label="隐患描述" prop="HIDDEN_PLACE" borderBottom>
								</u-form-item>
								<u--textarea fontSize="14px" disabled disabledColor="#fff" v-model="item.HIDDENSCRIPTION" border="none" inputAlign="right" autoHeight></u--textarea>
								<u-form-item label="整改措施" prop="HIDDEN_PLACE" borderBottom>
								</u-form-item>
								<u--textarea fontSize="14px" disabled disabledColor="#fff" v-model="item.RECIFYMEASURE" border="none" inputAlign="right" autoHeight></u--textarea>
								<u-form-item label="检查层级" prop="HIDDEN_PLACE" borderBottom>
									<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item.CHECKLEVEL" border="none" inputAlign="right"></u--input>
								</u-form-item>

								<u-form-item label="检查类型" prop="HIDDEN_PLACE" borderBottom>
									<u--input fontSize="14px" disabled disabledColor="#fff" v-model="item.CHECKTYPE" border="none" inputAlign="right"></u--input>
								</u-form-item>
							</view>


						</uni-collapse-item>
					</view>
				</uni-collapse>
				<view v-if="loading" class="loading-tip">加载中...</view>
				<view v-else class="loading-tip">已加载全部数据</view>



			</u--form>

		</view>
	</view>
</template>

<script>
	import {
		initFilter,
		extendRule,
		extendInclude,
		transformData
	} from '../../../../../utils/common'
	import {
		MineTypeIndex,
		MineTypeName
	} from '../../../../../utils/enums.js'
	import {
		SKOrderEntities
	} from '../../../../../services/apply/subPages/SK/SKServices.js'
	import {
		getEnum,
		GetEnumAnyOrder
	} from '../../../../../services/common';
	export default {
		data() {
			return {
				pageIndex: 0,
				pageSize: 20,
				total: 0,
				loading: true,
				model: {
					filterDatas: []
				},
				showData: [],
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {} // 存储枚举文本列表（用于下拉选择等场景）
			}
		},
		onLoad() {
			this.fetchEnums(['SKProductionUnit', 'SKEvaluateLevelEnum']);
		},

		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 orgId = uni.getStorageSync('orgId')
				let json = initFilter(orgId);
				SKOrderEntities(json).then(res => {
					this.total = res.TotalCount
					this.model.filterDatas = res.Data
					this.model.filterDatas.map(item => {
						item.MINE_NAME = item.MineType !== undefined ? this.enumsData['SKProductionUnit'].find(item1 => item1.code === item.MineType).name : '';
						item.EVALUATE_LEVELName = item.EVALUATE_LEVEL !== undefined ? this.enumsData['SKEvaluateLevelEnum'].find(item1 => item1.code === item.EVALUATE_LEVEL).name : '';
					})
					this.reload()
				})
			},
			reload() {

				if (this.showData.length >= this.model.filterDatas.length) {
					this.loading = false
				} else {
					this.loading = true
					const endIndex = this.pageIndex + this.pageSize;
					this.showData = this.model.filterDatas.slice(0, endIndex);
					this.pageIndex = endIndex;
				}

			}
		},
		onReachBottom() {
			this.reload()
		},
	}
</script>


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

	.loading-tip {
		text-align: center;
		padding: 15px 0;
		color: #999;
		font-size: 14px;
	}
</style>