<template>
	<xn-form-container
		:title="formData.id ? '编辑单位信息表' : '增加单位信息表'"
		:width="700"
		:visible="visible"
		:destroy-on-close="true"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-form-item label="单位代码，18位统一社会信用代码：" name="dwdm">
				<a-input v-model:value="formData.dwdm" placeholder="请输入单位代码，18位统一社会信用代码" allow-clear />
			</a-form-item>
			<a-form-item label="统一单位编码，企业性质代码+统一社会信用代码：" name="tydwbm">
				<a-input v-model:value="formData.tydwbm" placeholder="请输入统一单位编码，企业性质代码+统一社会信用代码" allow-clear />
			</a-form-item>
			<a-form-item label="单位名称：" name="dwmc">
				<a-input v-model:value="formData.dwmc" placeholder="请输入单位名称" allow-clear />
			</a-form-item>
			<a-form-item label="单位类型，引用LS/T 1701-2004的表A.1：" name="dwlx">
				<a-input v-model:value="formData.dwlx" placeholder="请输入单位类型，引用LS/T 1701-2004的表A.1" allow-clear />
			</a-form-item>
			<a-form-item label="注册日期，格式：yyyy-MM-dd：" name="zcrq">
				<a-input v-model:value="formData.zcrq" placeholder="请输入注册日期，格式：yyyy-MM-dd" allow-clear />
			</a-form-item>
			<a-form-item label="注册资本，单位：万元：" name="zczb">
				<a-input v-model:value="formData.zczb" placeholder="请输入注册资本，单位：万元" allow-clear />
			</a-form-item>
			<a-form-item label="资产总额，单位：万元，取最近一年财务报告数据，需每年更新：" name="zcze">
				<a-input v-model:value="formData.zcze" placeholder="请输入资产总额，单位：万元，取最近一年财务报告数据，需每年更新" allow-clear />
			</a-form-item>
			<a-form-item label="法定代表人：" name="fddbr">
				<a-input v-model:value="formData.fddbr" placeholder="请输入法定代表人" allow-clear />
			</a-form-item>
			<a-form-item label="法人身份证号：" name="frsfzh">
				<a-input v-model:value="formData.frsfzh" placeholder="请输入法人身份证号" allow-clear />
			</a-form-item>
			<a-form-item label="法人联系方式，国内标准手机号码或固定电话号码：" name="frlxfs">
				<a-input v-model:value="formData.frlxfs" placeholder="请输入法人联系方式，国内标准手机号码或固定电话号码" allow-clear />
			</a-form-item>
			<a-form-item label="企业联系人：" name="qylxr">
				<a-input v-model:value="formData.qylxr" placeholder="请输入企业联系人" allow-clear />
			</a-form-item>
			<a-form-item label="办公电话，国内标准手机号码或固定电话号码：" name="bgdh">
				<a-input v-model:value="formData.bgdh" placeholder="请输入办公电话，国内标准手机号码或固定电话号码" allow-clear />
			</a-form-item>
			<a-form-item label="注册地址：" name="zcdz">
				<a-input v-model:value="formData.zcdz" placeholder="请输入注册地址" allow-clear />
			</a-form-item>
			<a-form-item label="电子邮箱：" name="dzyx">
				<a-input v-model:value="formData.dzyx" placeholder="请输入电子邮箱" allow-clear />
			</a-form-item>
			<a-form-item label="企业官方网站地址：" name="qygfwzdz">
				<a-input v-model:value="formData.qygfwzdz" placeholder="请输入企业官方网站地址" allow-clear />
			</a-form-item>
			<a-form-item label="传真号码，国内标准传真号码：" name="czhm">
				<a-input v-model:value="formData.czhm" placeholder="请输入传真号码，国内标准传真号码" allow-clear />
			</a-form-item>
			<a-form-item label="邮政编码：" name="yzbm">
				<a-input v-model:value="formData.yzbm" placeholder="请输入邮政编码" allow-clear />
			</a-form-item>
			<a-form-item label="行政区划代码，引用GB/T 2260-2007年区划代码：" name="xzqhdm">
				<a-input v-model:value="formData.xzqhdm" placeholder="请输入行政区划代码，引用GB/T 2260-2007年区划代码" allow-clear />
			</a-form-item>
			<a-form-item label="上级单位名称：" name="sjdwmc">
				<a-input v-model:value="formData.sjdwmc" placeholder="请输入上级单位名称" allow-clear />
			</a-form-item>
			<a-form-item label="上级单位代码，18位统一社会信用代码：" name="sjdwdm">
				<a-input v-model:value="formData.sjdwdm" placeholder="请输入上级单位代码，18位统一社会信用代码" allow-clear />
			</a-form-item>
			<a-form-item label="库区数：" name="kqs">
				<a-input v-model:value="formData.kqs" placeholder="请输入库区数" allow-clear />
			</a-form-item>
			<a-form-item label="仓房数：" name="cfs">
				<a-input v-model:value="formData.cfs" placeholder="请输入仓房数" allow-clear />
			</a-form-item>
			<a-form-item label="油罐数：" name="ygs">
				<a-input v-model:value="formData.ygs" placeholder="请输入油罐数" allow-clear />
			</a-form-item>
			<a-form-item label="经度，以度数（十进制）表示：" name="jd">
				<a-input v-model:value="formData.jd" placeholder="请输入经度，以度数（十进制）表示" allow-clear />
			</a-form-item>
			<a-form-item label="纬度，以度数（十进制）表示：" name="wd">
				<a-input v-model:value="formData.wd" placeholder="请输入纬度，以度数（十进制）表示" allow-clear />
			</a-form-item>
			<a-form-item label="单位状态，1:正常，2:退出储备粮承储：" name="dwzt">
				<a-input v-model:value="formData.dwzt" placeholder="请输入单位状态，1:正常，2:退出储备粮承储" allow-clear />
			</a-form-item>
			<a-form-item label="操作标志，i:新增数据，u:更新数据，d:删除数据：" name="czbz">
				<a-input v-model:value="formData.czbz" placeholder="请输入操作标志，i:新增数据，u:更新数据，d:删除数据" allow-clear />
			</a-form-item>
			<a-form-item label="最后更新时间：" name="zhgxsj">
				<a-input v-model:value="formData.zhgxsj" placeholder="请输入最后更新时间" 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="unitInfoForm">
	import { cloneDeep } from 'lodash-es'
	import { required } from '@/utils/formRules'
	import unitInfoApi from '@/api/basic.info/unitInfoApi'
	// 抽屉状态
	const visible = ref(false)
	const emit = defineEmits({ successful: null })
	const formRef = ref()
	// 表单数据
	const formData = ref({})
	const submitLoading = ref(false)

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