<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.Nav_ProductionUnit||{}).NAME" 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" 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" 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" disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
						</u--input>
					</u-form-item>
					<view class="upload-title">隐患照片：</view>
					<full-upload v-model="model.Nav_Photos" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>
					<u--form labelWidth="auto" :model="model" ref="wForm" class="demo-ruleForm" 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>
						<u-form-item label="检查内容：">
							<u--input v-model="(model.Nav_Contents||{}).CHECKCONTENT" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
							</u--input>
						</u-form-item>
						<!-- <u-form-item label="检查依据:">
						</u-form-item>
						<u--textarea v-model="model.Nav_BasicsName" disabled maxlength="-1"></u--textarea>
						<u-form-item label="判定标准:">
							<u--input v-model="model.CHECKSTANDARD" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
							</u--input>
						</u-form-item> -->
						<u-form-item label="隐患描述:" prop="HIDDEN_DESCRIPTION">
						</u-form-item>
						<u--textarea v-model="(model.Nav_Question||{}).DESCREPTION" disabled maxlength="-1" border="none"></u--textarea>
						<u-form-item label="隐患等级" prop="HIDDEN_LEVEL">
							<u--input v-model="model.HIDDEN_LEVELName" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
							</u--input>
						</u-form-item>
						<u-form-item label="整改措施:">
							<u--input v-model="model.RECTIFICATION_MEASURES" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
							</u--input>
						</u-form-item>
						<!-- <u-form-item label="检查层级：" prop="Check_Level">
							<u--input v-model="model.DEPARTMENT_TYPEName" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">

							</u--input>

						</u-form-item>
						<u-form-item label="检查类型：" prop="Check_Type">
							<u--input v-model="(model.Nav_CheckType||{}).NAME" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px"></u--input>
						</u-form-item>
						<u-form-item label="检查周期：" prop="Check_Period">
							<u--input v-model="model.PLANCHECKFREQUENCYName" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px"></u--input>

						</u-form-item> -->
						<u-form-item label="隐患原因" prop="Nav_Reasons">
							<!-- <u-icon style="margin-left: 4px;" slot="right" name="arrow-down" size="12"></u-icon> -->
						</u-form-item>
						<u--textarea disabled autoHeight disabledColor="#fff" v-model="model.ReasonsNAME" border="none"></u--textarea>

						<u-form-item label="整改责任人" prop="HIDDEN_PLACE">
							<u--input v-model="(model.Nav_RecitifyUser||{}).NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
							</u--input>
						</u-form-item>
						<u-form-item label="整改期限" prop="HIDDEN_PLACE">
							<u--input v-model="model.RECITIFY_TIME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
							</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-item label="备注" prop="HIDDEN_PLACE" border-bottom>
						</u-form-item>
						<u-textarea v-model="item.REMARK" disabled placeholder="请填写备注">
						</u-textarea> -->
					</u--form>
				</u--form>
			</view>
			<check-action v-if="isLoadOK && tableKey === '1'&&isAudit " :okApi="okApi" :refuseApi="refuseApi" :dataSource="$store.state.auditModel"></check-action>
			<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>
		</view>
	</view>
</template>

