<template>
	<a-drawer
		:title="'过磅详情'"
		:width="800"
		:visible="visible"
		:destroy-on-close="true"
		:footer-style="{ textAlign: 'right' }"
		placement="left"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-descriptions :column="1" size="middle" bordered class="mb-2">
				<a-descriptions-item label="出入库">{{ formData.depotBizType }}</a-descriptions-item>
				<a-descriptions-item label="粮食种类">{{ formData.grainGroup }}</a-descriptions-item>
				<a-descriptions-item label="粮食类型">{{ formData.grainType }}</a-descriptions-item>
				<a-descriptions-item label="单据分类">{{ formData.billGroup }}</a-descriptions-item>
				<a-descriptions-item label="车牌号码">{{ formData.licensePlate }}</a-descriptions-item>
				<a-descriptions-item label="司机姓名">{{ formData.driverName }}</a-descriptions-item>
				<a-descriptions-item label="司机电话">{{ formData.driverMobile }}</a-descriptions-item>
				<a-descriptions-item label="车牌颜色">{{ formData.plateColor }}</a-descriptions-item>
				<a-descriptions-item label="车次编码">{{ formData.carNumber }}</a-descriptions-item>
				<a-descriptions-item label="过毛时间">{{ formData.grossTime }}</a-descriptions-item>
				<a-descriptions-item label="过皮时间">{{ formData.tareTime }}</a-descriptions-item>
				<a-descriptions-item label="毛重(公斤)">{{ formData.grossWeight }}</a-descriptions-item>
				<a-descriptions-item label="皮重(公斤)">{{ formData.tareWeight }}</a-descriptions-item>
				<a-descriptions-item label="净重(公斤)">{{ formData.netWeight }}</a-descriptions-item>
				<a-descriptions-item label="单价(元/吨)">{{ formData.unitPrice }}</a-descriptions-item>
				<a-descriptions-item label="总价(元)">{{ formData.totalPrice }}</a-descriptions-item>
			</a-descriptions>
			<a-form-item label="过毛图片：" name="licensePlate">
				<a v-if="formData.grossPlateName" :href="formData.grossPlateName" target="_blank"><img :src="formData.grossPlateName" class="record-img"/>&nbsp</a>
				<a v-if="formData.grossLicenseName" :href="formData.grossLicenseName" target="_blank"><img :src="formData.grossLicenseName" class="record-img"/>&nbsp</a>
				<a v-if="formData.grossCaptureHead" :href="formData.grossCaptureHead" target="_blank"><img :src="formData.grossCaptureHead" class="record-img"/>&nbsp</a>
				<a v-if="formData.grossCaptureTail" :href="formData.grossCaptureTail" target="_blank"><img :src="formData.grossCaptureTail" class="record-img"/>&nbsp</a>
				<br><a v-if="formData.grossCaptureWare" :href="formData.grossCaptureWare" target="_blank"><img :src="formData.grossCaptureWare" class="record-img"/>&nbsp</a>
				<a v-if="formData.grossCaptureBody" :href="formData.grossCaptureBody" target="_blank"><img :src="formData.grossCaptureBody" class="record-img"/>&nbsp</a>
				<a v-if="formData.grossCapturePoundRoom" :href="formData.grossCapturePoundRoom" target="_blank"><img :src="formData.grossCapturePoundRoom" class="record-img"/></a>
			</a-form-item>
			<a-form-item label="过皮图片：" name="licensePlate">
				<a v-if="formData.tarePlateName" :href="formData.tarePlateName" target="_blank"><img :src="formData.tarePlateName" class="record-img"/>&nbsp</a>
				<a v-if="formData.tareLicenseName" :href="formData.tareLicenseName" target="_blank"><img :src="formData.tareLicenseName" class="record-img"/>&nbsp</a>
				<a v-if="formData.tareCaptureHead" :href="formData.tareCaptureHead" target="_blank"><img :src="formData.tareCaptureHead" class="record-img"/>&nbsp</a>
				<a v-if="formData.tareCaptureTail" :href="formData.tareCaptureTail" target="_blank"><img :src="formData.tareCaptureTail" class="record-img"/>&nbsp</a>
				<br><a v-if="formData.tareCaptureWare" :href="formData.tareCaptureWare" target="_blank"><img :src="formData.tareCaptureWare" class="record-img"/>&nbsp</a>
				<a v-if="formData.tareCaptureBody" :href="formData.tareCaptureBody" target="_blank"><img :src="formData.tareCaptureBody" class="record-img"/>&nbsp</a>
				<a v-if="formData.tareCapturePoundRoom" :href="formData.tareCapturePoundRoom" target="_blank"><img :src="formData.tareCapturePoundRoom" class="record-img"/></a>
			</a-form-item>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
		</template>
	</a-drawer>
</template>

<style scoped>
.record-img {
	width: 150px;
	height: 150px;
}
</style>
<script setup name="depotTruckWeighDoubleForm">
import tool from '@/utils/tool'
import {cloneDeep} from 'lodash-es'
import {required} from '@/utils/formRules'
import depotTruckWeighDoubleApi from '@/api/biz/depotTruckWeighDoubleApi'
// 抽屉状态
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) {
		depotTruckWeighDoubleApi.depotTruckWeighDoubleDetail({truckBookId: record.truckBookId}).then((data) => {
			formData.value = data
		})
	}
}
// 关闭抽屉
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)
			depotTruckWeighDoubleApi
				.depotTruckWeighDoubleSubmitForm(formDataParam, !formDataParam.id)
				.then(() => {
					onClose()
					emit('successful')
				})
				.finally(() => {
					submitLoading.value = false
				})
		})
}
// 抛出函数
defineExpose({
	onOpen
})
</script>
