<template>
	<!-- 检查记录查看 -->
	<view class="page-wrap" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<view class="card">
			<uni-card margin="0" :is-shadow="true">
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model">
					<!-- 安全检查通知 -->
					<u-form-item label="安全检查名称" prop="NAME" borderBottom>
						<u--input v-model="model.NAME" border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="安全检查编号" prop="CODE" borderBottom>
						<u--input v-model="model.CODE" border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查类型" prop="Nav_CheckType.NAME" borderBottom>
						<u--input v-model="model.Nav_CheckType.NAME" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查范围" prop="CHECKOBJECT_DESCRIPTION" borderBottom>
						<u--input v-model="model.CHECKOBJECT_DESCRIPTION" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>

					<u-form-item label="检查层级" prop="Nav_CheckTypeLevel.Nav_Enums.NAME" borderBottom>
						<u--input v-model="model.Nav_CheckTypeLevel.Nav_Enums.NAME" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查时间" prop="CHECKTIME" borderBottom>
						<u--input v-model="model.CHECKTIME" border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>

					<view class="label-title">检查区域</view>
					<u-form-item prop="RiskAreaNAME" borderBottom>
						<u--textarea disabled autoHeight v-model="model.RiskAreaNAME" placeholder="检查区域"
							border="surround"></u--textarea>
					</u-form-item>

					<view class="label-title">检查项目</view>
					<u-form-item prop="CheckProjectNAME" borderBottom>
						<u--textarea disabled autoHeight v-model="model.CheckProjectNAME" placeholder="检查项目"
							border="surround"></u--textarea>
					</u-form-item>

					<view class="label-title">检查项目分类</view>
					<u-form-item prop="CheckProjectCategoryNAME" borderBottom>
						<u--textarea disabled autoHeight v-model="model.CheckProjectCategoryNAME" placeholder="检查项目分类"
							border="surround"></u--textarea>
					</u-form-item>

					<u-form-item label="检查人员" prop="CheckUsers" borderBottom>
						<u--input v-model="model.CheckUsers" border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>

					<view class="upload-title">附件</view>
					<full-upload :value="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"
						ref="sForm">
						<u-collapse :border="false" accordion>
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
								v-for="(item, index) in model.Nav_ListSafeCheckDetail">
								<u-collapse-item :thumb='item.QUESTION_LEVEL==null||item.QUESTION_LEVEL==0 ?null:"../../../../static/warm.png"' :title="index + 1 + '. ' + item.CHECKCONTENT">
									<u-form-item label="检查项目" prop="Nav_CheckProject.NAME" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.Nav_CheckProject.NAME"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<view class="label-title">检查内容</view>
									<u-form-item prop="CHECKCONTENT" borderBottom>
										<u--textarea disabled autoHeight v-model="item.CHECKCONTENT" placeholder="检查内容"
											border="surround"></u--textarea>
									</u-form-item>

									<view class="label-title">检查依据</view>
									<u-form-item prop="CHECKPROOF" borderBottom>
										<u--textarea disabled autoHeight v-model="item.CHECKPROOF" placeholder="检查依据"
											border="surround"></u--textarea>
									</u-form-item>

									<view class="label-title">检查问题描述</view>
									<u-form-item prop="listCheckDetailQuestion" borderBottom>
										<u--textarea disabled autoHeight v-model="item.listCheckDetailQuestion"
											placeholder="检查问题描述" border="surround"></u--textarea>
									</u-form-item>

									<u-form-item label="问题等级" prop="QUESTION_LEVEL_DESCRIPTION" borderBottom>
										<u--input disabled disabledColor="#fff"
											v-model="item.QUESTION_LEVEL_DESCRIPTION" border="none"
											inputAlign="right"></u--input>
									</u-form-item>

									<view class="label-title">整改建议与措施</view>
									<u-form-item prop="demands" borderBottom>
										<u--textarea disabled autoHeight v-model="item.demands" placeholder="整改建议与措施"
											border="surround"></u--textarea>
									</u-form-item>

									<u-form-item label="检查人员" prop="checkerNames" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.checkerNames"
											border="none" inputAlign="right"></u--input>
									</u-form-item>

									<u-form-item label="隐患地点" prop="ADDRESS" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.ADDRESS" border="none"
											inputAlign="right"></u--input>
									</u-form-item>
									<view class="upload-title">附件</view>
									<full-upload :value="item.Nav_Files" :isShowBtn='false'></full-upload>

								</u-collapse-item>
							</uni-card>
						</u-collapse>
					</u--form>
				</view>
			</view>
		</u-sticky>

		<check-action v-if="isLoadOK&& tableKey === '1' && isAudit == 'true'" :okApi="okApi" :refuseApi="refuseApi"
			:dataSource="$store.state.auditModel"></check-action>
	</view>
