<!-- 隐患上报 查看  BS006_VIEW-->
<template>
	<view class="page-wrap">
		<view class="card">
			<uni-card margin="0" :is-shadow="true">
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" ref="wForm"
					errorType="border-bottom">
					<u-form-item label="编码" prop="CODE" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.CODE" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="隐患上报名称" prop="NAME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.NAME" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<!--<u-form-item label="检查任务" prop="Nav_Check.NAME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.Nav_Check.NAME" border="none"
							slot="right" inputAlign="right"></u--input>
					</u-form-item>-->
					<u-form-item label="检查类型" prop="Nav_CheckType.NAME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.Nav_CheckType.NAME" border="none"
							slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查层级" prop="Nav_CheckTypeLevel.Nav_Enums.NAME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.Nav_CheckTypeLevel.Nav_Enums.NAME"
							border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查时间" prop="CREATE_TIME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.CREATE_TIME" border="none"
							slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<view class="upload-title">附件</view>
<!--					<u-album :urls="model.attachments" singleSize="70" keyName="src"></u-album>-->
					<full-upload v-model="model.Nav_Files" :isShowBtn='false'></full-upload>
				</u--form>
			</uni-card>
		</view>
		<u-sticky offset-top="20">
			<view class="sub-form">
				<view class="sub-form-wrap">
					<u-form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom" :borderBottom="false"
						ref="sForm">
						<u-collapse accordion>
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
								v-for="(item, index) in model.Nav_ListRiskSubmitContent" :name="index">
								<u-collapse-item title-border="none" :show-arrow="false" :border="false">
									<view slot="title" class="collapse-title">
										<view class="down">
											<uni-icons type="bottom"></uni-icons>
										</view>
										<view class="text">{{index + 1 + '. ' +item.CHECKCONTENT}}</view>
									</view>
									<u-form-item label="检查区域" prop="Nav_RiskArea.NAME" borderBottom>
										<u--input disabled disabledColor="#ffffff" v-model="item.Nav_RiskArea.NAME"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<view class="label-title">检查内容</view>
									<u-form-item prop="DESCREPTION" borderBottom>
										<u--textarea disabled autoHeight v-model="item.DESCREPTION" placeholder="检查内容"
											border="surround"></u--textarea>
									</u-form-item>

									<u-form-item label="问题等级" prop="QUESTION_LEVEL_SHOW" borderBottom>
										<u--input disabled disabledColor="#ffffff" v-model="item.QUESTION_LEVEL_SHOW"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<view class="label-title">整改建议与措施</view>
									<u-form-item prop="DEMAND" borderBottom>
										<u--textarea disabled autoHeight v-model="item.DEMAND" placeholder="整改建议与措施"
											border="surround"></u--textarea>
									</u-form-item>
									<u-form-item label="隐患原因" prop="listCheckDetailReason" borderBottom>
										<u--input disabledColor="#ffffff" v-model="item.listCheckDetailReason"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="隐患地点" prop="ADDRESS" borderBottom>
										<u--input disabledColor="#ffffff" v-model="item.ADDRESS" border="none"
											inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="整改期限" prop="LastDateUser" borderBottom>
										<u--input v-model="item.LastDateUser" disabledColor="#fff" placeholder="请选择整改期限"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="整改实施单位" prop="Nav_DepartmentDeal.NAME" borderBottom>
										<u--input disabledColor="#fff" v-model="item.Nav_DepartmentDeal.NAME"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="整改责任人" prop="Nav_UserDeal.NAME" borderBottom>
										<u--input disabledColor="#fff" :value="item.responsibler" border="none"
											inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="验收人" prop="Nav_UserCheck.NAME" :borderBottom="false">
										<u--input disabledColor="#fff" :value="item.accepter" border="none"
											inputAlign="right"></u--input>
									</u-form-item>
								</u-collapse-item>
							</uni-card>
						</u-collapse>
					</u-form>
				</view>
			</view>
		</u-sticky>
		<audit-process :show="showAudit" @close="handleCloseAudit" :dataSource="auditData" />
	</view>
</template>

