<!-- 隐患整改通知确认 -->
<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" :rules="rules"
					ref="wForm" errorType="border-bottom">
					<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" :model="subDataModel"
						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_ListRiskSubmitContent">
								<u-collapse-item :title="index + 1 + '. ' + item.CHECKCONTENT" name="1">

									<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="#fff" 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="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 v-model="item.Nav_Files" :isShowBtn='false'></full-upload>
									<u-form-item label="整改期限" prop="LastDateUserShow" borderBottom>
										<u--input disabled disabledColor="#fff" placeholder="请选择整改期限" border="none"
											:value="$u.timeFormat(item.LastDateUser, 'yyyy-mm-dd')"
											inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item label="系统整改期限" prop="LastDateSystemShow" borderBottom>
										<u--input disabled disabledColor="#fff"
											:value="$u.timeFormat(item.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>
										<rich-text disabled disabledColor="#fff" v-html="item.UserDealNameHtml"
											border="none" slot="right"></rich-text>

									</u-form-item>
									<u-form-item label="验收人" prop="Nav_UserCheck.NAME" borderBottom>
										<rich-text disabled disabledColor="#fff" slot="right"
											v-html="item.UserCheckNameHtml" border="none"></rich-text>
									</u-form-item>
									<u-form-item label="整改落实人" prop="Nav_UserActualDeal.NAME" borderBottom>
										<rich-text disabled disabledColor="#fff" slot="right"
											v-html="item.UserActureNameHtml" border="none"></rich-text>
									</u-form-item>

								</u-collapse-item>
							</uni-card>
						</u-collapse>
					</u--form>
				</view>
			</view>
		</u-sticky>
		<u-modal :show="showDelModalIndex >= 0" @confirm="confirmDel" title="确认删除？"></u-modal>
		<!--		<query-selector :show="showPopup" :lists="userLists" @close="handleClosePopup" @search="handleSearchUser"-->
		<!--		@select="handleSelectedUser" />-->
		<!-- <u-picker :show="comPickerInfo.showSheet" :columns="comPickerInfo.columns" @confirm="onConfirmPicker"@close="closePicker" @cancel="closePicker" keyName="NAME"></u-picker> -->

		<!-- <Button className={styles.agreedUser} type={'primary'} icon={'check'} loading={this.state.isOKLoad}
			onClick={()=> this.sureCheck(riskContentState == 15 ? 10 : 1)} >同意</Button>
		<Button className={styles.rejectedUser} type={'primary'} icon={'close'} loading={this.state.isRejectLoad}
			onClick={()=> this.sureCheck(riskContentState == 15 ? 20 : 2)} >驳回</Button> -->

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

		<view class="bottom-button">
			<!-- 验收人 确认 -->
			<button type="primary" v-if=' (isLoadOK && tableKey === "1"&&isCheckerCheck )'
				@click="handlePass">确认</button>
		</view>

		<!-- <check-no-action v-if='isLoadOK && tableKey === "1" && !isActualDealCheck&&(isCheckerCheck || isDealUserCheck)'
			v-on:chilPass='handlePass' v-on:chilReject='handleReject'></check-no-action> -->

	</view>
</template>

