<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="biz_price_monitor的id：" name="priceMonitorId">
				<a-input v-model:value="formData.priceMonitorId" placeholder="请输入biz_price_monitor的id" allow-clear />
			</a-form-item>
			<a-form-item label="采集方式 0：移动端；1：PC端；：" name="type">
				<a-input v-model:value="formData.type" placeholder="请输入采集方式 0：移动端；1：PC端；" allow-clear />
			</a-form-item>
			<a-form-item label="biz_user_collect的id；type=0时，是必填项。：" name="userCollectId">
				<a-input
					v-model:value="formData.userCollectId"
					placeholder="请输入biz_user_collect的id；type=0时，是必填项。"
					allow-clear
				/>
			</a-form-item>
			<a-form-item label="是否实地采集 0：否；1：是；type=0时，是必填项。：" name="isSelfPriceMonitor">
				<a-input
					v-model:value="formData.isSelfPriceMonitor"
					placeholder="请输入是否实地采集 0：否；1：是；type=0时，是必填项。"
					allow-clear
				/>
			</a-form-item>
			<a-form-item label="价格采集人：" name="userCollectName">
				<a-input v-model:value="formData.userCollectName" placeholder="请输入价格采集人" allow-clear />
			</a-form-item>
			<a-form-item label="价格采集人联系方式：" name="userCollectPhone">
				<a-input v-model:value="formData.userCollectPhone" placeholder="请输入价格采集人联系方式" allow-clear />
			</a-form-item>
			<a-form-item label="采集时间：" name="userCollectTime">
				<a-input v-model:value="formData.userCollectTime" placeholder="请输入采集时间" allow-clear />
			</a-form-item>
			<a-form-item label="采集时间是否在报送周期内 0：否；1：是；：" name="isInRemindCycle">
				<a-input
					v-model:value="formData.isInRemindCycle"
					placeholder="请输入采集时间是否在报送周期内 0：否；1：是；"
					allow-clear
				/>
			</a-form-item>
			<a-form-item label="状态 0：未审核；1：已审核；：" name="status">
				<a-input v-model:value="formData.status" 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> -->
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button v-if="disabled !== true" type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
		</template>
	</xn-form-container>
</template>

<script setup name="bizGrainPriceCollectForm">
	import { cloneDeep } from 'lodash-es'
	import { required } from '@/utils/formRules'
	import bizGrainPriceCollectApi from '@/api/basic.info/bizGrainPriceCollectApi'
	// 抽屉状态
	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 onOpen = (record, flag) => {
		visible.value = true
		if (record) {
			let recordData = cloneDeep(record)
			formData.value = Object.assign({}, recordData)
		}
		if (flag) {
			disabled.value = flag
		} else {
			disabled.value = false
		}
	}
	// 关闭抽屉
	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)
			bizGrainPriceCollectApi
				.bizGrainPriceCollectSubmitForm(formDataParam, formDataParam.id)
				.then(() => {
					onClose()
					emit('successful')
				})
				.finally(() => {
					submitLoading.value = false
				})
		})
	}
	// 抛出函数
	defineExpose({
		onOpen
	})
</script>
