<template>
	<view class="page-wrap" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<view class="background"></view>
		<view class="card">
			<!-- <uni-card margin="0" :is-shadow="true"> -->
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" 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="CHECK_TIME" borderBottom>
					<u--input disabledColor="#fff" disabled v-model="model.CHECK_TIME" border="none" inputAlign="right" fontSize="14px"></u--input>

				</u-form-item>

				<u-form-item label="整改责任单位" prop="Nav_CheckType" borderBottom>
					<u--input v-if="model.Nav_Project" disabledColor="#fff" disabled v-model="model.Nav_Project.UNIT_NAME" border="none" inputAlign="right" fontSize="14px"></u--input>

				</u-form-item>

				<u-form-item label="隐患提报人" prop="Nav_ListArea" borderBottom>
					<u--input v-if="model.Nav_User" disabledColor="#fff" disabled v-model="model.Nav_User.NAME" border="none" inputAlign="right" fontSize="14px"></u--input>

				</u-form-item>
				<u-form-item label="生产单元" borderBottom>
					<u--input disabledColor="#fff" disabled v-model="model.MineTypes" border="none" inputAlign="right" fontSize="14px"></u--input>

				</u-form-item>
				<view class="upload-title">附件</view>
				<full-upload v-model="model.Nav_Files" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>

			</u--form>
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm" class="sub-form" style="margin-top: 10px;" v-if="model.Nav_Details.length>0">
				<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 model.Nav_Details" :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">
										{{index+1+'.'+item.CHECK_CONTENT}}
									</view>

								</view>
							</template>
							<view class="content" style="margin: 0px 10px;">
								<u-form-item label="生产单元：" prop="MineType" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.MineTypes" border="none" inputAlign="right" fontSize="14px"></u--input>

								</u-form-item>
								<u-form-item label="检查区域" prop="Nav_ListArea" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.Nav_Area.AREA" border="none" inputAlign="right" fontSize="14px"></u--input>
									<!-- <u-icon style="margin-left: 4px;" name="arrow-down" size="12"></u-icon> -->
								</u-form-item>
								<u-form-item label="检查内容" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.CHECK_CONTENT" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
								<u-form-item label="检查依据" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.CHECK_BASIS" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
								<u-form-item label="问题描述" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.REMARK" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
								<u-form-item label="隐患地点" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.ADRESS" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
								<u-form-item label="整改期限" prop="CHECK_TIME" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.END_TIME" border="none" inputAlign="right" fontSize="14px"></u--input>

								</u-form-item>
								<view class="upload-title">附件</view>
								<full-upload v-model="item.Nav_Files" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>

							</view>


						</uni-collapse-item>
						<!-- <u-collapse-item :title="item.ROW_NUM + '. ' + item.MEASURE+' - '+transLevel(item.ISORNOT)+' - '+item.REMARK">
						</u-collapse-item> -->
					</view>
				</uni-collapse>
			</u--form>
			<check-action v-if="isLoadOK&&tableKey==1&&isAudit" :okApi="okApi" :refuseApi="refuseApi" :dataSource="auditModel"></check-action>
		</view>
		<!-- <view class="bottom-button" style="padding: 10px 16px;" v-if="isLoadOK&&tableKey==1&&isSign">
			<u-button type="primary" @click="onTableBtnAgree" color="#3d4b70">确认</u-button>
		</view> -->

	</view>
</template>

<script>
	import {
		initFilter,
		extendRule,
		extendInclude,
		getDepartmentName
	} from '../../../../utils/common'

	import {
		WBHDSign,
		WBHDGet
	} from '../../../../services/apply/subPages/scWB';
	import '../../../../utils/showMsg.js'
	import color from '../../../../uni_modules/uview-ui/libs/config/color'
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				model: {
					ID: '',
					ORG_ID: '',
					TaskID: null,
					PROJECT_ID: '',
					Nav_Project: {
						NAME: ''
					},
					Nav_CheckType: {
						NAME: ''
					},
					Nav_ListArea: [],
					Nav_ListArea: '',
					Nav_ListAreasID: '',
					MineTypes: '',
					Nav_Details: [{
						MineTypes: '',
						Nav_Area: {
							AREA: ''
						},
						ID: '',
						ORG_ID: '',
					}]
				},
				listPropUpload: ['PARENT_ID'],
				listPropValUpload: [],
				paddingBottom: '150',
				TaskID: "",
				tableKey: '0',
				isLoadOK: false,
				isSign: true,
				isAudit: true,
				DEALOPINION: "",
				ORG_ID: uni.getStorageSync('orgId'),
			}
		},
		onLoad(option) {
			this.model.ID = option.ID;
			this.TaskID = option.taskID;
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.okApi = option.okApi
			this.refuseApi = option.refuseApi
			this.auditModel = {
				...this.$store.state.auditModel,
				TaskID: option.taskID ? option.taskID : ''
			}
			this.loadData()
		},
		methods: {
			transLevel(level) {
				if (level == 0) {
					return '否';
				}
				if (level == 1) {
					return '是 ';
				}
			},
			getDepartmentName(value) {
				const codeMap = {
					'0': '全公司',
					'10': '选矿厂',
					'20': '露天矿',
					'30': '尾矿库',
					'40': '地下矿'
				};

				// 去除首尾下划线并分割
				const codes = value.replace(/^_+|_+$/g, '').split('_');

				// 映射代码到部门名称并过滤无效代码
				const departments = codes
					.map(code => codeMap[code])
					.filter(name => name);

				// 拼接结果，若为空则返回未知部门
				return departments.length > 0 ? departments.join('、') : '未知部门';
			},
			loadData() {
				const json = initFilter(this.ORG_ID)
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_Project')
				extendInclude(json, 'Nav_User')
				extendInclude(json, 'Nav_Details.Nav_Area')
				extendInclude(json, 'Nav_Details.Nav_Files.Nav_ImgFile')
				extendInclude(json, 'Nav_Files.Nav_ImgFile')
				 json.IgnoreDataRule = true;
				WBHDGet(json).then(res => {
					this.model = res
					// this.model.MineType = this.getDepartmentName(res.MineType)
					this.model.CHECK_TIME = uni.$u.timeFormat(res.CHECK_TIME, 'yyyy-mm-dd')
					if (res.MineType) {
						this.model.MineTypes = getDepartmentName(res.MineType)
					}
					this.model.Nav_Details.map(item => {
						let MineTypeName = {
							0: '全公司',
							10: '选矿厂',
							20: '尾矿库',
							30: '露天矿',
							40: '地下矿',
						}
						if (item.MineType) {
							item.MineTypes = MineTypeName[item.MineType]
						}
						item.END_TIME = uni.$u.timeFormat(item.END_TIME, 'yyyy-mm-dd')
					})
					this.isLoadOK = true
				})
			},
			onTableBtnAgree() {
				const json = initFilter(this.ORG_ID)
				json.Parameter1 = this.model.TASK_ID;
				json.Parameter2 = this.TaskID;
				json.Parameter3 = uni.getStorageSync('appInfo')?.User?.ID || ''
				json.Parameter4 = this.model.ID;
				WBHDSign(json).then(res => {
					if (res) {
						uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						}, 'success', 1000)
					}
				})
			},

		}
	}
</script>

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