<script>
	import {
		extendFilterGroup,
		extendGroupRule,
		extendInclude,
		extendOrder,
		extendRule,
		extendIgnoreDataRule,
		guid,
		initFilter,
		initFilterGroup,
		transformData
	} from '../../../../utils/common'
	import {
		MineTypeIndex,
		MineTypeName
	} from '../../../../utils/enums.js'
	import {
		GetVerifyRiskReportRecord,
		SKHiddenDangerIdentityUpdate
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import {
		getEnum,
		GetEnumAnyOrder
	} from '../../../../services/common';
	import stepTitle from '@/components/custom/step-title.vue'
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				model: {
					Product_Unit: '',
					Nav_RiskArea: {
						NAME: ''
					},
					HIDDEN_PLACE: '',
					HIDDEN_DESCRIPTION: '',
					Nav_Photos: [],
					Nav_Contents: {
						CHECKCONTENT: ''
					},
					Nav_ApplyDepartment: {
						NAME: ''
					},
					Nav_ApplyUser: {
						NAME: ''
					},
					Nav_Question: {
						DESCREPTION: ''
					},
					CHECKPROOF: '',
					CHECKSTANDARD: '',
					HIDDEN_DESCRIPTION_DETAIL: '',
					HIDDEN_LEVEL: '',
					RECTIFICATION_MEASURES: '',
					DEPARTMENT_TYPE: '',
					Nav_CheckType: {
						NAME: ''
					},
					PLANCHECKFREQUENCY: '',
					Nav_RecitifyUser: {
						NAME: ''
					},
					RECITIFY_TIME: '',
					IS_STORE: '',
					Nav_Files: [],
					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.okApi = option.okApi
			this.refuseApi = option.refuseApi
			this.auditModel = {
				...this.$store.state.auditModel,
				TaskID: option.taskID ? option.taskID : ''
			}
			this.fetchEnums(['SKProductionUnit', 'SKPLANCHECKFREQUENCYEnum', 'SKDepartmentTypeEnum',
				'SKHiddenLevel'
			]);
			// this.loadData()
		},
		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')
				const json = initFilter(orgId, "", "")
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_Report');
				extendInclude(json, 'Nav_ApplyUser');
				extendInclude(json, 'Nav_ApplyDepartment');
				extendInclude(json, 'Nav_ProductionUnit');
				extendInclude(json, 'Nav_Basics');
				extendInclude(json, 'Nav_Question');
				extendInclude(json, 'Nav_ApplyUser');
				extendInclude(json, 'Nav_Basics.Nav_Law');
				extendInclude(json, 'Nav_RiskArea');
				extendInclude(json, 'Nav_Contents');
				extendInclude(json, 'Nav_CheckType');
				extendInclude(json, 'Nav_RecitifyUser');
				extendInclude(json, 'Nav_Photos');
				extendInclude(json, 'Nav_Files');
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				extendInclude(json, 'Nav_Photos.Nav_ImgFile');
				extendIgnoreDataRule(json)
				// extendRule(json, 'TASK_ID', 1, this.TaskID);
				GetVerifyRiskReportRecord(json).then(res => {
					this.model = res
					this.STATUS = res.STATUS
					this.model.CREATE_TIME = res.CREATE_TIME

					this.model.CONTEXT = res.CONTEXT ? res.CONTEXT : ''
					this.model.RECITIFY_TIME = uni.$u.timeFormat(res.RECITIFY_TIME,
						'yyyy-mm-dd')
					let ReasonsNAME = ''
					if (res.Nav_Reasons && res.Nav_Reasons.length > 0) {
						for (let i = 0; i < res.Nav_Reasons.length; i++) {
							ReasonsNAME += (ReasonsNAME.length > 0 ? "," : "") + res
								.Nav_Reasons[i].Nav_Reason.NAME;
						}
					}
					this.model.ReasonsNAME = ReasonsNAME
					this.model.PLANCHECKFREQUENCYName = res.PLANCHECKFREQUENCY !== undefined ? this.enumsData['SKPLANCHECKFREQUENCYEnum'].find(item => item.code === res.PLANCHECKFREQUENCY).name : '';
					this.model.DEPARTMENT_TYPEName = res.DEPARTMENT_TYPE !== undefined ? this.enumsData['SKDepartmentTypeEnum'].find(item => item.code === res.DEPARTMENT_TYPE).name : '';
					this.model.HIDDEN_LEVELName = res.HIDDEN_LEVEL !== undefined ? this.enumsData['SKHiddenLevel'].find(item => item.code === res.HIDDEN_LEVEL).name : '';
				})
				this.isLoadOK = true

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

		}



	}
</script>

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