<!-- 隐患整改通知-->
<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" :rules="rules"
					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="CREATE_TIME" borderBottom>
						<u--input disabled disabledColor="#ffffff" 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="#ffffff" 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="#ffffff" v-model="model.Nav_User.NAME" border="none"
							slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查类型"
						v-if="model.Nav_Submit.SUBMIT_TYPE!=undefined&&model.Nav_Submit.SUBMIT_TYPE!=10"
						prop="Nav_Submit.Nav_CheckType.NAME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.Nav_Submit.Nav_CheckType.NAME"
							border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="检查层级"
						v-if="model.Nav_Submit.SUBMIT_TYPE!=undefined&&model.Nav_Submit.SUBMIT_TYPE!=10"
						prop="Nav_Submit.Nav_CheckTypeLevel.Nav_Enums.NAME" borderBottom>
						<u--input disabled disabledColor="#ffffff"
							v-model="model.Nav_Submit.Nav_CheckTypeLevel.Nav_Enums.NAME" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="驳回信息" v-if="isRefused===true" prop="CHECK_USER_REFUSED_REASON" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.CHECK_USER_REFUSED_REASON"
							border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>

				</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 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="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 :value="item.Nav_Files" :isShowBtn='false'></full-upload>

									<u-form-item label="整改期限" prop="LastDateUserShow" borderBottom>
										<u--input disabled v-model="item.LastDateUserShow" disabledColor="#fff"
											placeholder="请选择整改期限" border="none" inputAlign="right"></u--input>
										<!-- <u-icon style="margin-left: 4px;" slot="right"
														name="arrow-down"></u-icon> -->
									</u-form-item>
									<u-form-item label="系统整改期限" prop="LastDateSystemShow" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.LastDateSystemShow"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item disabled label="整改实施单位" prop="Nav_DepartmentDeal.NAME" borderBottom
										@click="handleShowSheet({title: '整改实施单位', name: 'departmentName', dataIndex: index})">
										<u--input disabledColor="#fff" disabled v-model="item.Nav_DepartmentDeal.NAME"
											border="none" inputAlign="right"></u--input>
										<u-icon style="margin-left: 4px;" slot="right" name="arrow-down"></u-icon>
									</u-form-item>
									<u-form-item disabled label="整改责任人" prop="Nav_UserDeal.NAME" borderBottom
										@click="handleShowSheet({title: '整改责任人', name: 'userDetailer', dataIndex: index})">
										<u--input disabledColor="#fff" v-model="item.Nav_UserDeal.NAME" disabled
											border="none" inputAlign="right"></u--input>
										<u-icon style="margin-left: 4px;" slot="right" name="arrow-down"></u-icon>
									</u-form-item>
									<u-form-item label="验收人" prop="Nav_UserCheck.NAME" borderBottom
										@click="handleShowSheet({title: '验收人', name: 'userChecker', dataIndex: index})">
										<u--input disabled disabledColor="#fff" v-model="item.Nav_UserCheck.NAME"
											border="none" inputAlign="right"></u--input>
										<u-icon style="margin-left: 4px;" slot="right" name="arrow-down"></u-icon>
									</u-form-item>
								</uni-collapse-item>
							</uni-card>
						</uni-collapse>
					</u--form>
				</view>

			</view>
		</u-sticky>


		<!-- <query-selector :show="comPickerInfo.showSheet" :lists="userLists" :defaultValue="currentOperateUser.NAME"
			@close="closePicker" @search="handleSearchUser" @select="onConfirmPicker" /> -->

		<u-picker :show="comPickerInfo.showSheet" :columns="comPickerInfo.columns" @confirm="onConfirmPicker"
			@close="closePicker" @cancel="closePicker" keyName="NAME"></u-picker>

		<u-datetime-picker :show="dateTimePickerInfo.showCheckDate" mode="date"
			v-model='dateTimePickerInfo.defaultDateTime' :formatter="formatter" @confirm="handleCheckDate"
			@close="dateTimePickerInfo.showCheckDate = false;"
			@cancel="dateTimePickerInfo.showCheckDate = false;"></u-datetime-picker>



		<view class="bottom-button">
			<button type="primary" v-if='isLoadOK&&tableKey==1' @click="FullCheckUpdate">提交</button>
		</view>
	</view>
