<template>
	<!-- 获取整改单信息 -->
	<view class="page-wrap">
		<uni-card margin="0" :is-shadow="true">
			<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model" :rules="rules"
				ref="wForm" errorType="border-bottom">
				<!-- 安全检查通知 -->
				<view v-if='AUDIT_OPINION' class="label-title-red">驳回信息</view>
				<u-form-item v-if='AUDIT_OPINION' borderBottom>
					<u--textarea disabled autoHeight :value="AUDIT_OPINION" placeholder="请输入检查内容"
						border="surround"></u--textarea>
				</u-form-item>

				<u-form-item label="通知单编号" prop="Nav_SubmitNoticePerson.CODE" borderBottom>
					<u--input disabled disabledColor="#fff" v-model="model.Nav_SubmitNoticePerson.CODE" border="none"
						slot="right" inputAlign="right"></u--input>
				</u-form-item>
				<!-- <u-form-item label="检查问题" prop="Nav_SubmitContent.DESCREPTION" borderBottom>
					<u--input disabled v-model="model.Nav_SubmitContent.DESCREPTION" border="none" slot="right"
						inputAlign="right"></u--input>
				</u-form-item> -->

				<view class="label-title">检查问题</view>
				<u-form-item borderBottom>
					<u--textarea disabled disabledColor="#fff" v-model="model.Nav_SubmitContent.DESCREPTION"
						placeholder="请输入活动内容" border="surround" autoHeight></u--textarea>
				</u-form-item>

				<u-form-item label="整改部门" prop="Nav_UserDeal.Nav_Department.NAME" borderBottom>
					<u--input disabled disabledColor="#fff" v-model="model.Nav_UserDeal.Nav_Department.NAME"
						border="none" slot="right" inputAlign="right"></u--input>
				</u-form-item>

				<u-form-item label="整改责任人" prop="Nav_UserDeal.NAME" borderBottom>
					<u--input disabled disabledColor="#fff" v-model="model.Nav_UserDeal.NAME" border="none" slot="right"
						inputAlign="right"></u--input>
				</u-form-item>

				<u-form-item label="验收人" prop="Nav_UserCheck.NAME" borderBottom>
					<u--input disabled disabledColor="#fff" v-model="model.Nav_UserCheck.NAME" border="none"
						slot="right" inputAlign="right"></u--input>
				</u-form-item>

				<u-form-item label="整改落实人" prop="Nav_UserActualDeal.NAME" borderBottom>
					<u--input disabled disabledColor="#fff" v-model="model.Nav_UserActualDeal.NAME" border="none"
						slot="right" inputAlign="right"></u--input>
				</u-form-item>
				<u-form-item label="隐患地点" prop="ADDRESS" borderBottom>
					<u--input disabled disabledColor="#fff" v-model="model.Nav_SubmitContent.ADDRESS" border="none"
						inputAlign="right"></u--input>
				</u-form-item>
				<!-- 	<u-form-item label="整改建议与措施" prop="Nav_SubmitContent.DEMAND" borderBottom>
					<u--input disabled v-model="model.Nav_SubmitContent.DEMAND" border="none" slot="right"
						inputAlign="right"></u--input>
				</u-form-item> -->
				<view class="label-title">整改建议与措施</view>
				<u-form-item borderBottom>
					<u--textarea disabled disabledColor="#fff" v-model="model.Nav_SubmitContent.DEMAND"
						placeholder="整改建议与措施" border="surround" autoHeight></u--textarea>
				</u-form-item>

				<u-form-item label="整改部门" prop="Nav_UserDeal.Nav_Department.NAME" borderBottom>
					<u--input disabled disabledColor="#fff" v-model="model.Nav_UserDeal.Nav_Department.NAME"
						border="none" slot="right" inputAlign="right"></u--input>
				</u-form-item>
				<u-form-item label="整改期限" prop="Nav_SubmitContent.LastDateUser" borderBottom>
					<u--input disabled disabledColor="#fff"
						:value="$u.timeFormat(model.Nav_SubmitContent.LastDateUser, 'yyyy-mm-dd')" border="none"
						slot="right" inputAlign="right"></u--input>
				</u-form-item>

				<w-view-require v-if="tableKey==1" class="label-title" title='整改后情况描述'></w-view-require>
				<view v-else class="label-title">整改后情况描述</view>
				<u-form-item v-if="tableKey==1" borderBottom prop="DEALDESCRIBE">
					<u--textarea v-model="model.DEALDESCRIBE" placeholder="请输入整改后情况描述" border="surround"></u--textarea>
				</u-form-item>
				<u-form-item v-else borderBottom prop="DEALDESCRIBE">
					<u--textarea disabled disabledColor="#fff" v-model="model.DEALDESCRIBE" placeholder="请输入整改后情况描述"
						border="surround" autoHeight></u--textarea>
				</u-form-item>
				<w-view-require v-if="tableKey==1"  class="label-title" title='附件（整改前）'></w-view-require>
				<view v-else class="label-title">附件（整改前）</view>
				<full-upload v-model="model.Nav_Files" :isShowBtn=' tableKey==1? true:false' :listProp='listProp'
					:listPropVal='listPropVal'></full-upload>

				<w-view-require  v-if="tableKey==1" class="label-title" title='附件（整改后）'></w-view-require>
				<view v-else class="label-title">附件（整改后）</view>
				<full-upload v-model="model.Nav_FilesAfter" :isShowBtn=' tableKey==1?true:false' :listProp='listProp2'
					:listPropVal='listPropVal2'></full-upload>

				<view v-if="model.DEALOPINION!=null&&model.DEALOPINION.length>0&&AUDIT_OPINION==''" class="label-title">
					整改责任人意见</view>
				<u-form-item v-if="model.DEALOPINION!=null&&model.DEALOPINION.length>0&&AUDIT_OPINION==''" borderBottom
					prop="DEALOPINION">
					<u--textarea disabled height="auto" v-model="model.DEALOPINION" placeholder="请输入整改后情况描述"
						border="surround"></u--textarea>
				</u-form-item>

				<view v-if="model.CHECKOPINION!=null&&model.CHECKOPINION.length>0" class="label-title">验收人意见</view>
				<u-form-item v-if="model.CHECKOPINION!=null&&model.CHECKOPINION.length>0" borderBottom
					prop="CHECKOPINION">
					<u--textarea disabled height="auto" v-model="model.CHECKOPINION" placeholder="请输入整改后情况描述"
						border="surround"></u--textarea>
				</u-form-item>

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

