<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">
					<!-- 安全检查通知 -->
					<u-form-item label="安全检查名称" prop="NAME" borderBottom>
						<u--input v-model="model.NAME" disabled disabledColor="#fff" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="安全检查编号" prop="CODE" borderBottom>
						<u--input v-model="model.CODE" disabled disabledColor="#fff" 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" disabled disabledColor="#fff" border="none"
							slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查范围" prop="NAME" borderBottom>
						<u--input v-model="model.NAME" border="none" disabled disabledColor="#fff" 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" disabled disabledColor="#fff"
							border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查时间" prop="CREATE_TIME" borderBottom>
						<u--input v-model="model.CREATE_TIME" disabled disabledColor="#fff" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>

					<u-form-item label="检查区域" prop="RiskAreaNAME" borderBottom>
						<u--input v-model="model.RiskAreaNAME" disabled disabledColor="#fff" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查项目" prop="CheckProjectNAME" borderBottom>
						<u--input v-model="model.CheckProjectNAME" disabled disabledColor="#fff" border="none"
							slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查项目分类" prop="CheckProjectCategoryNAME" borderBottom>
						<u--input v-model="model.CheckProjectCategoryNAME" disabled disabledColor="#fff" border="none"
							slot="right" inputAlign="right"></u--input>
					</u-form-item>

					<u-form-item label="检查人员" prop="CheckUsers" borderBottom>
						<u--input v-model="model.CheckUsers" border="none" disabled disabledColor="#fff" 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">
					<view class="sub-form-btns">
					</view>
					<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
						ref="sForm">
						<u-collapse :border="false" accordion value="1">
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
								v-for="(item, index) in model.Nav_ListSafeCheckDetail">
								<u-collapse-item :title="index + 1 + '. ' + item.CHECKCONTENT" name="1">
									<!-- <view slot="right-icon" class="row-action"></view> -->
									<!-- <view slot="value" class="row-action">
										<text @click.stop="handleOkRow">
											<u--text type="primary" text="确认"></u--text>
										</text>
										<text @click.stop="handleDelRowBefore(index)">
											<u--text type="error" text="删除"></u--text>
										</text>
									</view> -->
									<u-form-item label="检查区域" prop="Nav_CheckArea.NAME" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item['Nav_CheckArea'].NAME"
											border="none" inputAlign="right" slot="right"></u--input>
									</u-form-item>
									<u-form-item label="检查项目" prop="Nav_CheckProject.NAME" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item['Nav_CheckProject'].NAME"
											border="none" inputAlign="right" slot="right"></u--input>
									</u-form-item>


									<view class="label-title">检查内容</view>
									<u-form-item prop="CHECKCONTENT" borderBottom>
										<!-- <label>{{item.CHECKCONTENT}}</label> -->
										<!-- <u--input disabled disabledColor="#fff" v-model="item.CHECKCONTENT"
											border="none" inputAlign="right"></u--input> -->
										<u--textarea disabled autoHeight v-model="item.CHECKCONTENT" placeholder="检查内容"
											border="surround"></u--textarea>
									</u-form-item>


									<view class="label-title">问题描述</view>
									<u-form-item borderBottom prop="CHECKRESULT_DESCRIPTION">
										<u--textarea disabled autoHeight v-model="item.CHECKRESULT_DESCRIPTION"
											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 borderBottom prop="DEMAND_SHOW">
										<u--textarea disabled autoHeight v-model='item.DEMAND_SHOW'
											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> -->
									<!-- 问题描述 问题等级 整改建议与措施 -->

									<u-form-item label="检查人员" prop="userNameHtml" borderBottom>
										<rich-text disabled disabledColor="#fff" v-html="item.userNameHtml"
											border="none" slot="right"></rich-text>
									</u-form-item>

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


		<view class="bottom-button">
			<button type="primary" class="bottom" v-if='isLoadOK&&tableKey==1' @click="sureCheck">确认</button>
		</view>
	</view>
