<template>
	<xn-form-container
		title="参数设置"
		:width="800"
		:visible="visible"
		:destroy-on-close="true"
		:body-style="{ 'padding-top': '20px' }"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-form-item label="PCR有效时长" name="duration">
				<a-input v-model:value="formData.duration">
					<template #addonAfter>小时</template>
				</a-input>
			</a-form-item>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
		</template>
	</xn-form-container>
</template>

<script setup name="pcrForm">
	import { required, rules } from "@/utils/formRules";
	import washEntranceApi from "@/api/wash/washEntranceApi";
	const visible = ref(false)
	const formRef = ref()
	const emit = defineEmits({ successful: null })
	const submitLoading = ref(false)
	const formData = ref({})
	const formRules = ref({
		duration: [required('请输入有效时长'), rules.integer]
	})

	const onClose = () => {
		formRef.value.resetFields()
		formData.value = {}
		visible.value = false
		submitLoading.value = false
	}
	// 打开抽屉
	const onOpen = (record) => {
		visible.value = true
		washEntranceApi.getPcrModal().then((res) => {
			formData.value.duration = res.pcr
		})
	}

	const onSubmit = () => {
		formRef.value.validate().then(() => {
			submitLoading.value = true
			let params = {
				time: formData.value.duration
			}
			washEntranceApi.savePcrModal(params).then(() => {
				onClose()
				emit('successful')
			}).finally(() => {
				submitLoading.value = false
			})
		})
	}

	// 抛出函数
	defineExpose({
		onOpen
	})

</script>

<style scoped>

</style>