<script>
	import wViewRequire from '@/components/custom/w-view-require.vue'
	import {
		initFilter,
		extendRule,
		extendInclude
	} from '../../../../utils/common'

	import {
		GetBS044,
		UpdateDealBS044
	} from '../../../../services/apply/subPages/BS/riskSubmit'

	import {
		auditOptionShow
	} from '../../../../services/common'

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

	export default {
		components: {
			wViewRequire
		},
		data() {
			return {
				isLoadOK: false,
				isStateCanDel: false,
				tableKey: '0',
				TaskID: '',
				listProp: ['RISK_SUBMIT_CONTENT_DEAL_ID'],
				listPropVal: [],
				listProp2: ['RISK_SUBMIT_CONTENT_DEAL_ID'],
				listPropVal2: [],
				AUDIT_OPINION: '',
				model: {
					Nav_SubmitNoticePerson: {
						CODE: ''
					},
					Nav_SubmitContent: {
						LastDateUser: '',
						DEMAND: '',
						DESCREPTION: ''
					},
					Nav_UserDeal: {
						NAME: '',
						Nav_Department: {
							NAME: ''
						}
					},
					Nav_UserCheck: {},
					Nav_UserActualDeal: {},
					Nav_Files: [],
					Nav_FilesAfter: []
				},
				rules: {
					'DEALDESCRIBE': {
						type: 'string',
						required: true,
						trigger: ['blur', 'change'],
						message: '整改后情况描述不能为空'
					}
				}
			}
		},
		onLoad(option) {
			this.model.ID = option.ID
			this.model.TaskID = option.taskID
			this.TaskID = option.taskID
			this.tableKey = option.tableKey
			this.loadData()
		},
		methods: {
			loadData() {
				const orgId = uni.getStorageSync('orgId')
				// this.listPropVal.push(orgId)
				this.listPropVal.push(this.model.ID)
				// this.listPropVal2.push(orgId)
				this.listPropVal2.push(this.model.ID)

				const json = initFilter(orgId, "", "CODE", 1)
				extendRule(json, 'ID', 1, this.model.ID)
				extendInclude(json, "Nav_ListCheckUserSign")
				extendInclude(json, "Nav_SubmitNoticePerson")
				extendInclude(json, "Nav_SubmitContent")
				extendInclude(json, "Nav_UserDeal.Nav_Department")
				extendInclude(json, "Nav_UserDeal")
				extendInclude(json, "Nav_UserCheck")
				extendInclude(json, "Nav_UserActualDeal")
				extendInclude(json, "Nav_SubmitContent.Nav_SafeCheckDetail")
				extendInclude(json, "Nav_Files.Nav_ImgFile")
				extendInclude(json, "Nav_FilesAfter.Nav_ImgFile");
				extendInclude(json, "Nav_ListUserSign")
				json.IgnoreDataRule = true
				GetBS044(json).then(res => {
					this.model = res
					if (res.Nav_SubmitContent.RiskContentState == 30 || res.Nav_SubmitContent.RiskContentState ==
						33 || res.Nav_SubmitContent.RiskContentState == 34 ||
						res.Nav_SubmitContent.RiskContentState == 70 || res.DEALSITUATION == 3) {
						this.isStateCanDel = true
					}

					auditOptionShow(this.model.DEALSITUATION, 3, this.model.APPROVE_ID).then(res => {
						this.AUDIT_OPINION = res
					})

					this.isLoadOK = true

				})
			},
			FullCheckUpdate() {
				const ele = this.$refs
				// debugger
				// // let fi1Result = ele['refUpFiles'].dataUpdate(true)
				// // if (fi1Result != undefined && fi1Result === false) {
				// // 	uni.$showErrorInfo('附件上传中，请稍后再试！')
				// // 	return false
				// // }
				// // let fi1Result2 = ele['refUpFilesAfter'].dataUpdate(true)
				// // if (fi1Result2 != undefined && fi1Result2 === false) {
				// // 	uni.$showErrorInfo('附件上传中，请稍后再试！')
				// // 	return false
				// // }

				// return false
				ele['wForm'].validate().then(res => {
					this.model.OPERARTETYPE = 20
					this.model.TaskID = this.TaskID
					this.model.ENDDATE = uni.$u.timeFormat(new Date(), 'yyyy-mm-dd hh:MM:ss')

					UpdateDealBS044(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('校验失败！')
						// }
					)
				}).catch(err => {
					if (err.length > 0) {
						uni.$showErrorInfo(err[0].message)
					} else {
						uni.$showErrorInfo('校验失败！')
					}
				})
			},
		},
		computed: {

		}
	}
</script>

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