</template>

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

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

	// import '@/utils/showMsg.js'


	export default {
		data() {
			return {
				isLoadOK: false,
				model: {
					Nav_CheckType: {},
					Nav_CheckTypeLevel: {
						Nav_Enums: {}
					}
				}
			}
		},
		onLoad(option) {
			this.model.ID = option.ID
			this.loadData()
		},
		methods: {
			loadData() {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "CREATE_TIME", 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.Nav_File');
				extendInclude(json, 'Nav_ListCheckUserSign.Nav_ImgFile.Nav_File');
				extendInclude(json, 'Nav_ListSafeCheckDetail.Nav_Files.Nav_ImgFile.Nav_File');
				extendInclude(json, 'Nav_Approve.Nav_ApproveDetails.Nav_ApproveUser');
				extendInclude(json,
					'Nav_ApproveCheckAudit.Nav_ApproveDetails.Nav_ApproveUser.Nav_UserSignFiles.Nav_ImgFile.Nav_File');
				json.IgnoreDataRule = true
				GetCheckAllInfo034View(json).then(res => {
					// console.log('res', res)

					if (res.Nav_ListSafeCheckDetail != null && res.Nav_ListSafeCheckDetail.length >
						0) {

						let CHECKRESULT_DESCRIPTION = ''
						let DEMAND_SHOW = ''
						for (let i = 0; i < res.Nav_ListSafeCheckDetail.length; i++) {
							CHECKRESULT_DESCRIPTION = ''
							DEMAND_SHOW = ''
							if (res.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion != null && res
								.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion.length > 0) {
								for (let j = 0; j < res.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion
									.length; j++) {

									CHECKRESULT_DESCRIPTION += ((CHECKRESULT_DESCRIPTION.length > 0 ? '，' : '') +
										res.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion[j]
										.Nav_Question.DESCREPTION)
									if (res.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion[j]
										.Nav_Question && res.Nav_ListSafeCheckDetail[i]
										.Nav_ListCheckDetailQuestion[j].Nav_Question.DEMAND) {
										DEMAND_SHOW += ((DEMAND_SHOW.length > 0 ? '，' : '') + res
											.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion[j]
											.Nav_Question.DEMAND)
									}
								}
							}
							res.Nav_ListSafeCheckDetail[i].DEMAND_SHOW = DEMAND_SHOW
							res.Nav_ListSafeCheckDetail[i].CHECKRESULT_DESCRIPTION = CHECKRESULT_DESCRIPTION
						}
					}


					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

					let userNameHtml = ''
					if (this.model.Nav_ListSafeCheckDetail != null && this.model.Nav_ListSafeCheckDetail.length >
						0) {

						// let CHECKRESULT_DESCRIPTION = ''
						// let DEMAND_SHOW = ''
						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) {
								userNameHtml = ''
								// debugger
								// this.model.Nav_ListSafeCheckDetail[i].foreach(
								// 	function(item, index) {
								// 		userNameHtml += item.Nav_User.NAME
								// 	})

								// this.model.Nav_ListSafeCheckDetail[i].foreach((item) => {
								// 	userNameHtml += item.Nav_User.NAME
								// })

								for (let j = 0; j < this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser
									.length; j++) {
									if (this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser[j]
										.SAFECHECKSTATE == 80) {
										userNameHtml += '<a style="color:rgba(0, 0, 0, 0.65)"> ' + (j > 0 ?
												"," : "") + this.model.Nav_ListSafeCheckDetail[i]
											.Nav_ListCheckDetailUser[j].Nav_User.NAME + '</a>'
									} else {
										userNameHtml += '<a style="color: red"> ' + (j > 0 ? "," : "") +
											this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailUser[j]
											.Nav_User.NAME + '</a>'
									}
								}
								this.model.Nav_ListSafeCheckDetail[i].userNameHtml = userNameHtml







								// if (this.model.Nav_ListSafeCheckDetail[i].CHECKRESULT == null || this.model
								// 	.Nav_ListSafeCheckDetail[i].CHECKRESULT == 0 || this.model
								// 	.Nav_ListSafeCheckDetail[i].CHECKRESULT == 20) {
								// 	debugger

								// 	// this.model.Nav_ListSafeCheckDetail[i].DEMAND_SHOW = this.model
								// 	// 	.Nav_ListSafeCheckDetail[i].CHECKRESULT_DESCRIPTION
								// 	// this.model.Nav_ListSafeCheckDetail[i].CHECKRESULT_DESCRIPTION = ''

								// 	this.model.Nav_ListSafeCheckDetail[i].DEMAND_SHOW = this.model
								// 		.Nav_ListSafeCheckDetail[i].CHECKRESULT_DESCRIPTION

								// 	this.model.Nav_ListSafeCheckDetail[i].CHECKRESULT_DESCRIPTION = this.model
								// 		.Nav_ListSafeCheckDetail[i].CHECKRESULT_DESCRIPTION

								// } else {
								// 	debugger
								// 	// DEMAND_SHOW
								// 	// CHECKRESULT_DESCRIPTION
								// 	if (this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion !=
								// 		null &&
								// 		this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion.length >
								// 		0) {

								// 		CHECKRESULT_DESCRIPTION = ''
								// 		DEMAND_SHOW = ''
								// 		for (let j = 0; j < this.model.Nav_ListSafeCheckDetail[i]
								// 			.Nav_ListCheckDetailQuestion.length; j++) {

								// 			CHECKRESULT_DESCRIPTION += ((CHECKRESULT_DESCRIPTION.length > 0 ? '，' :
								// 					'') + this.model.Nav_ListSafeCheckDetail[i]
								// 				.Nav_ListCheckDetailQuestion[j].Nav_Question.DESCREPTION)
								// 			if (this.model.Nav_ListSafeCheckDetail[i].Nav_ListCheckDetailQuestion[
								// 					j].Nav_Question) {
								// 				DEMAND_SHOW += ((DEMAND_SHOW.length > 0 ? '，' : '') + this.model
								// 					.Nav_ListSafeCheckDetail[i]
								// 					.Nav_ListCheckDetailQuestion[j].Nav_Question.DEMAND)
								// 			}
								// 		}

								// 		this.model.Nav_ListSafeCheckDetail[i].DEMAND_SHOW = DEMAND_SHOW
								// 		this.model.Nav_ListSafeCheckDetail[i].CHECKRESULT_DESCRIPTION =
								// 			CHECKRESULT_DESCRIPTION

								// 	} else {
								// 		this.model.Nav_ListSafeCheckDetail[i].DEMAND_SHOW = this.model
								// 			.Nav_ListSafeCheckDetail[i].CHECKRESULT_DESCRIPTION
								// 		this.model.Nav_ListSafeCheckDetail[i].CHECKRESULT_DESCRIPTION = ''
								// 	}
								// }
							}
						}

					}

				})
			},
		},
		computed: {

		}
	}
