<template>
	<!-- 检查记录查看 -->

	<view class="page-wrap" v-bind:style="{paddingBottom:paddingBottom+'px'}">
		<view class="card">
			<!-- <view class="todo-page"> -->
			<uni-card margin="0" :is-shadow="true">
				<u--form labelPosition="left" labelWidth="auto" labelAlign="center" :model="model">
					<!-- 安全检查通知 -->
					<u-form-item label="编码" prop="CODE" borderBottom>
						<u--input v-model="model.CODE" border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="延期整改名称" prop="NAME" borderBottom>
						<u--input v-model="model.NAME" border="none" slot="right" inputAlign="right"></u--input>
					</u-form-item>

					<u-form-item label="申请人" prop="Nav_User.NAME" borderBottom>
						<u--input v-model="model.Nav_User.NAME" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>
					<u-form-item label="申请部门" prop="Nav_DepartmentApply.NAME" borderBottom>
						<u--input v-model="model.Nav_DepartmentApply.NAME" border="none" slot="right"
							inputAlign="right"></u--input>
					</u-form-item>

					<u-form-item label="问题等级" prop="QUESTION_LEVEL_SHOW" borderBottom>
						<u--input 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">
					<u--form labelPosition="left" labelWidth="auto" labelAlign="center" errorType="border-bottom"
						ref="sForm">
						<u-collapse :border="false" accordion value="1" :accordion="true">
							<uni-card style="margin-bottom: 16px;" margin="0" spacing="0" :is-shadow="false"
								v-for="(item, index) in model.Nav_ListApplyDetail">
								<u-collapse-item :title="index + 1 + '. ' + item.Nav_SubmitContent.DESCREPTION"
									name="1" :open="true">
									<view class="label-title">检查问题描述</view>
									<u-form-item prop="CHECKCONTENT" borderBottom>
										<u--textarea disabled autoHeight v-model="item.Nav_SubmitContent.DESCREPTION"
											placeholder="检查问题描述" border="surround"></u--textarea>
									</u-form-item>

									<view class="label-title">延期理由</view>
									<u-form-item prop="REASON" borderBottom>
										<u--textarea disabled autoHeight v-model="item.REASON" placeholder="延期理由"
											border="surround"></u--textarea>
									</u-form-item>

									<view class="label-title">临时整改建议与措施</view>
									<u-form-item prop="TEMPDEMAND" borderBottom>
										<u--textarea disabled autoHeight v-model="item.TEMPDEMAND"
											placeholder="临时整改建议与措施" border="surround"></u--textarea>
									</u-form-item>

									<u-form-item label="原整改期限" prop="LastDate" borderBottom>
										<u--input disabled disabledColor="#fff"
											:value="$u.timeFormat(item.LastDate, 'yyyy-mm-dd')" border="none"
											inputAlign="right"></u--input>
									</u-form-item>

									<u-form-item label="延期后整改期限" prop="LastDateApply" borderBottom>
										<u--input disabled disabledColor="#fff"
											:value="$u.timeFormat(item.LastDateApply, 'yyyy-mm-dd')" border="none"
											inputAlign="right"></u--input>
									</u-form-item>

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

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

		<check-action v-if="isLoadOK && tableKey === '1' && isAudit === 'true'" :okApi="okApi" :refuseApi="refuseApi"
			:dataSource="$store.state.auditModel"></check-action>

	</view>
</template>

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

	import {
		GetAll,
		CheckDetail
	} from '../../../../services/apply/subPages/BS/delayApply'


	export default {
		data() {
			return {
				isLoadOK: false,
				TaskID: '',
				paddingBottom: '170',
				model: {
					ID: '',
					TaskID: '',
					Nav_SubmitContent: {
						DESCREPTION: ''
					},
					Nav_DepartmentApply: {
						NAME: ''
					},
					Nav_User: {
						NAME: ''
					}
				},
				ApproveID: '',
				isAudit: false,
				okApi: '',
				refuseApi: '',
				isLoadOK: false,
				isCheck: false
			}
		},
		onLoad(option) {
			this.model.ID = option.ID

			this.model.TaskID = option.taskID
			this.TaskID = option.taskID
			this.tableKey = option.tableKey
			this.isAudit = option.isAudit
			this.ApproveID = option.ApproveID
			this.okApi = option.okApi
			this.refuseApi = option.refuseApi

			this.auditModel = {
				...this.$store.state.auditModel,
				TaskID: this.TaskID
			}

			if (!this.tableKey || this.tableKey != 1)
				this.paddingBottom = 10
			this.loadData()
		},
		methods: {
			loadData() {
				const orgId = uni.getStorageSync('orgId')
				let json = initFilter(orgId);
				extendRule(json, 'ID', 1, this.model.ID);
				extendInclude(json, 'Nav_SubmitContent');
				extendInclude(json, 'Nav_User');
				extendInclude(json, 'Nav_DepartmentApply');
				extendInclude(json, 'Nav_ListApplyDetail.Nav_SubmitContent');
				extendInclude(json,
					'Nav_Approve.Nav_ApproveDetails.Nav_ApproveUser.Nav_UserSignFiles.Nav_ImgFile.Nav_File');

				json.IgnoreDataRule = true
				GetAll(json).then(res => {
					this.model = res
					this.isLoadOK = true
					this.isCheck = (this.tableKey === '1' && !this.isAudit && res.OPERARTETYPE == 40 && res
						.Nav_ListApplyDetail
						.length > 0 && res.Nav_ListApplyDetail[0].CHCEKTIME == null && uni.getStorageSync(
							'appInfo').User.ID ==
						res.Nav_ListApplyDetail[0].Nav_SubmitContent.CHECK_USER_ID) ? true : false

				})
			},

			sureCheck() {
				let detailID = ''
				for (let i = 0; i < this.model.Nav_ListApplyDetail.length; i++) {
					detailID += ',' + this.model.Nav_ListApplyDetail[i].ID
				}

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

		}
	}
</script>

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