<template>
	<view class="container">
		<view class="card">
			<!-- 隐患详情查看 -->
			<app-hidden-view
				:hidden-id="hiddenId"
				@throw-basic-info="info = $event.pd"
			/>
			<!-- 处置审核 -->
			<view class="card">
				<u-form
					ref="formRef"
					label-position="left"
					:model="form"
					:rules="rules"
					label-width="auto"
				>
					<u-form-item label="处置审核" prop="DISPOSITION_AUDIT" required>
						<u-radio-group
							v-model="form.DISPOSITION_AUDIT"
							direction="horizontal"
						>
							<u-radio name="1" label="通过" />
							<u-radio name="2" label="不通过" />
						</u-radio-group>
					</u-form-item>
					<u-line />
					<block v-if="form.DISPOSITION_AUDIT === '1'">
						<u-form-item
							label="临时措施"
							label-position="top"
							prop="TEMPORARY_MEASURES"
							required
						>
							<u-textarea
								v-model="form.TEMPORARY_MEASURES"
								placeholder="请输入临时措施"
								border="none"
								auto-height
							/>
						</u-form-item>
						<u-line />
					</block>
					<block v-if="form.DISPOSITION_AUDIT === '2'">
						<u-form-item
							label="是否更换整改负责人"
							prop="REPLACE_PRINCIPAL"
							required
						>
							<u-radio-group
								v-model="form.REPLACE_PRINCIPAL"
								direction="horizontal"
							>
								<u-radio name="1" label="是" />
								<u-radio name="2" label="否" />
							</u-radio-group>
						</u-form-item>
						<u-line />
						<block v-if="form.REPLACE_PRINCIPAL === '1'">
							<app-department
								:name="form.PRINCIPAL_DEPARTMENT_NAME"
								:id="form.PRINCIPAL_DEPARTMENT_ID"
								:form="form"
								clear-key="PRINCIPAL_NAME,PRINCIPAL_ID"
								prop="PRINCIPAL_DEPARTMENT_NAME"
								label="整改负责人部门"
							/>
							<app-personnel
								:id="form.PRINCIPAL_ID"
								:name="form.PRINCIPAL_NAME"
								:department-id="form.PRINCIPAL_DEPARTMENT_ID"
								prop="PRINCIPAL_NAME"
								label="整改负责人"
							/>
						</block>
					</block>
					<view class="mt-10">
						<u-button
							type="primary"
							shape="circle"
							text="提交"
							:throttle-time="1000"
							@click="fnSubmit"
						/>
					</view>
				</u-form>
			</view>
		</view>
	</view>
</template>

<script>
import AppHiddenView from "@/components/hiddenView/index.vue";
import AppDepartment from "@/components/department/index.vue";
import AppPersonnel from "@/components/personnel/index.vue";
import useFormValidate from "@/utils/useFormValidate";
import { setHiddenSpecialDisposalReviewSubmit } from "../../api";

export default {
	components: { AppHiddenView, AppDepartment, AppPersonnel },

	onLoad(query) {
		this.hiddenId = query.HIDDEN_ID;
		this.hiddenExamineId = query.HIDDENEXAMINE_ID;
	},

	data() {
		return {
			store: this.$store,
			hiddenId: "",
			hiddenExamineId: "",
			form: {
				TEMPORARY_MEASURES: "", // 临时措施
				REPLACE_PRINCIPAL: "", // 是否更换整改负责人
				PRINCIPAL_DEPARTMENT_NAME: "", // 整改负责人部门名称
				PRINCIPAL_DEPARTMENT_ID: "", // 整改负责人部门ID
				PRINCIPAL_NAME: "", // 整改负责人名称
				PRINCIPAL_ID: "", // 整改负责人ID
			},
			// 表单校验规则
			rules: {
				DISPOSITION_AUDIT: {
					type: "string",
					required: true,
					message: "请选择处置审核",
					trigger: ["blur", "change"],
				},
				TEMPORARY_MEASURES: {
					type: "string",
					required: true,
					message: "请输入临时措施",
					trigger: ["blur", "change"],
				},
				REPLACE_PRINCIPAL: {
					type: "string",
					required: true,
					message: "请选择是否更换整改负责人",
					trigger: ["blur", "change"],
				},
				PRINCIPAL_DEPARTMENT_NAME: {
					type: "string",
					required: true,
					message: "请选择整改负责人部门",
					trigger: ["blur", "change"],
				},
				PRINCIPAL_NAME: {
					type: "string",
					required: true,
					message: "请选择整改负责人",
					trigger: ["blur", "change"],
				},
			},
		};
	},

	methods: {
		async fnSubmit() {
			await useFormValidate(this.$refs.formRef);
			await setHiddenSpecialDisposalReviewSubmit({
				loginUserId: userInfo.USER_ID,
				USERNAME: userInfo.NAME,
				HIDDENEXAMINE_ID: hiddenExamineId.value,
				TYPE: form.value.DISPOSITION_AUDIT,
				disposalPlan: form.value.TEMPORARY_MEASURES,
				OLDRECTIFICATIONOR: info.value.RECTIFICATIONOR,
				spare2: form.value.PRINCIPAL_ID,
				spare1: form.value.REPLACE_PRINCIPAL,
				isChange: form.value.REPLACE_PRINCIPAL,
				changeUserDepartment: form.value.PRINCIPAL_DEPARTMENT_ID,
				changeUser: form.value.PRINCIPAL_ID,
			});
			uni.showToast({
				icon: "none",
				title: "提交成功",
			});
			setTimeout(() => {
				uni.navigateBack();
			}, 1000);
		},
	},
};
</script>

<style scoped lang="scss"></style>
