<!-- 指定整改落实人确认-->
<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"> <!-- :rules="rules" -->
					<u-form-item label="编码" prop="CODE" borderBottom>
						<u--input disabled disabledColor="#fff" v-model="model.CODE" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="发起时间" prop="CREATE_TIME" borderBottom>
						<u--input disabled disabledColor="#fff" v-model="model.CREATE_TIME" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="发起部门" prop="Nav_User.Nav_Department.NAME" borderBottom>
						<u--input disabled disabledColor="#fff" v-model="model.Nav_User.Nav_Department.NAME"
							border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="发起人" prop="Nav_User.NAME" borderBottom>
						<u--input disabled disabledColor="#fff" v-model="model.Nav_User.NAME" 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">
					<view class="sub-form-btns">
					</view>
					<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
						ref="sForm">
						<uni-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_ListRiskSubmitContent">
								<uni-collapse-item :title="index + 1 + '. ' + item.CHECKCONTENT" name="1">

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

									<!-- <u-form-item label="检查问题" prop="DESCREPTION" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item.DESCREPTION"
														border="none" inputAlign="right"></u--input>
												</u-form-item> -->

									<u-form-item label="隐患等级" prop="QUESTION_LEVEL_SHOW" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.QUESTION_LEVEL_SHOW"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<!-- <u-form-item label="整改建议与措施" prop="DEMAND" borderBottom>
													<u--input disabled disabledColor="#fff" v-model="item.DEMAND"
														border="none" inputAlign="right"></u--input>
												</u-form-item> -->

									<view class="label-title">整改建议与措施</view>
									<u-form-item borderBottom prop="DEMAND">
										<u--textarea disabled autoHeight v-model="item.DEMAND" placeholder="整改建议与措施"
											border="surround"></u--textarea>
									</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>
									<u-form-item label="备注" prop="REMARK" borderBottom>
										<u--input disabled disabledColor="#fff" placeholder='备注'  border="none" v-model="item.REMARK"
											inputAlign="right"></u--input>
									</u-form-item>

									<u-form-item label="整改期限" prop="LastDateUser" borderBottom>
										<u--input disabled :value="$u.timeFormat(model.LastDateUser, ' yyyy-mm-dd')"
											disabledColor="#fff" placeholder="请选择整改期限" border="none"
											inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="系统整改期限" prop="LastDateSystem" borderBottom>
										<u--input disabled disabledColor="#fff"
											:value="$u.timeFormat(model.LastDateSystem, ' yyyy-mm-dd')" border="none"
											inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="整改实施单位" prop="Nav_DepartmentDeal.NAME" borderBottom>
										<u--input disabled 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 disabled disabledColor="#fff" v-model="item.Nav_UserDeal.NAME"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="验收人" prop="Nav_UserCheck.NAME" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.Nav_UserCheck.NAME"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="整改落实人" prop="Nav_UserActualDeal.NAME" borderBottom>
										<!-- <u--input disabled disabledColor="#fff"
														v-model="item.Nav_UserActualDeal.NAME" border="none"
														inputAlign="right"></u--input> -->
										<rich-text disabled disabledColor="#fff" slot="right"
											v-html='item.UserActualDealNameHtml' border="none"></rich-text>
									</u-form-item>

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

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

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

	import {

		GetDetailCheck,
		UpdateActualDealRecord
	} from '../../../../services/apply/subPages/BS/riskSubmit'


	// import {
	// 	data
	// } from '../../../../uni_modules/uview-ui/libs/mixin/mixin'

	import {
		OrderPagedUseful,
	} from '../../../../services/common'


	export default {
		data() {
			return {
				tableKey: '0',
				TaskID: '',
				isCheckerCheck: true,
				isDealUserCheck: true,
				isActualDealCheck: true,
				RiskContentState: 0,
				index: 1,
				options: [],
				model: {
					ID: '',
					TaskID: '',
					Nav_User: {
						NAME: '',
						Nav_Department: {
							NAME: ''
						}
					},
					Nav_ListRiskSubmitContent: [{
						Nav_UserCheck: {
							NAME: ''
						},
						Nav_UserDeal: {
							NAME: ''
						},
						Nav_DepartmentDeal: {
							NAME: ''
						},
						UserActualDealNameHtml: ''
					}],
				},
				isLoadOK: false,

				// rules: {
				// 	'Nav_UserActualDeal.NAME': {
				// 		type: 'string',
				// 		required: true,
				// 		// message: '请选择整改落实人!',
				// 		trigger: ['blur', 'change']
				// 	}
				// },
			}
		},
		onLoad(option) {
			this.model.ID = option.ID
			this.model.TaskID = option.taskID
			this.TaskID = option.taskID
			this.tableKey = option.tableKey

			if (this.tableKey == undefined || this.tableKey != '1') {
				this.isCheckerCheck = false
				this.isDealUserCheck = false
				this.isActualDealCheck = false
			}

			this.loadData()
		},
		methods: {
			handleTab(t) {
				this.currentTab = t
			},
			loadData() {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "CODE", 1)
				extendRule(json, 'ID', 1, this.model.ID)
				extendRule(json, 'RiskContentState', 1, 32)
				json.IgnoreDataRule = true

				GetDetailCheck(json).then(res => {
					if (res.Nav_ListRiskSubmitContent != null && res.Nav_ListRiskSubmitContent.length > 0) {
						let UserActualDealNameHtml = ''

						if (this.isActualDealCheck && res.Nav_ListRiskSubmitContent[0]
							.ACTUAL_DEAL_USER_ID != null && res.Nav_ListRiskSubmitContent[0].RiskContentState == 32
						) {
							this.isActualDealCheck = (uni.getStorageSync('appInfo').User["ID"] == res
								.Nav_ListRiskSubmitContent[0].ACTUAL_DEAL_USER_ID) ? true : false
						}

						for (let i = 0; i < res.Nav_ListRiskSubmitContent.length; i++) {
							res.Nav_ListRiskSubmitContent[i].CHECKCONTENT_SHOW = (res.Nav_ListRiskSubmitContent[i]
									.ISBACK == 'true' ? '(返)' : '') + res.Nav_ListRiskSubmitContent[i]
								.CHECKCONTENT

							this.riskContentState = res.Nav_ListRiskSubmitContent[i].RiskContentState


							UserActualDealNameHtml = ''
							// {(isActualDealCheck || data.Nav_ListRiskSubmitContent[0].Nav_UserActualDeal != null) ?
							//  (isActualDealCheck ? <td>{<a className={styles.red} > 
							//  {item.Nav_UserActualDeal?.NAME} </a>}</td> : 
							//  <td>{item.Nav_UserActualDeal?.NAME}</td>) : null}
							if (this.isActualDealCheck) {
								UserActualDealNameHtml =
									'<a style="color:red">' + res.Nav_ListRiskSubmitContent[i].Nav_UserActualDeal
									.NAME + '</a>'
							} else {
								UserActualDealNameHtml = res.Nav_ListRiskSubmitContent[i].Nav_UserActualDeal.NAME
							}
							res.Nav_ListRiskSubmitContent[i].UserActualDealNameHtml = UserActualDealNameHtml
						}
					}

					var loginID = uni.getStorageSync('appInfo').User["ID"]
					if (this.isCheckerCheck)
						this.isCheckerCheck = (loginID == res.Nav_ListRiskSubmitContent[0]
							.CHECK_USER_ID &&
							res.Nav_ListRiskSubmitContent[0].RiskContentState == 15) ? true : false
					if (this.isDealUserCheck)
						this.isDealUserCheck = (loginID == res.Nav_ListRiskSubmitContent[0]
							.DEAL_USER_ID &&
							res.Nav_ListRiskSubmitContent[0].RiskContentState == 17) ? true : false

					if (this.isActualDealCheck)
						this.isActualDealCheck = (loginID == res.Nav_ListRiskSubmitContent[0]
							.ACTUAL_DEAL_USER_ID && res.Nav_ListRiskSubmitContent[0].RiskContentState == 32) ?
						true : false
					this.model = res
					if (this.isActualDealCheck && this.tableKey === "1" && this.model.Nav_ListRiskSubmitContent &&
						this.model.Nav_ListRiskSubmitContent.length > 1) {
						//保留一个 
						let ListRiskSubmitContent0 = this.model.Nav_ListRiskSubmitContent[0]
						this.model.Nav_ListRiskSubmitContent = []
						this.model.Nav_ListRiskSubmitContent.push(ListRiskSubmitContent0)
					}

					this.isLoadOK = true

				})
			},

			sureCheckActualDeal() {
				const orgId = uni.getStorageSync('orgId')
				let json = initFilter(orgId, this.model.ID, null, null, null, this.TaskID);
				UpdateActualDealRecord(json).then(res => {
					uni.$showMsgFunc('操作成功!', () => {
						// if (this.tableKey == null || this.tableKey == 0) {
						// 	uni.navigateTo({
						// 		url: 'safeCheckIndex'
						// 	})
						// } else {
						uni.navigateBack()
						// }
					}, 'success', 1000)
				})
			},

			closePicker() {
				this.comPickerInfo = {
					showSheet: false,
					columns: [],
					title: '',
					name: '',
					formIndex: undefined
				}
			},
		},
		computed: {},
		// onNavigationBarButtonTap(e) {
		// 	this.subForms.push({
		// 		title: '检查详情' + (this.subForms.length + 1),
		// 		Nav_ListCheckDetailReason: '',
		// 	})
		// }
	}
</script>


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

	.card {
		margin-bottom: 18px;
	}

	.sub-form {
		margin-bottom: 16px;
	}

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

	.page-wrap>>>.u-upload__button {
		margin-bottom: 0;
	}

	.btnEnable {
		background: #E6E6E6;
		color: #303133;
	}

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