<script>
	import checkNoAction from '@/components/custom/check-no-action.vue'
	import {
		guid,
		initFilter,
		extendRule,
		extendInclude,
		extendGroupRule,
		initFilterGroup,
		extendFilterGroup,
		extendFilterGroupGroupRules,
		ShowDateTime
	} from '../../../../utils/common'

	import {
		GetDetailCheck,
		UserCheckAndSend,
		CheckerCheck,
		UpdateActualDealRecord
	} from '../../../../services/apply/subPages/BS/riskSubmit'

	import '@/utils/getLoginInfo.js'
	// import UButton from '../../../../uni_modules/uview-ui/components/u-button/u-button.vue'

	export default {
		components: {
			checkNoAction
		},
		data() {
			return {
				tableKey: '0',
				TaskID: '',
				paddingBottom: '70',
				isCheckerCheck: true,
				isDealUserCheck: true,
				isActualDealCheck: true,
				riskContentState: 0,
				DEALOPINION: '',
				model: {
					ID: '',
					TaskID: '',
					LastDateUserShow: '',
					LastDateSystemShow: '',
					Nav_User: {
						NAME: '',
						Nav_Department: {
							NAME: '',
						}
					},
					Nav_ListRiskSubmitContent: [{
						CHECKCONTENT_SHOW: '',
						UserDealNameHtml: '',
						UserCheckNameHtml: '',
						UserActureNameHtml: '',
						Nav_DepartmentDeal: {
							NAME: ''
						},
						Nav_UserDeal: {
							NAME: ''
						},
						Nav_UserActualDeal: {
							NAME: ''
						}
					}]


					// Nav_CheckType: {},
					// Nav_CheckTypeLevel: {
					// 	Nav_Enums: {}
					// },
					// Nav_ListSafeCheckDetail: [{
					// 	Nav_CheckArea: {},
					// 	Nav_CheckProject: {},
					// 	checkerNames: '',
					// 	Nav_ListCheckDetailReason: [{}],
					// 	listCheckDetailReason: '',
					// 	CHECKCONTENT: '空',
					// 	Nav_ListCheckDetailQuestion: [{
					// 		Nav_Question: [],
					// 	}],
					// 	listCheckDetailQuestion: '',
					// 	QUESTION_LEVELShow: ''
					// }] //子表
				},
				isAudit: true,
				isLoadOK: false,
				lists: [],
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				// subForms: [{
				// 	title: '检查详情',
				// 	listCheckDetailReason: '',
				// 	// checkContent: '',
				// 	// checkProblem: '',
				// 	// problemLevel: '',
				// 	// riskPosition: ''
				// }],
				subDataModel: {
					Nav_CheckArea: {},
					Nav_CheckProject: {},
					checkerNames: '',
					Nav_ListCheckDetailReason: [{}],
					listCheckDetailReason: '',
					CHECKCONTENT: '空',
					Nav_ListCheckDetailQuestion: [{
						Nav_Question: [],
					}],
					listCheckDetailQuestion: '',
					QUESTION_LEVELShow: ''
				},
				showCheckDate: false,
				showPopup: false,
				showDelModalIndex: undefined,
				rules: {
					'activityTopic': {
						type: 'string',
						required: true,
						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.paddingBottom = 10
			}
			this.loadData()
		},
		methods: {
			// handleOkRow() {
			// 	console.log('ok row')
			// },
			// handleDelRowBefore(index) {
			// 	this.showDelModalIndex = index
			// },
			// confirmDel() {
			// 	this.model.Nav_ListSafeCheckDetail.splice(this.showDelModalIndex, 1)
			// 	this.showDelModalIndex = undefined
			// },
			// handleAdd() {
			// 	this.model.Nav_ListSafeCheckDetail.unshift(this.subDataModel)
			// },
			// 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, 'ISLOGIN', 1, 1)
				json.IgnoreDataRule = true

				GetDetailCheck(json).then(res => {
					if (res.Nav_ListRiskSubmitContent != null && res.Nav_ListRiskSubmitContent.length > 0) {
						var UserDealNameHtml = ''
						var UserCheckNameHtml = ''
						var UserActureNameHtml = ''
						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

							if (!res.Nav_ListRiskSubmitContent[i].ISDEALUSERCHECK) {
								UserDealNameHtml = '<a style="color:red">' + res.Nav_ListRiskSubmitContent[i]
									.Nav_UserDeal.NAME + '</a>'
							} else {
								UserDealNameHtml = res.Nav_ListRiskSubmitContent[i].Nav_UserDeal.NAME
							}

							if (!res.Nav_ListRiskSubmitContent[i].ISCHECKERCHECK && res.OPERATETYPE <= 20) {
								UserCheckNameHtml = '<a style="color:red">' + res.Nav_ListRiskSubmitContent[i]
									.Nav_UserCheck.NAME + '</a>'
							} else {
								UserCheckNameHtml = res.Nav_ListRiskSubmitContent[i].Nav_UserCheck.NAME
							}

							if (res.OPERATETYPE < 30) {
								UserActureNameHtml = '<a style="color:red">' + res.Nav_ListRiskSubmitContent[i]
									.Nav_UserActualDeal.NAME + '</a>'
							} else {
								UserActureNameHtml = res.Nav_ListRiskSubmitContent[i].Nav_UserActualDeal.NAME
							}

							res.Nav_ListRiskSubmitContent[i].UserDealNameHtml = UserDealNameHtml
							res.Nav_ListRiskSubmitContent[i].UserCheckNameHtml = UserCheckNameHtml
							res.Nav_ListRiskSubmitContent[i].UserActureNameHtml = UserActureNameHtml
						}
					}

					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 == 17) ? true : false //CHECK_USER_ID
					if (this.isDealUserCheck)
						this.isDealUserCheck = (loginID == res.Nav_ListRiskSubmitContent[0].DEAL_USER_ID &&
							res.Nav_ListRiskSubmitContent[0].RiskContentState == 15) ? true : false //DEAL_USER_ID
					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
					this.isLoadOK = true

				})
			},


			handlePass(data) {
				this.DEALOPINION = data.opinions
				this.sureCheck(this.riskContentState == 15 ? 1 : 10) //? 10 : 1
			},
			handleReject(data) {
				this.DEALOPINION = data.opinions
				this.sureCheck(this.riskContentState == 15 ? 2 : 20) //? 20 : 2
			},

			// 整改责任人 验收人 同意
			sureCheck(val) {
				const orgId = uni.getStorageSync('orgId')
				if (val == 1 || val == 2) {

					//整改责任人 同意
					// Parameter4 审批结果  1同意 2驳回
					// Parameter3 驳回理由
					if (val == 2 && (this.DEALOPINION == undefined || this.DEALOPINION == null || this.DEALOPINION ==
							'')) {
						uni.$showErrorInfo('请填写驳回意见！')
						return false;
					}

					// let json = initFilter(orgId, this.model.ID, null, null, null, this.TaskID, this.state.rowcount, this.DEALOPINION, val);
					let json = initFilter(orgId, this.model.ID, null, null, null, this.TaskID, null, this.DEALOPINION,
						val);

					UserCheckAndSend(json).then(res => {
						uni.$showMsgFunc('操作成功!', () => {
							// if (this.tableKey == null || this.tableKey == 0) {
							// 	uni.navigateTo({
							// 		url: 'safeCheckIndex'
							// 	})
							// } else {
							uni.navigateBack()
							// }
						}, 'success', 1000)
					})

				} else {
					//验收人 同意
					if (val == 20 && (this.DEALOPINION == undefined || this.DEALOPINION == null || this.DEALOPINION ==
							'')) {
						uni.$showErrorInfo('请填写驳回意见！')
						return false;
					}

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

				}
			},

			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)
				})
			},


		},
		computed: {},
		// onNavigationBarButtonTap(e) {
		// 	this.subForms.push({
		// 		title: '检查详情' + (this.subForms.length + 1),
		// 		Nav_ListCheckDetailReason: '',
		// 	})
		// }
	}
</script>


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

	.btn-wrap {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
		padding: 16px;
		z-index: 1000;
		background: #fff;
		box-shadow: 0 -1px 2px 0 rgba(0, 0, 0, .05);
	}

	.buttons {
		display: flex;
		justify-content: space-between;
	}

	.buttons .first-btn {
		margin-right: 20px;
	}

	/* .page-wrap {
		padding: 16px 16px 72px;
	}

	.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;
	}

	.row-action {
		display: flex;
	}

	.row-action text {
		margin-left: 10px;
	}

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

	.sub-form-btn {
		display: flex;
	}

	.sub-form-btn .icon {
		margin-right: 4px;
	}

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

	.btn-wrap {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
		padding: 16px;
		z-index: 1000;
		background: #fff;
		box-shadow: 0 -1px 2px 0 rgba(0, 0, 0, .05);
	}

	.buttons {
		display: flex;
		justify-content: space-between;
	}

	.buttons .first-btn {
		margin-right: 20px;
	}

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