</template>

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

	import {
		// GetBS006,
		// GetSubmitContent,
		// FullUpdateBS006
		GetNoticePerson,
		FullUpdateNoticePerson
	} from '../../../../services/apply/subPages/BS/riskSubmit'

	// import {
	// 	orderPagedRiskReason,
	// } from '../../../../services/apply/subPages/BS/safeCheck'
	// import '@/utils/showMsg.js'
	import {
		data
	} from '../../../../uni_modules/uview-ui/libs/mixin/mixin'

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


	export default {
		data() {
			return {
				tableKey: '0',
				TaskID: '',
				isRefused: false,
				model: {
					ID: '',
					TaskID: '',
					SUBMIT_TYPE: undefined,
					Nav_User: {
						NAME: '',
						Nav_Department: {
							NAME: ''
						}
					},
					Nav_CheckType: {},
					Nav_CheckTypeLevel: {
						Nav_Enums: {}
					},
					Nav_ListRiskSubmitContent: [{
						Nav_Department: {
							NAME: ''
						},
						Nav_UserCheck: {
							NAME: ''
						},
						Nav_UserDeal: {
							NAME: ''
						},

						LastDateUser: '',
						departmentName: '',
						userChecker: '',
						userDetailer: ''
					}]
				},
				isLoadOK: false,
				lists: [],
				comPickerInfo: {
					showSheet: false,
					columns: [],
					title: '',
					dataIndex: undefined,
					formIndex: undefined,
					name: ''
				},
				dateTimePickerInfo: {
					showCheckDate: false,
					dataIndex: undefined,
					defaultDateTime: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd'),
					value: ''
				},

				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
			this.loadData()

		},
		methods: {
			handleTab(t) {
				this.currentTab = t
			},

			//显示时间控件
			showCheckDate(dataIndex) {
				if (this.model.Nav_ListRiskSubmitContent[dataIndex].LastDateUser == null) {
					this.model.Nav_ListRiskSubmitContent[dataIndex].LastDateUser = uni.$u.timeFormat(new Date(),
						'yyyy-mm-dd')
				}

				this.dateTimePickerInfo = {
					showCheckDate: true,
					dataIndex: dataIndex,
					defaultDateTime: this.model.Nav_ListRiskSubmitContent[dataIndex].LastDateUser
				}
			},

			//隐藏控件 显示时间
			handleCheckDate(e) {
				let v = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
				const {
					name,
					dataIndex
				} = this.dateTimePickerInfo
				this.dateTimePickerInfo.showCheckDate = false
				this.model.Nav_ListRiskSubmitContent[dataIndex].LastDateUser = uni.$u.timeFormat(e.value,
					'yyyy-mm-dd')
			},

			FullCheckUpdate() {
				const ele = this.$refs
				ele['wForm'].validate().then(res => {
					this.model.SUBMIT_STATUS = 20
					this.model.TaskID = this.TaskID
					this.model.OPERATETYPE = 20
					// const orgId = uni.getStorageSync('orgId')
					// this.model.Nav_Check = null
					// this.model.Nav_CheckType = null
					// this.model.Nav_CheckTypeLevel = null

					if (!this.model.Nav_ListRiskSubmitContent)
						uni.$showErrorInfo('整改详情不能为空！')

					// for (let i = 0; i < this.model.Nav_ListRiskSubmitContent.length; i++) {
					// 	this.model.Nav_ListRiskSubmitContent[i].Nav_UserCheck = null
					// 	this.model.Nav_ListRiskSubmitContent[i].Nav_UserDeal = null
					// 	this.model.Nav_ListRiskSubmitContent[i].Nav_User = null
					// 	this.model.Nav_ListRiskSubmitContent[i].Nav_Department = null
					// 	this.model.Nav_ListRiskSubmitContent[i].Nav_DepartmentDeal = null
					// 	this.model.Nav_ListRiskSubmitContent[i].Nav_SafeCheckDetail = null
					// 	this.model.Nav_ListRiskSubmitContent[i].Nav_CheckMain = null
					// 	this.model.Nav_ListRiskSubmitContent[i].Nav_Question = null
					// 	if (this.model.Nav_ListRiskSubmitContent[i].Nav_ListRiskQuestionReason == null || this
					// 		.model
					// 		.Nav_ListRiskSubmitContent[i].Nav_ListRiskQuestionReason.length < 1) {
					// 		uni.$showErrorInfo('子表【' + i + '】隐患原因不能为空！')
					// 	}
					// 	for (let j = 0; j < this.model.Nav_ListRiskSubmitContent[i].Nav_ListRiskQuestionReason
					// 		.length; j++) {
					// 		this.model.Nav_ListRiskSubmitContent[i].Nav_ListRiskQuestionReason[j].Nav_RiskReason =
					// 			null;
					// 	}
					// 	this.model.Nav_ListRiskSubmitContent[i].LastDateUser = this.model
					// 		.Nav_ListRiskSubmitContent[i].LastDateUser + ' 23:59:59'
					// 	this.model.Nav_ListRiskSubmitContent[i].ORG_ID = orgId
					// }

					FullUpdateNoticePerson(this.model).then(res => {
						uni.$showMsgFunc('操作成功!', () => {
							if (this.tableKey == null || this.tableKey == 0) {
								uni.navigateTo({
									url: 'safeCheckIndex'
								})
							} else {
								uni.navigateBack()
							}
						}, 'success', 1000)
					})
				}).catch(err => {
					// console.log('校验失败', err)
					uni.$showErrorInfo('校验失败！')
				})
			},

			loadData() {
				var that = this
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "CODE", 1)
				extendRule(json, 'ID', 1, this.model.ID)
				extendInclude(json, "Nav_User")
				extendInclude(json, "Nav_User.Nav_Department")
				extendInclude(json, "Nav_Submit.Nav_CheckType")
				extendInclude(json, "Nav_Submit.Nav_CheckTypeLevel.Nav_Enums")
				extendInclude(json, "Nav_ListRiskSubmitContent")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_CheckProject")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_CheckProjectCategory")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_SafeCheckDetail")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_Files.Nav_ImgFile.Nav_File")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_User")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_Department")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_DepartmentDeal")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_UserDeal")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_UserActualDeal")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_UserCheck")
				json.IgnoreDataRule = true

				GetNoticePerson(json).then(res => {
					if (res.Nav_ListRiskSubmitContent != null && res.Nav_ListRiskSubmitContent.length > 0) {
						for (let i = 0; i < res.Nav_ListRiskSubmitContent.length; i++) {
							res.Nav_ListRiskSubmitContent[i].LastDateUserShow = (res.Nav_ListRiskSubmitContent[i]
								.LastDateUser?.split(' ')[0])
							res.Nav_ListRiskSubmitContent[i].LastDateSystemShow = (res.Nav_ListRiskSubmitContent[i]
								.LastDateSystem?.split(' ')[0])
						}
					}
					this.model = res
					this.isLoadOK = true
				})
			},

			//下拉数据加载
			async handleShowSheet(p) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "", 0)
				let dataSelect = []
				// if (p.name === 'listCheckDetailReason') {
				// 	// extendOrder(json, "NUM", "0")
				// 	// NAME
				// 	dataSelect = await orderPagedRiskReason(json).then(res => {
				// 		return res
				// 	})
				// } else 
				if (p.name === 'departmentName') {
					extendInclude(json, "Nav_User")
					dataSelect = await GetDpartMentNameHeader(json).then(res => {
						return res
					})
				} else if (p.name === 'userDetailer' || p.name === 'userChecker') {
					dataSelect = await OrderPagedUseful(json).then(res => {
						return res
					})
				}

				if (dataSelect.length) {
					this.comPickerInfo = {
						showSheet: true,
						title: p.title,
						name: p.name,
						dataIndex: p.dataIndex,
						columns: [dataSelect]
					}
				} else {
					// 暂无数据
				}
			},
			onConfirmPicker(e) {
				const {
					name,
					dataIndex
				} = this.comPickerInfo

				// if (name == 'listCheckDetailReason') {
				// 	this.model.Nav_ListRiskSubmitContent[dataIndex].listCheckDetailReason = e.value[0].NAME
				// 	let selectReason = e.value[0]
				// 	selectReason.RISK_REASON_ID = selectReason.ID
				// 	selectReason.ID = guid()
				// 	selectReason.CHECK_DETAIL_ID = this.model.Nav_ListRiskSubmitContent[dataIndex].ID;
				// 	if (this.model.Nav_ListRiskSubmitContent[dataIndex].Nav_ListCheckDetailReason ==
				// 		undefined) {
				// 		this.model.Nav_ListRiskSubmitContent[dataIndex].Nav_ListCheckDetailReason = []
				// 		this.model.Nav_ListRiskSubmitContent[dataIndex].Nav_ListCheckDetailReason.push(
				// 			selectReason)
				// 	} else {
				// 		this.model.Nav_ListRiskSubmitContent[dataIndex].Nav_ListCheckDetailReason[0] =
				// 			selectReason
				// 	}
				// } else 
				if (name == 'userChecker') {
					//验收人
					this.model.Nav_ListRiskSubmitContent[dataIndex].Nav_UserCheck = e.value[0]
					this.model.Nav_ListRiskSubmitContent[dataIndex].userChecker = e.value[0].NAME
					this.model.Nav_ListRiskSubmitContent[dataIndex].CHECK_USER_ID = e.value[0].ID
				} else if (name == 'userDetailer') {
					//整改责任人
					this.model.Nav_ListRiskSubmitContent[dataIndex].Nav_UserDeal = e.value[0]
					this.model.Nav_ListRiskSubmitContent[dataIndex].userDetailer = e.value[0].NAME
					this.model.Nav_ListRiskSubmitContent[dataIndex].DEAL_USER_ID = e.value[0].ID
				} else if (name == 'departmentName') {
					//整改实施单位
					this.model.Nav_ListRiskSubmitContent[dataIndex].Nav_DepartmentDeal = e.value[0]
					this.model.Nav_ListRiskSubmitContent[dataIndex].departmentName = e.value[0].NAME
					this.model.Nav_ListRiskSubmitContent[dataIndex].DEAL_DEPARTMENT_ID = e.value[0].ID
				}
				this.comPickerInfo.showSheet = false
			},


			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>