<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="检查类型：" 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="PLANCHECKFREQUENCYName">
						<u--input v-model="model.PLANCHECKFREQUENCYName" disabledColor="#ffffff" border="none" inputAlign="right" fontSize="14px"></u--input>
					</u-form-item>
					<u-form-item label="检查层级：" prop="DEPARTMENT_TYPEName">
						<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_TIME">
						<u--input v-model="model.CHECK_TIME" disabled disabledColor="#ffffff" placeholder="请选择检查时间" border="none" inputAlign="right" fontSize="14px">

						</u--input>
					</u-form-item>
					<!-- <u-form-item label="检查人员：" prop="UserNames">
					</u-form-item>
					<rich-text style="line-height: 30px;" autoHeight type="textarea" v-html="model.UserNames" border="none" inputAlign="right" disabled class="richtext"></rich-text> -->
					<view class="upload-title">附件：</view>
					<full-upload v-model="model.Nav_ReportFiles" :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_ReportDetails" :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+'.'}}
										</view>
										<view @click.stop>
											<!-- <u-icon @click="handleDelRowBefore(index)" name="trash" color="#ff4d4f" size="21" style="margin-right: 10px;"></u-icon> -->
										</view>
									</view>
								</template>
								<view class="content">
									<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_Contents||{}).CHECKCONTENT" disabled></u-textarea>

									<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" border="none">

									</u-form-item>
									<u-textarea v-model="item.HIDDEN_DESCRIPTION" disabled autoHeight border="none">
									</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-form-item>
									<u--textarea disabled autoHeight disabledColor="#fff" v-model="item.ReasonsNAME" border="none"></u--textarea>

									
									<u-form-item label="隐患照片" prop="CHECKSTANDARD">
									</u-form-item>
									<full-upload v-model="item.Nav_ReportDetailFiles" :isShowBtn='false' :listProp='listPropUpload' :listPropVal='listPropValUpload'></full-upload>
									<u-form-item label="整改责任人" prop="HIDDEN_PLACE" border-bottom>
										<u--input v-model="(item.Nav_RecitifyUser||{}).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.RECITIFY_TIME" disabled disabledColor="#ffffff" inputAlign="right" fontSize="14px" border="none">
										</u--input>
									</u-form-item>
									<u-form-item label="整改措施" prop="HIDDEN_PLACE">

									</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-form-item>
									<u-textarea v-model="item.REMARK"  disabled autoHeight disabledColor="#fff" border="none">
									</u-textarea>
								</view>
							</uni-collapse-item>
						</view>
					</uni-collapse>
				</u--form>
			</view>
			<check-action v-if="isLoadOK && tableKey === '1'&&isAudit==='true' " :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 {
		FMProductionUnit,
		CheckPeriods,
		CheckLevels
	} from '../../../../utils/enums.js'
	import {
		GetHiddenDangerReportNew,
		HiddenDangerReportUpdate
	} from '../../../../services/apply/subPages/SK/SKServices.js'
	import {
		getRequest,
	} from '../../../../services/apply/FOServices/FOServices';
	import stepTitle from '@/components/custom/step-title.vue'
	import {
		getEnum,
		GetEnumAnyOrder
	} from '../../../../services/common';
	export default {
		components: {
			stepTitle,
		},
		data() {
			return {
				showDelModalIndex: undefined,
				showDelModalIndex1: undefined,
				subsectionList: ['无隐患', '有隐患', '不涉及'],
				curNow: 1,
				isAudit: false,
				isLoadOK: false,
				tableKey: 0,
				RiskLevel: ['一般', '重大'],
				listPropUpload: ['NOTIFY_ID'],
				listPropValUpload: [],
				ORG_ID: uni.getStorageSync('orgId'),
				model: {
					Nav_ApplyDepartment: {
						NAME: ''
					},
					Nav_ApplyUser: {
						NAME: ''
					},
					CREATE_TIME: '',
					Nav_Files: [],
					Nav_CheckType: {
						NAME: ''
					},
					Check_Period: '',
					Check_Level: '',
					Check_Date: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss'),
					Nav_ReportDetails: [{
						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.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'])
		},
		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.ID);
				extendRule(json, 'TASK_ID', 1, this.TaskID);
				extendIgnoreDataRule(json)
				GetHiddenDangerReportNew(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_ReportDetails && this.model.Nav_ReportDetails.length > 0) {
						this.model.Nav_ReportDetails.map(item => {
							item.HIDDEN_LEVELName = item.HIDDEN_LEVEL !== undefined ? this.enumsData['SKHiddenLevel'].find(item1 => item1.code === item.HIDDEN_LEVEL).name : ''
							// item.MARKName = this.enumsData['SKMarkEnum'].find(item1 => item1.code === item.MARK).name;
						let ReasonsNAME = ''
						if (item.Nav_ReportDetailReasons && item.Nav_ReportDetailReasons.length > 0) {
							for (let i = 0; i < item.Nav_ReportDetailReasons.length; i++) {
								ReasonsNAME += (ReasonsNAME.length > 0 ? "," : "") + item
									.Nav_ReportDetailReasons[i].Nav_Reason.NAME;
							}
						}
						item.ReasonsNAME = ReasonsNAME
						})
					}
					this.stepsPage = res.STATUS == 0 ? 0 : res.STATUS == 10 ? 1 : res.STATUS == 20 ? 2 : 3

				})
				this.isLoadOK = true
			},
			handlePack(index, index1) {
				this.model.Nav_ReportDetails[index].Nav_DetailContents[index1].showPack = this.model.Nav_ReportDetails[index].Nav_DetailContents[index1].showPack == false ? true : false
				this.model.Nav_ReportDetails = [...this.model.Nav_ReportDetails]

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



	}
</script>

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