</template>

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

	import {
		GetCheckInfo034ShowPrint
	} from '../../../../services/apply/subPages/BS/safeCheck'

	export default {
		data() {
			return {
				isLoadOK: false,
				TaskID: '',
				paddingBottom: '170',
				model: {
					ID: '',
					TaskID: '',
					Nav_CheckType: {
						NAME: ''
					},
					Nav_CheckTypeLevel: {
						Nav_Enums: {
							NAME: '',
						}
					},
					Nav_ListSafeCheckDetail: [{
						checkerNames: '',
						listCheckDetailQuestion: '',
						demands: '',
						Nav_CheckProject: {
							NAME: ''
						}
					}]
				},
				ApproveID: '',
				isAudit: false,
				okApi: '',
				refuseApi: '',
				isLoadOK: false,
			}
		},
		onLoad(option) {
			this.model.ID = option.ID

			this.model.TaskID = option.taskID
			this.TaskID = option.taskID
			this.tableKey = option.tableKey
			this.isAudit = option.isAudit
			this.ApproveID = option.ApproveID
			this.okApi = option.okApi
			this.refuseApi = option.refuseApi

			this.auditModel = {
				...this.$store.state.auditModel,
				TaskID: this.TaskID
			}

			if (!this.tableKey || this.tableKey != '1')
				this.paddingBottom = 10
			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_CheckType');
				extendInclude(json, 'Nav_CheckTypeLevel.Nav_Enums');
				extendInclude(json, 'Nav_ListCheckRiskArea.Nav_RiskArea');
				extendInclude(json, 'Nav_ListCheckProject.Nav_CheckProject');
				extendInclude(json, 'Nav_ListCheckProjectCategory.Nav_CheckProjectCategory');
				extendInclude(json, 'Nav_Files.Nav_ImgFile');

				json.IgnoreDataRule = true
				GetCheckInfo034ShowPrint(json).then(res => {
					// console.log('res', res)
					this.model = res
					//数据组装
					let strRiskAreaNAME = ''
					if (res.Nav_ListCheckRiskArea && res.Nav_ListCheckRiskArea.length > 0) {
						for (let i = 0; i < res.Nav_ListCheckRiskArea.length; i++) {
							strRiskAreaNAME += (strRiskAreaNAME.length > 0 ? "," : "") + res.Nav_ListCheckRiskArea[
								i].Nav_RiskArea.NAME;
						}
					}

					let strCheckProjectNAME = ''
					if (res.Nav_ListCheckProject && res.Nav_ListCheckProject.length > 0) {
						for (let i = 0; i < res.Nav_ListCheckProject.length; i++) {
							strCheckProjectNAME += (strCheckProjectNAME.length > 0 ? "," : "") + res
								.Nav_ListCheckProject[i].Nav_CheckProject.NAME;
						}
					}

					let CheckProjectCategoryNAME = ''
					if (res.Nav_ListCheckProjectCategory && res.Nav_ListCheckProjectCategory.length > 0) {
						for (let i = 0; i < res.Nav_ListCheckProjectCategory.length; i++) {
							CheckProjectCategoryNAME += (CheckProjectCategoryNAME.length > 0 ? "," : "") + res
								.Nav_ListCheckProjectCategory[i].Nav_CheckProjectCategory.NAME;
						}
					}

					this.model.RiskAreaNAME = strRiskAreaNAME
					this.model.CheckProjectNAME = strCheckProjectNAME
					this.model.CheckProjectCategoryNAME = CheckProjectCategoryNAME

					// this.isLoadOK = true
					if (this.model.Nav_ListSafeCheckDetail != null && this.model.Nav_ListSafeCheckDetail.length >
						0) {
						let checkerNames = ''
						for (let i = 0; i < this.model.Nav_ListSafeCheckDetail.length; i++) {
							if (this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser != null && this.model
								.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser.length > 0) {
								checkerNames = ''
								for (let j = 0; j < this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser
									.length; j++) {
									checkerNames += ' ' + this.model.Nav_ListSafeCheckDetail[i]
										.Nav_ListCheckDetailUser[j].Nav_User.NAME
								}
							}
							this.model.Nav_ListSafeCheckDetail[i].checkerNames = checkerNames.substring(1)

							let listCheckDetailQuestion = ''
							let demands = ''
							if (this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion != null && this
								.model
								.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion.length > 0) {
								for (let j = 0; j < this.model.Nav_ListSafeCheckDetail[i]
									.Nav_ListCheckDetailQuestion
									.length; j++) {
									if (this.model.Nav_ListSafeCheckDetail[i]
										.Nav_ListCheckDetailQuestion[j].Nav_Question && this.model
										.Nav_ListSafeCheckDetail[i]
										.Nav_ListCheckDetailQuestion[j].Nav_Question.DESCREPTION) {
										listCheckDetailQuestion += ' ' + this.model.Nav_ListSafeCheckDetail[i]
											.Nav_ListCheckDetailQuestion[j].Nav_Question.DESCREPTION
									}

									if (this.model.Nav_ListSafeCheckDetail[i]
										.Nav_ListCheckDetailQuestion[j].Nav_Question && this.model
										.Nav_ListSafeCheckDetail[i]
										.Nav_ListCheckDetailQuestion[j].Nav_Question.DEMAND) {
										demands += ' ' + this.model.Nav_ListSafeCheckDetail[i]
											.Nav_ListCheckDetailQuestion[j].Nav_Question.DEMAND
									}
								}
							}
							this.model.Nav_ListSafeCheckDetail[i].listCheckDetailQuestion = listCheckDetailQuestion
								.substring(1)
							this.model.Nav_ListSafeCheckDetail[i].demands = demands
								.substring(1)
						}
					}

					this.isLoadOK = true
				})
			},
		},
		computed: {

		}
	}
</script>

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