<template>
	<xn-form-container
		:title="formData.id ? '编辑门禁记录表' : '增加门禁记录表'"
		:width="700"
		v-model:open="open"
		:destroy-on-close="true"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-form-item label="车牌号码：" name="licensePlate">
				<a-input v-model:value="formData.licensePlate" placeholder="请输入车牌号码" allow-clear />
			</a-form-item>
			<a-form-item label="车牌颜色：" name="licensePlateColor">
				<a-input v-model:value="formData.licensePlateColor" placeholder="请输入车牌颜色" allow-clear />
			</a-form-item>
			<a-form-item label="进出时间：" name="inOutTime">
				<a-input v-model:value="formData.inOutTime" placeholder="请输入进出时间" allow-clear />
			</a-form-item>
			<a-form-item label="车牌图片：" name="licensePlatePicture">
				<a-input v-model:value="formData.licensePlatePicture" placeholder="请输入车牌图片" allow-clear />
			</a-form-item>
			<a-form-item label="车图片：" name="carPicture">
				<a-input v-model:value="formData.carPicture" placeholder="请输入车图片" allow-clear />
			</a-form-item>
			<a-form-item label="进出类型  1-进厂  2-出厂：" name="inOutFactory">
				<a-input v-model:value="formData.inOutFactory" placeholder="请输入进出类型  1-进厂  2-出厂" allow-clear />
			</a-form-item>
			<a-form-item label="车辆类型：" name="vehicleType">
				<a-input v-model:value="formData.vehicleType" placeholder="请输入车辆类型" allow-clear />
			</a-form-item>
			<a-form-item label="地磅绑定状态 0-未绑定 1-单次过磅完成 2-一次过磅完成  3-二次过磅完成  4-已结束：" name="bindStatus">
				<a-input v-model:value="formData.bindStatus" placeholder="请输入地磅绑定状态 0-未绑定 1-单次过磅完成 2-一次过磅完成  3-二次过磅完成  4-已结束" allow-clear />
			</a-form-item>
			<a-form-item label="预约ID：" name="appointmentRegisterId">
				<a-input v-model:value="formData.appointmentRegisterId" placeholder="请输入预约ID" allow-clear />
			</a-form-item>
			<a-form-item label="订单id：" name="orderId">
				<a-input v-model:value="formData.orderId" placeholder="请输入订单id" allow-clear />
			</a-form-item>
			<a-form-item label="云端车牌图片：" name="cloudPlateName">
				<a-input v-model:value="formData.cloudPlateName" placeholder="请输入云端车牌图片" allow-clear />
			</a-form-item>
			<a-form-item label="云端车图片：" name="cloudLicenseName">
				<a-input v-model:value="formData.cloudLicenseName" placeholder="请输入云端车图片" allow-clear />
			</a-form-item>
			<a-form-item label="云端抓拍1：" name="cloudCapturePic1">
				<a-input v-model:value="formData.cloudCapturePic1" placeholder="请输入云端抓拍1" allow-clear />
			</a-form-item>
			<a-form-item label="云端抓拍2：" name="cloudCapturePic2">
				<a-input v-model:value="formData.cloudCapturePic2" placeholder="请输入云端抓拍2" allow-clear />
			</a-form-item>
			<a-form-item label="云端抓拍3：" name="cloudCapturePic3">
				<a-input v-model:value="formData.cloudCapturePic3" placeholder="请输入云端抓拍3" allow-clear />
			</a-form-item>
			<a-form-item label="云端抓拍4：" name="cloudCapturePic4">
				<a-input v-model:value="formData.cloudCapturePic4" placeholder="请输入云端抓拍4" allow-clear />
			</a-form-item>
			<a-form-item label="云端抓拍5：" name="cloudCapturePic5">
				<a-input v-model:value="formData.cloudCapturePic5" placeholder="请输入云端抓拍5" allow-clear />
			</a-form-item>
			<a-form-item label="放行形式  1-自动放行  2-人工放行：" name="releaseType">
				<a-input v-model:value="formData.releaseType" placeholder="请输入放行形式  1-自动放行  2-人工放行" allow-clear />
			</a-form-item>
			<a-form-item label="所属设备分类 1-门禁端设备 2-签样区设备：" name="weighbridgeType">
				<a-input v-model:value="formData.weighbridgeType" placeholder="请输入所属设备分类 1-门禁端设备 2-签样区设备" allow-clear />
			</a-form-item>
			<a-form-item label="设备组（1：一组，2：二组）：" name="deviceGroup">
				<a-input v-model:value="formData.deviceGroup" placeholder="请输入设备组（1：一组，2：二组）" allow-clear />
			</a-form-item>
			<a-form-item label="抓拍1：" name="capturePic1">
				<a-input v-model:value="formData.capturePic1" placeholder="请输入抓拍1" allow-clear />
			</a-form-item>
			<a-form-item label="抓拍2：" name="capturePic2">
				<a-input v-model:value="formData.capturePic2" placeholder="请输入抓拍2" allow-clear />
			</a-form-item>
			<a-form-item label="抓拍3：" name="capturePic3">
				<a-input v-model:value="formData.capturePic3" placeholder="请输入抓拍3" allow-clear />
			</a-form-item>
			<a-form-item label="抓拍4：" name="capturePic4">
				<a-input v-model:value="formData.capturePic4" placeholder="请输入抓拍4" allow-clear />
			</a-form-item>
			<a-form-item label="抓拍5：" name="capturePic5">
				<a-input v-model:value="formData.capturePic5" placeholder="请输入抓拍5" allow-clear />
			</a-form-item>
			<a-form-item label="推送状态（0-推送失败 1-推送成功）：" name="pushStatus">
				<a-input v-model:value="formData.pushStatus" placeholder="请输入推送状态（0-推送失败 1-推送成功）" allow-clear />
			</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="bizAccessRecordForm">
	import { cloneDeep } from 'lodash-es'
	import { required } from '@/utils/formRules'
	import bizAccessRecordApi from '@/api/biz/bizAccessRecordApi'
	// 抽屉状态
	const open = ref(false)
	const emit = defineEmits({ successful: null })
	const formRef = ref()
	// 表单数据
	const formData = ref({})
	const submitLoading = ref(false)

	// 打开抽屉
	const onOpen = (record) => {
		open.value = true
		if (record) {
			let recordData = cloneDeep(record)
			formData.value = Object.assign({}, recordData)
		}
	}
	// 关闭抽屉
	const onClose = () => {
		formRef.value.resetFields()
		formData.value = {}
		open.value = false
	}
	// 默认要校验的
	const formRules = {
	}
	// 验证并提交数据
	const onSubmit = () => {
		formRef.value
			.validate()
			.then(() => {
				submitLoading.value = true
				const formDataParam = cloneDeep(formData.value)
				bizAccessRecordApi
					.bizAccessRecordSubmitForm(formDataParam, formDataParam.id)
					.then(() => {
						onClose()
						emit('successful')
					})
					.finally(() => {
						submitLoading.value = false
					})
			})
			.catch(() => {})
	}
	// 抛出函数
	defineExpose({
		onOpen
	})
</script>
