<!--整改责任人 指定落实人-->
<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">
					<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="NAME" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.NAME" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="隐患等级" prop="QUESTION_LEVEL_SHOW" borderBottom>
						<u--input disabled disabledColor="#ffffff" v-model="model.QUESTION_LEVEL_SHOW" 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="DESCREPTION" borderBottom>
										<u--textarea disabled autoHeight v-model="item.DESCREPTION" placeholder="检查问题"
											border="surround"></u--textarea>
									</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="Nav_RiskArea.NAME" borderBottom>
										<u--input disabled disabledColor="#fff" v-model="item.Nav_RiskArea.NAME"
											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>
									<u-form-item label="整改期限" prop="LastDateUserShow" borderBottom>
										<u--input disabled v-model="item.LastDateUserShow" disabledColor="#fff"
											placeholder="请选择整改期限" 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 disabled label="整改实施单位" prop="Nav_DepartmentDeal.NAME" borderBottom>
										<u--input disabledColor="#fff" disabled v-model="item.Nav_DepartmentDeal.NAME"
											border="none" inputAlign="right"></u--input>
									</u-form-item>
									<u-form-item disabled label="整改责任人" prop="Nav_UserDeal.NAME" borderBottom>
										<u--input disabledColor="#fff" v-model="item.Nav_UserDeal.NAME" disabled
											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 required label="整改落实人" required style="margin-left: 8px;"
										prop="Nav_UserActualDeal.NAME" borderBottom
										@click="handleShowSheet({title: '整改落实人', name: 'actualDeal', dataIndex: index})">
										<u--input disabled disabledColor="#fff" v-model="item.Nav_UserActualDeal.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" :title="comPickerInfo.title" :lists="comPickerInfo.dataLists"
			@search="handleShowSheet" @select="onConfirmPicker" @close="comPickerInfo.showSheet=false" />
		<!-- handleSearchUser -->
		<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 {
		GetNoticePerson,
		FullUpdateNoticePerson,
		NoticePersonGet,
		NoticePersonFullUpdate
	} from '../../../../services/apply/subPages/BS/riskSubmit'

	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,
					QUESTION_LEVEL_SHOW: '',
					Nav_ListRiskSubmitContent: [{
						Nav_DepartmentDeal: {
							NAME: ''
						},
						Nav_UserCheck: {
							NAME: ''
						},
						Nav_UserDeal: {
							NAME: ''
						},
						Nav_RiskArea: {
							NAME: ''
						},
						Nav_UserActualDeal: {
							NAME: ''
						},

						LastDateUser: '',
						departmentName: '',
						userChecker: '',
						userDetailer: ''
					}]
				},
				isLoadOK: false,
				lists: [],
				comPickerInfo: {
					showSheet: false,
					columns: [],
					dataLists: [],
					title: '整改落实人选择',
					dataIndex: undefined,
					dataIndex: undefined,
					name: ''
				},
				rules: {
					'Nav_UserActualDeal.NAME': {
						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
			},

			FullCheckUpdate() {
				var index = 0
				var isWarm = false
				this.model.Nav_ListRiskSubmitContent.forEach(e => {
					if (!isWarm) {
						index++
						if (e.ACTUAL_DEAL_USER_ID == null) {
							isWarm = true
							uni.$showErrorInfo('请选择第【' + index + '】项的整改落实人！')
							return
						}
					}
				})
				if (isWarm)
					return

				const ele = this.$refs
				// ele['wForm'].validate().then(res => {
				this.model.TaskID = this.TaskID
				this.model.OPERATETYPE = 20
				this.model.Nav_ListRiskSubmitContent.forEach(e => {
					e.Nav_DepartmentDeal = null
					e.Nav_UserCheck = null
					e.Nav_UserDeal = null
					e.Nav_RiskArea = null
					e.Nav_UserActualDeal = null
				})

				NoticePersonFullUpdate(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_ListRiskSubmitContent")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_RiskArea")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_Files.Nav_ImgFile.Nav_File")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_DepartmentDeal")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_UserDeal")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_UserCheck")
				extendInclude(json, "Nav_ListRiskSubmitContent.Nav_UserActualDeal")
				json.IgnoreDataRule = true

				NoticePersonGet(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])
							if (res.Nav_ListRiskSubmitContent[i].Nav_UserActualDeal == null) {
								res.Nav_ListRiskSubmitContent[i].Nav_UserActualDeal = {
									NAME: ''
								}
							}
						}
					}

					this.model = res
					this.isLoadOK = true
				})
			},

			//下拉数据加载
			async handleShowSheet(p) {
				const orgId = uni.getStorageSync('orgId')
				const json = initFilter(orgId, "", "", 0)
				if (p.name) {
					this.comPickerInfo.showSheet = true
					this.comPickerInfo.dataIndex = p.dataIndex
				} else {
					if (p != null && p.length > 0) {
						extendRule(json, 'NAME', 9, p);
					}
				}
				let dataSelect = []
				OrderPagedUseful(json).then(res => {
					this.comPickerInfo.dataLists = res.map(i => {
						return {
							...i,
							name: i.NAME,
							code: i.CODE
						}
					})
				})
			},
			onConfirmPicker(e) {
				const {
					dataIndex
				} = this.comPickerInfo
				this.model.Nav_ListRiskSubmitContent[dataIndex].Nav_UserActualDeal = e
				this.model.Nav_ListRiskSubmitContent[dataIndex].ACTUAL_DEAL_USER_ID = e.ID
				this.comPickerInfo.showSheet = false
			},

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


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