</script>

<style>
	@import url("../../../../style/css/editTemplate.css");
	
	/* .todo-page {
		padding: 16px;
	}

	.todo-page .status-bar {
		height: 120px;
		background-image: linear-gradient(to right, #CFECFF, #6EB6FF);
		position: absolute;
		top: 0;
		left: 0;
		z-index: -10;
	}

	.todo-page .main {
		padding: 62px 8px;
		position: relative;
		z-index: 10;
		background-size: 100% 120px;
		background-repeat: no-repeat;
	}

	.todo-page .swiper-wrap {
		margin-bottom: 16px;
	}

	.tabs-bar {
		display: flex;
		flex-direction: row;
	}

	.tabs-bar .tab {
		display: flex;
		align-items: center;
		position: relative;
		margin-right: 20px;
		padding-bottom: 6px;
	}


	.sub-form-btns {
		padding: 4px 2px;
	}

	.tabs-bar .tab .t {
		position: relative
	}

	.tabs-bar .tab .t .name {
		font-size: 18px;
		line-height: 22px;
		color: #999;
	}

	.tabs-bar .tab .bottom-widget {
		width: 20px;
		height: 3px;
		background-color: #004F9D;
	}

	.content-list {
		padding: 10px 0;
	}

	.content-list .card {
		border-radius: 8px;
		margin-bottom: 12px;
		font-size: 14px;
		overflow: hidden;
		padding: 14px;
		box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.1);
		border: 1px solid rgba(0, 0, 0, 0.1);
	}

	.content-list .card .card-body {
		display: flex;
		flex-direction: row;
	}

	.content-list .card .card-body .left {
		margin-right: 4px;
		width: 20px;
		padding-top: 4px;
	}

	.content-list .card .card-body .left .todo-icon {
		width: 16px;
		height: 16px;
	}

	.content-list .card .card-body .contain {
		flex: 1;
	}

	.content-list .card .card-body .content {
		margin-bottom: 6px;
		display: flex;
		flex-direction: row;
	}

	.content-list .card .card-body .content-text {
		color: #333333;
		line-height: 24px;
		font-weight: bold;
		font-size: 16px;
		flex: 1;
	}

	.content-list .card .card-body .content-bottom {
		display: flex;
		flex-direction: row;
		align-items: flex-end;
	}

	.content-list .card .card-body .date-time {
		flex: 1
	}

	.content-list .card .card-body .content-status {
		width: 56px;
	}

	.content-list .card .card-body .status {
		background: rgba(255, 87, 51, 0.2);
		color: rgba(255, 87, 51, 1);
		text-align: center;
		font-size: 12px;
		width: 56px;
		height: 18px;
		line-height: 18px;
		border-radius: 2px;
	}

	.content-list .card .card-body .status.normal {
		background: rgba(0, 161, 64, 0.2);
		color: rgba(0, 161, 64, 1);
	}

	.content-list .card .card-body .status.warn {
		background: rgba(202, 158, 3, 0.2);
		color: rgba(202, 158, 3, 1);
	}

	.content-list .card .card-body .time {
		font-weight: 400;
		line-height: 18px;
		color: #333333;
		display: flex;
		flex-direction: row;
		margin-top: 4px;
		align-items: center;
	}

	.content-list .card .card-body .time .point {
		width: 8px;
		height: 8px;
		border-radius: 50%;
		margin-right: 4px;
	}

	.content-list .card .card-body .time .point.green {
		background: #00A140;
	}

	.content-list .card .card-body .time .point.red {
		background: #EE0A24;
	}

	.content-list .card .card-body .label {
		color: #666666;
		font-size: 12px;
	}

	.content-list .card .card-body .value {
		font-size: 12px;
	}

	.label-title {
		color: #303133;
		font-size: 15px;
		line-height: 22px;
		padding-top: 8px;
	}

	.bottom-button {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 10px 16px;
		box-sizing: border-box;
		background: #fff;
		z-index: 999;
	} */
</style>