<script>
	import {
		guid,
		initFilter,
		extendRule,
		extendInclude,
		extendGroupRule,
		initFilterGroup,
		extendFilterGroup,
		extendFilterGroupGroupRules
	} from '../../../../utils/common'

	import {
		GetBS006,
		getLoadAuditData
	} from '../../../../services/apply/subPages/BS/riskSubmit'
	import config from '../../../../config/common'

	export default {
		data() {
			return {
				sourceUrl: config.uni_app_web_source_url,
				tableKey: '0',
				TaskID: '',
				model: {
					ID: '',
					TaskID: '',
					Nav_Check: {
						NAME: ''
					},
					Nav_CheckType: {
						NAME: ''
					},
					Nav_CheckTypeLevel: {
						Nav_Enums: {
							NAME: ''
						}
					},
					Nav_Files: [],
					attachments: [], // 附件
					Nav_ListRiskSubmitContent: [{
						Nav_Department: {
							NAME: ''
						},
						LastDateUser: null,
						departmentName: '',
						userChecker: '',
						userDetailer: '',
						Nav_Files: [],
						Nav_ListRiskQuestionReason: [{
							Nav_RiskReason: {
								NAME: ''
							}
						}],
						listCheckDetailReason: '',
						accepter: '', // 验收人
						responsibler: '', // 整改责任人
						Nav_RiskArea: {
							NAME: ''
						},
						Nav_DepartmentDeal: {
							NAME: ''
						},
						Nav_UserCheck: {
							NAME: ''
						},
						Nav_UserDeal: {
							NAME: ''
						}
					}]
				},
				isLoadOK: false,
				lists: [],
				auditData: [],
				showAudit: false
			}
		},
		onLoad(option) {
			this.model.ID = option.ID
			this.loadData()

		},
		methods: {
			loadData() {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "CODE", 1)
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_Check');
				extendInclude(json, 'Nav_CheckType');
				extendInclude(json, 'Nav_CheckTypeLevel.Nav_Enums');
				extendInclude(json, 'Nav_ListRiskSubmitContent');
				extendInclude(json, 'Nav_ListRiskSubmitContent.Nav_SafeCheckDetail');
				extendInclude(json, 'Nav_ListRiskSubmitContent.Nav_CheckMain');
				extendInclude(json, 'Nav_ListRiskSubmitContent.Nav_Question');
				extendInclude(json, 'Nav_ListRiskSubmitContent.Nav_CheckMain.Nav_CheckProject');
				extendInclude(json, 'Nav_ListRiskSubmitContent.Nav_UserDeal');
				extendInclude(json, 'Nav_ListRiskSubmitContent.Nav_UserCheck');
				extendInclude(json, 'Nav_ListRiskSubmitContent.Nav_Department');
				extendInclude(json, 'Nav_ListRiskSubmitContent.Nav_DepartmentDeal');
				extendInclude(json, 'Nav_ListRiskSubmitContent.Nav_ListRiskQuestionReason.Nav_RiskReason');
				extendInclude(json, 'Nav_Files.Nav_ImgFile');
				json.IgnoreDataRule = true
				GetBS006(json).then(res => {
					this.model = res
					if (this.model.Nav_ListRiskSubmitContent != null && this.model.Nav_ListRiskSubmitContent
						.length > 0) {
						let reasons = ''
						this.model.Nav_ListRiskSubmitContent.forEach(e => {
							reasons = ''
							if (e.Nav_ListRiskQuestionReason != null && e.Nav_ListRiskQuestionReason
								.length > 0) {
								e.Nav_ListRiskQuestionReason.forEach(er => {
									reasons += er.Nav_RiskReason.NAME
								})
							}
							e.listCheckDetailReason = reasons

							e.accepter = e.Nav_UserCheck?.NAME || ''
							e.responsibler = e.Nav_UserDeal?.NAME || ''
						})
					}
					if (this.model.Nav_Files && this.model.Nav_Files.length) {
						this.model.attachments = this.model.Nav_Files
							.filter(i => !!i.Nav_ImgFile?.Nav_File)
							.map(o => {
								return {
									...o.Nav_ImgFile.Nav_File,
									src: this.sourceUrl + o.Nav_ImgFile.FILE_PATH
								}
							})
					}
					this.isLoadOK = true
				})
			},
			loadAuditData() {
				const orgId = uni.getStorageSync('orgId')
				// const json = initFilter(orgId, "8ca253be-2f46-7e21-b8a7-ccc1000271d8", "CODE", 1)
				const json = initFilter(orgId, this.model.ID, "CODE", 1)
				json.Parameter2 = "T_BS_RISK_SUBMIT_NOTICE,RISK_SUBMIT_ID"
				return new Promise((resolve, reject) => {
					getLoadAuditData(json).then(res => {
						if (res) {
							if (res && res[0].Nav_ApproveDetails.length > 0) {
								resolve(res)
							}
						} else {
							uni.showToast({
								title: '暂无审批数据',
								icon: 'none'
							})
						}
					}).catch(err => {
						reject(err)
					})
				})
			},
			handleCloseAudit() {
				this.showAudit = false
			}
		},
		computed: {},
		async onNavigationBarButtonTap() {
			const res = await this.loadAuditData()
			if (res) {
				this.auditData = res
				this.showAudit = true
			}
		}
	}
</script>


<style scoped>
	@import url("../../../../style/css/editTemplate.css");
	.collapse-title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
	}
	.collapse-title .down {
		width: 20px;
		flex: 0 0 auto;
	}
	.collapse-title .text {
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
		flex: 1;
		width: calc(100% - 60px);
	}
</style>
