<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-if="model.Nav_ApplyDepartment" 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-if="model.Nav_ApplyUser" 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="检查类型：" prop="Check_Type">
						<u--input v-if="model.Nav_CheckType" 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" 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_Date">
						<u--input v-model="model.CHECK_TIME" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>
					<u-form-item label="检查人员：" prop="Check_Date">
						<u--input v-model="model.CHECK_PERSON" disabled disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">
						</u--input>
					</u-form-item>
					<view class="upload-title">附件：</view>
					<full-upload v-model="model.Nav_RectifyFiles" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>
				</u--form>
				<u--form labelWidth="auto" :model="model" ref="wForm" class="sub-form">
					<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;margin-top: 20px;">隐患内容</view>
					<uni-collapse :border="false" accordion>
						<view v-for="(item, index) in model.Nav_RectifyDetails" :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_RiskArea?index+1+'.'+item.Nav_RiskArea.NAME:index+1+'.'}}
											<!-- <span v-if="item.Nav_RecitifyUser && item.Nav_RecitifyUser.NAME">
											（{{ item.Nav_RecitifyUser.NAME}}）
										</span> -->
										</view>
									</view>
								</template>
								<view class="content" style="padding-left:10px;">
									<u-form-item label="检查区域：" prop="CHECK_TIME">
										<u--input disabled v-model="(item.Nav_RiskArea||{}).NAME" disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px">

										</u--input>
									</u-form-item>
									<u-form-item label="隐患描述：" prop="CHECK_TIME">
									</u-form-item>
									<u-textarea v-model="(item.Nav_Question||{}).DESCREPTION" disabled >
									</u-textarea>
									
									<u-form-item label="隐患具体描述：" prop="CHECK_TIME">
									
									</u-form-item>
									<u-textarea v-model="item.HIDDEN_DESCRIPTION" disabled placeholder="请填写隐患具体描述">
									</u-textarea>
									<!-- <u--textarea v-model="item.Nav_Question.DESCREPTION" disabled placeholder="请选择隐患描述" maxlength="-1"></u--textarea> -->
									<u-form-item label="隐患等级" prop="HIDDEN_LEVEL" border-bottom>
										<u--input v-model="item.HIDDEN_LEVELName" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="隐患地点" prop="HIDDEN_PLACE" border-bottom>
										<u--input v-model="item.HIDDEN_PLACE" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
										</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="item.ReasonsNAME"  border="none"></u--textarea>
									
									
									<u-form-item label="整改措施" prop="HIDDEN_PLACE" border-bottom>
										
									</u-form-item>
										<u--textarea disabled autoHeight disabledColor="#fff" v-model="(item.Nav_Question||{}).DEMAND" border="none"></u--textarea>

									<u-form-item label="整改期限" prop="HIDDEN_PLACE">
										<u--input v-model="item.RECITIFY_TIME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="整改落实人" prop="HIDDEN_PLACE" border-bottom>
										<u--input v-model="(item.Nav_ImplementUser||{}).NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="验收人" prop="HIDDEN_PLACE" border-bottom>
										<u--input v-model="(item.Nav_AcceptUser||{}).NAME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="隐患照片" prop="CHECKSTANDARD">
									</u-form-item>
									<full-upload v-model="item.Nav_RectifyDetailFiles" :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.RECTIFICATION_MEASURES" disabled placeholder="请填写备注">
									</u-textarea>
								</view>


							</uni-collapse-item>
						</view>
					</uni-collapse>
				</u--form>
				<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>
	</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 {
		GetDangerRectifyShow,
		SKRectifyNoticeShow
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import stepTitle from '@/components/custom/step-title.vue'
	import {
		getEnum,
		GetEnumAnyOrder
	} from '../../../../services/common';
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				isAudit: false,
				isLoadOK: false,
				tableKey: 0,
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				model: {
					Nav_Files: [],
					Check_Type: '',
					Check_Period: '',
					Check_Level: '',
					Check_Date: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					Nav_ApplyDepartment: {
						NAME: '',
					},
					Nav_ApplyUser: {
						NAME: ''
					},

					Nav_CheckRecordDetails: [{
						Nav_RiskArea: {
							NAME: ''
						},
						Nav_Users: [],

					}],
				},
				peopleSelectOption: {
					showSelector: false,
					value: null,
					index: 0,
					defaultChecked: []
				},
				dateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM'),
				stepsText: ['发起', '确认', '归档'],
				stepsPage: 0,
				Pu: '',
				Check_Type_ID: '',
				TypeListres: {},
				TaskID: '',
				poparr: '',
				enumsData: {}, // 存储所有枚举数据（键：枚举名称，值：处理后的枚举列表）
				enumsText: {} // 存储枚举文本列表（用于下拉选择等场景）

			}
		},
		onLoad(option) {
			this.TaskID = option.taskID ? option.taskID : '';
			this.ID = option.ID ? option.ID : ''
			this.model.ID = option.ID ? option.ID : '';
			this.tableKey = option.tableKey ? option.tableKey : '0'
			this.isAudit = option.isAudit
			this.fetchEnums(['SKProductionUnit', 'SKPLANCHECKFREQUENCYEnum', 'SKDepartmentTypeEnum', 'SKHiddenLevel']);
		},
		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 json = {}
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "")
				extendRule(json, 'ID', 1, this.model.ID);
				extendRule(json, 'TASK_ID', 1, this.TaskID);
				extendIgnoreDataRule(json)
				GetDangerRectifyShow(json).then(res => {
					this.model = res
					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 : '';
					if (this.model.Nav_RectifyDetails && this.model.Nav_RectifyDetails.length > 0) {
						this.model.Nav_RectifyDetails.map(item => {
							item.HIDDEN_LEVELName = item.HIDDEN_LEVEL !== undefined ? this.enumsData['SKHiddenLevel'].find(item1 => item1.code === item.HIDDEN_LEVEL).name : ''
							item.RECITIFY_TIME = item.RECITIFY_TIME ? uni.$u.timeFormat(item.RECITIFY_TIME,
								'yyyy-mm-dd') : ''
								let ReasonsNAME = ''
								if (item.Nav_RectifyDetailReasons && item.Nav_RectifyDetailReasons.length > 0) {
									for (let i = 0; i < item.Nav_RectifyDetailReasons.length; i++) {
										ReasonsNAME += (ReasonsNAME.length > 0 ? "," : "") + item
											.Nav_RectifyDetailReasons[i].Nav_Reason.NAME;
									}
								}
								item.ReasonsNAME = ReasonsNAME
							// item.MARKName = this.enumsData['SKMarkEnum'].find(item1 => item1.code === item.MARK).name;
						})
					}
					this.stepsPage = res.STATUS == 0 ? 0 : res.STATUS == 10 ? 1 : 2
				})
				this.isLoadOK = true
			},
			submit() {
				let json = {};
				json.ID = this.ID;
				json.TaskID = this.TaskID;
				SKRectifyNoticeShow(json).then(res => {
					uni.$showMsgFunc('操作成功!', () => {
							uni.navigateBack()
						},
						'success', 1000)
				})
			}
		}



	}
</script>

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