<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="Nav_Project.NAME" borderBottom>
					<u--input v-if="model.Nav_Project" v-model="model.Nav_Project.NAME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="检查时间：" prop="Nav_Project.UNIT_NAME" borderBottom>
					<u--input v-model="model.CHECK_TIME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="检查类型：" prop="Nav_Type.NAME" borderBottom>
					<u--input v-if="model.Nav_CheckType" v-model="model.Nav_CheckType.NAME" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="生产单元：" borderBottom>
					<u--input autoHeight v-model="model.MineType" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>
				<u-form-item label="检查区域：" borderBottom>
					<u--input autoHeight v-model="model.Nav_ListAreas" border="none" inputAlign="right" disabled disabledColor="#ffffff" fontSize="14px"></u--input>
				</u-form-item>

			</u--form>
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" ref="sForm" class="sub-form" style="margin-top: 10px;">
				<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.Nav_Area.AREA}}
									</view>

								</view>
							</template>
							<view class="content" style="margin: 0px 10px;">
								<u-form-item label="检查人员:" prop="UsersName">

								</u-form-item>
								<u-textarea v-model="item.Nav_UsersName" disabled autoHeight></u-textarea>
								<u-form-item label="记录人员:" prop="DisCloseUser" borderBottom>
									<u--input disabledColor="#fff" disabled v-model="item.Nav_User.NAME" border="none" inputAlign="right" fontSize="14px"></u--input>
								</u-form-item>
								<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-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>

							</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>

		</view>
		<view class="bottom-button" style="padding: 10px 16px;" v-if="isLoadOK&&(tableKey==1||tableKey==4)">
			<u-button type="primary" @click="onTableBtnAgree" color="#3d4b70">确认</u-button>
		</view>

	</view>
</template>

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

	import {
		WBSCSign,
		WBSCGet
	} 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: {},
				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_CheckType')
				extendInclude(json, 'Nav_ListArea.Nav_CheckArea')
				extendInclude(json, 'Nav_Details.Nav_User')
				extendInclude(json, 'Nav_Details.Nav_Users.Nav_User')
				 json.IgnoreDataRule = true;
				WBSCGet(json).then(res => {
					this.model = res
					this.model.MineType =this.getDepartmentName(res.MineType)
					let arr =''
					res.Nav_ListArea.map(item=>{
						
						if(item.Nav_CheckArea&&item.Nav_CheckArea.AREA){
							arr+=item.Nav_CheckArea.AREA
						}

					})
					this.model.Nav_ListAreas = arr
					this.model.Nav_Details.map(item => {
						let arr = ''
						if (item.Nav_Users && item.Nav_Users.length > 0) {
							item.Nav_Users.map(item1 => {
								arr += item1.Nav_User.NAME
							})
						}
						item.Nav_User = {
							NAME: !item.Nav_User ? '' : item.Nav_User.NAME ? item.Nav_User.NAME : ''
						}
						item.Nav_Area = {
							AREA: !item.Nav_Area ? '' : item.Nav_Area.AREA ? item.Nav_Area.AREA : ''
						}
						item.Nav_UsersName = arr
						let MineTypeName = {
							0: '全公司',
							10: '选矿厂',
							20: '尾矿库',
							30: '露天矿',
							40: '地下矿',
						}
						item.MineTypes = MineTypeName[item.MineType]
					})
					// if (this.model.STATUS == 30) {
					// 	this.isSign = true;
					// 	this.isAudit = false;
					// } else if (this.model.STATUS == 20) {
					// 	this.isSign = false;
					// 	this.isAudit = true;
					// }
					this.isLoadOK = true
				})
			},
			onTableBtnAgree() {
				const json = initFilter(this.ORG_ID)
				json.Parameter1 = this.model.ID;
				json.Parameter2 = this.TaskID;
				json.Parameter3 = uni.getStorageSync('appInfo')?.User?.ID || ''
				WBSCSign(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>