<template>
	<a-drawer
		:title="'车辆详情'"
		:width="900"
		: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-form-item label="详情类型：" name="menuType">
				<a-radio-group
					v-model:value="formData.detailGroup"
					button-style="solid"
					:options="[
						{label:'入库信息',value:'入库信息'},{label:'扦样信息',value:'扦样信息'}
						,{label:'卸货信息',value:'卸货信息'},{label:'过磅信息',value:'过磅信息'},]"
					option-type="button"
				>
				</a-radio-group>
			</a-form-item>
			<a-descriptions :column="1" size="middle" bordered class="mb-2" v-if="formData.detailGroup === '入库信息'">
				<a-descriptions-item label="企业客户">{{ formData.depotWork.depotGrainName }}</a-descriptions-item>
				<a-descriptions-item label="放款状态">{{ formData.depotWork.loanState }}</a-descriptions-item>
				<a-descriptions-item label="放款审批员">{{ formData.depotWork.approvalUserName }}</a-descriptions-item>
				<a-descriptions-item label="放款审批员账号">{{ formData.depotWork.approvalUserAccount }}</a-descriptions-item>
				<a-descriptions-item label="放款单号">{{ formData.depotWork.loanOrderNo }}</a-descriptions-item>
				<a-descriptions-item label="预约编号">{{ formData.depotWork.truckBookId }}</a-descriptions-item>
				<a-descriptions-item label="单据分类">{{ formData.depotWork.billGroup }}</a-descriptions-item>
				<a-descriptions-item label="车牌">{{ formData.depotWork.licensePlate }}</a-descriptions-item>
				<a-descriptions-item label="粮食种类">{{ formData.depotWork.grainGroup }}</a-descriptions-item>
				<a-descriptions-item label="粮食类型">{{ formData.depotWork.grainType }}</a-descriptions-item>
				<a-descriptions-item label="入库价格 (元/吨)">{{ formData.depotWork.dryPrice }}</a-descriptions-item>
				<a-descriptions-item label="入库实际价格 (元/吨)">{{ formData.depotWork.depotPrice }}</a-descriptions-item>
				<a-descriptions-item label="入库重量 (吨)">{{ formData.depotWork.dryTonCount }}</a-descriptions-item>
				<a-descriptions-item label="入库实际重量 (吨)">{{ formData.depotWork.depotTonCount }}</a-descriptions-item>
				<a-descriptions-item label="入库总金额 (元)">{{ formData.depotWork.orderAmount }}</a-descriptions-item>
				<a-descriptions-item label="质量">{{ formData.depotWork.depotQuality }}</a-descriptions-item>
				<a-descriptions-item label="过毛时间">{{ formData.depotWork.grossTime }}</a-descriptions-item>
				<a-descriptions-item label="过皮时间">{{ formData.depotWork.tareTime }}</a-descriptions-item>
				<a-descriptions-item label="毛重 (公斤)">{{ formData.depotWork.grossWeight }}</a-descriptions-item>
				<a-descriptions-item label="皮重 (公斤)">{{ formData.depotWork.tareWeight }}</a-descriptions-item>
				<a-descriptions-item label="潮干比">{{ formData.depotWork.dampRatio }}</a-descriptions-item>
				<a-descriptions-item label="干粮水份 (%)">{{ formData.depotWork.canonRatio }}</a-descriptions-item>
				<a-descriptions-item label="入库时间">{{ formData.depotWork.createTime }}</a-descriptions-item>
				<a-form-item label="计算公式">
					<p>入库价格 = 总价 /  入库重量 </p>
					<p>入库重量 = 潮粮数量 * ( 1 - 潮干比 * ( 潮粮水份 - 干粮水份 )  ) </p>
					<p>实际重量 = ( 毛重 - 皮重 ) / 1000</p>
					<p>实际价格 = 扦样价格</p>
					<p>总价 = 实际重量 * 实际价格</p>
				</a-form-item>
			</a-descriptions>
			<a-descriptions :column="1" size="middle" bordered class="mb-2" v-if="formData.detailGroup === '扦样信息'">
				<a-descriptions-item label="车牌">{{ formData.depotSampling.licensePlate }}</a-descriptions-item>
				<a-descriptions-item label="司机姓名">{{ formData.depotSampling.driverName }}</a-descriptions-item>
				<a-descriptions-item label="水份(%)">{{ formData.depotSampling.samplingShuiFen }}</a-descriptions-item>
				<a-descriptions-item label="容重">{{ formData.depotSampling.samplingRongZhong }}</a-descriptions-item>
				<a-descriptions-item label="不完善率">{{ formData.depotSampling.samplingQueShao }}</a-descriptions-item>
				<a-descriptions-item label="霉变">{{ formData.depotSampling.samplingMeiBian }}</a-descriptions-item>
				<a-descriptions-item label="杂质">{{ formData.depotSampling.samplingZaZhi }}</a-descriptions-item>
				<a-descriptions-item label="价格">{{ formData.depotSampling.samplingPrice }}</a-descriptions-item>
				<a-descriptions-item label="粮食种类">{{ formData.depotSampling.grainGroup }}</a-descriptions-item>
				<a-descriptions-item label="粮食类型">{{ formData.depotSampling.grainType }}</a-descriptions-item>
				<a-descriptions-item label="确认状态">{{ formData.depotSampling.saveState }}</a-descriptions-item>
				<a-descriptions-item label="确认时间">{{ formData.depotSampling.saveTime }}</a-descriptions-item>
				<a-descriptions-item label="扦样状态">{{ formData.depotSampling.samplingType }}</a-descriptions-item>
				<a-descriptions-item label="扦样员">{{ formData.depotSampling.createUserName }}</a-descriptions-item>
				<a-descriptions-item label="扦样员账号">{{ formData.depotSampling.createUserAccount }}</a-descriptions-item>
				<a-descriptions-item label="扦样区图片">
					<a v-if="formData.truckPicInOne" :href="formData.truckPicInOne" target="_blank">
						<img :src="formData.truckPicInOne" alt="avatar" style="max-height: 100px; max-width: 100px"/>
						<p></p></a>
					<a v-if="formData.truckPicInTwo" :href="formData.truckPicInTwo" target="_blank">
						<img :src="formData.truckPicInTwo" alt="avatar" style="max-height: 100px; max-width: 100px"/>
						<p></p></a>
					<a v-if="formData.truckPicOutOne" :href="formData.truckPicOutOne" target="_blank">
						<img :src="formData.truckPicOutOne" alt="avatar" style="max-height: 100px; max-width: 100px"/>
						<p></p></a>
					<a v-if="formData.truckPicOutTwo" :href="formData.truckPicOutTwo" target="_blank">
						<img :src="formData.truckPicOutTwo" alt="avatar" style="max-height: 100px; max-width: 100px"/>
						<p></p></a>
				</a-descriptions-item>
			</a-descriptions>
			<a-descriptions :column="1" size="middle" bordered class="mb-2" v-if="formData.detailGroup === '卸货信息'">
				<a-descriptions-item label="车辆预约编码">{{ formData.depotTruckLade.truckBookId }}</a-descriptions-item>
				<a-descriptions-item label="车牌">{{ formData.depotTruckLade.licensePlate }}</a-descriptions-item>
				<a-descriptions-item label="后车牌">{{ formData.depotTruckLade.licensePlateBack }}</a-descriptions-item>
				<a-descriptions-item label="司机姓名">{{ formData.depotTruckLade.driverName }}</a-descriptions-item>
				<a-descriptions-item label="库位">{{ formData.depotTruckLade.shedName }}</a-descriptions-item>
				<a-descriptions-item label="卸货员(载货拍照)">{{ formData.depotTruckLade.onePicUserName }}</a-descriptions-item>
				<a-descriptions-item label="卸货员账号(载货拍照)">{{ formData.depotTruckLade.onePicUserAccount }}</a-descriptions-item>
				<a-descriptions-item label="卸货员(卸货拍照)">{{ formData.depotTruckLade.onePicUserName }}</a-descriptions-item>
				<a-descriptions-item label="卸货员账号(卸货拍照)">{{ formData.depotTruckLade.twoPicUserAccount }}</a-descriptions-item>
				<a-descriptions-item label="载货拍照时间">{{ formData.depotTruckLade.twoPicTime }}</a-descriptions-item>
				<a-descriptions-item label="载货拍照">
					<a v-if="formData.depotTruckLade.onePicUrl" :href="formData.depotTruckLade.onePicUrl" target="_blank">
						<img :src="formData.depotTruckLade.onePicUrl" alt="avatar" style="max-height: 100px; max-width: 100px"/></a>
				</a-descriptions-item>
				<a-descriptions-item label="卸货拍照时间">{{ formData.depotTruckLade.twoPicTime }}</a-descriptions-item>
				<a-descriptions-item label="卸货拍照">
					<a v-if="formData.depotTruckLade.twoPicUrl" :href="formData.depotTruckLade.twoPicUrl" target="_blank">
						<img :src="formData.depotTruckLade.twoPicUrl" alt="avatar" style="max-height: 100px; max-width: 100px"/></a>
				</a-descriptions-item>
				<a-descriptions-item label="粮食种类">{{ formData.depotTruckLade.grainGroup }}</a-descriptions-item>
				<a-descriptions-item label="粮食类型">{{ formData.depotTruckLade.grainType }}</a-descriptions-item>
			</a-descriptions>
			<a-descriptions :column="1" size="middle" bordered class="mb-2" v-if="formData.detailGroup === '过磅信息'">
				<a-descriptions-item label="出入库">{{ formData.depotTruckWeighDouble.depotBizType }}</a-descriptions-item>
				<a-descriptions-item label="粮食种类">{{ formData.depotTruckWeighDouble.grainGroup }}</a-descriptions-item>
				<a-descriptions-item label="粮食类型">{{ formData.depotTruckWeighDouble.grainType }}</a-descriptions-item>
				<a-descriptions-item label="单据分类">{{ formData.depotTruckWeighDouble.billGroup }}</a-descriptions-item>
				<a-descriptions-item label="车牌号码">{{ formData.depotTruckWeighDouble.licensePlate }}</a-descriptions-item>
				<a-descriptions-item label="司机姓名">{{ formData.depotTruckWeighDouble.driverName }}</a-descriptions-item>
				<a-descriptions-item label="司机电话">{{ formData.depotTruckWeighDouble.driverMobile }}</a-descriptions-item>
				<a-descriptions-item label="车牌颜色">{{ formData.depotTruckWeighDouble.plateColor }}</a-descriptions-item>
				<a-descriptions-item label="车次编码">{{ formData.depotTruckWeighDouble.carNumber }}</a-descriptions-item>
				<a-descriptions-item label="过毛时间">{{ formData.depotTruckWeighDouble.grossTime }}</a-descriptions-item>
				<a-descriptions-item label="过皮时间">{{ formData.depotTruckWeighDouble.tareTime }}</a-descriptions-item>
				<a-descriptions-item label="毛重(公斤)">{{ formData.depotTruckWeighDouble.grossWeight }}</a-descriptions-item>
				<a-descriptions-item label="皮重(公斤)">{{ formData.depotTruckWeighDouble.tareWeight }}</a-descriptions-item>
				<a-descriptions-item label="净重(公斤)">{{ formData.depotTruckWeighDouble.netWeight }}</a-descriptions-item>
				<a-descriptions-item label="单价(元/吨)">{{ formData.depotTruckWeighDouble.unitPrice }}</a-descriptions-item>
				<a-descriptions-item label="总价(元)">{{ formData.depotTruckWeighDouble.totalPrice }}</a-descriptions-item>
				<a-form-item label="过毛图片：" name="licensePlate">
					<a v-if="formData.depotTruckWeighDouble.grossPlateName" :href="formData.depotTruckWeighDouble.grossPlateName" target="_blank"><img
						:src="formData.depotTruckWeighDouble.grossPlateName" class="record-img"/>&nbsp</a>
					<a v-if="formData.depotTruckWeighDouble.grossLicenseName" :href="formData.depotTruckWeighDouble.grossLicenseName" target="_blank"><img
						:src="formData.depotTruckWeighDouble.grossLicenseName"
						class="record-img"/>&nbsp</a>
					<a v-if="formData.depotTruckWeighDouble.grossCaptureHead" :href="formData.depotTruckWeighDouble.grossCaptureHead" target="_blank"><img
						:src="formData.depotTruckWeighDouble.grossCaptureHead"
						class="record-img"/>&nbsp</a>
					<a v-if="formData.depotTruckWeighDouble.grossCaptureTail" :href="formData.depotTruckWeighDouble.grossCaptureTail" target="_blank"><img
						:src="formData.depotTruckWeighDouble.grossCaptureTail"
						class="record-img"/>&nbsp</a>
					<br><a v-if="formData.depotTruckWeighDouble.grossCaptureWare" :href="formData.depotTruckWeighDouble.grossCaptureWare" target="_blank"><img
					:src="formData.depotTruckWeighDouble.grossCaptureWare"
					class="record-img"/>&nbsp</a>
					<a v-if="formData.depotTruckWeighDouble.grossCaptureBody" :href="formData.depotTruckWeighDouble.grossCaptureBody" target="_blank"><img
						:src="formData.depotTruckWeighDouble.grossCaptureBody"
						class="record-img"/>&nbsp</a>
					<a v-if="formData.depotTruckWeighDouble.grossCapturePoundRoom" :href="formData.depotTruckWeighDouble.grossCapturePoundRoom" target="_blank"><img
						:src="formData.depotTruckWeighDouble.grossCapturePoundRoom"
						class="record-img"/></a>
				</a-form-item>
				<a-form-item label="过皮图片：" name="licensePlate">
					<a v-if="formData.depotTruckWeighDouble.tarePlateName" :href="formData.depotTruckWeighDouble.tarePlateName" target="_blank"><img
						:src="formData.depotTruckWeighDouble.tarePlateName" class="record-img"/>&nbsp</a>
					<a v-if="formData.depotTruckWeighDouble.tareLicenseName" :href="formData.depotTruckWeighDouble.tareLicenseName" target="_blank"><img
						:src="formData.depotTruckWeighDouble.tareLicenseName"
						class="record-img"/>&nbsp</a>
					<a v-if="formData.depotTruckWeighDouble.tareCaptureHead" :href="formData.depotTruckWeighDouble.tareCaptureHead" target="_blank"><img
						:src="formData.depotTruckWeighDouble.tareCaptureHead"
						class="record-img"/>&nbsp</a>
					<a v-if="formData.depotTruckWeighDouble.tareCaptureTail" :href="formData.depotTruckWeighDouble.tareCaptureTail" target="_blank"><img
						:src="formData.depotTruckWeighDouble.tareCaptureTail"
						class="record-img"/>&nbsp</a>
					<br><a v-if="formData.depotTruckWeighDouble.tareCaptureWare" :href="formData.depotTruckWeighDouble.tareCaptureWare" target="_blank"><img
					:src="formData.depotTruckWeighDouble.tareCaptureWare"
					class="record-img"/>&nbsp</a>
					<a v-if="formData.depotTruckWeighDouble.tareCaptureBody" :href="formData.depotTruckWeighDouble.tareCaptureBody" target="_blank"><img
						:src="formData.depotTruckWeighDouble.tareCaptureBody"
						class="record-img"/>&nbsp</a>
					<a v-if="formData.depotTruckWeighDouble.tareCapturePoundRoom" :href="formData.depotTruckWeighDouble.tareCapturePoundRoom"
					   target="_blank"><img :src="formData.depotTruckWeighDouble.tareCapturePoundRoom"
											class="record-img"/></a>
				</a-form-item>
			</a-descriptions>
		</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="depotLoanOrderForm">
import {message} from 'ant-design-vue'
import tool from '@/utils/tool'
import {cloneDeep} from 'lodash-es'
import {required, rules} from '@/utils/formRules'
import depotWorkApi from '@/api/biz/depotWorkApi'
import sysConfig from "@/config";
import depotLoanOrderApi from "@/api/biz/depotLoanOrderApi";

// 抽屉状态
const visible = ref(false)
const emit = defineEmits({successful: null})
const formRef = ref()
// 表单数据
const formData = ref({})
const submitLoading = ref(false)

const tableData = ref([])

// 打开抽屉
const onOpen = (record) => {
	visible.value = true
	if (record) {
		depotLoanOrderApi.depotLoanOrderDetailGroup({truckBookId: record.truckBookId}).then((data) => {
			formData.value = data
			formData.value.detailGroup = '入库信息'
		})
	}
}
// 关闭抽屉
const onClose = () => {
	formRef.value.resetFields()
	formData.value = {}
	visible.value = false
}
// 默认要校验的
const formRules = {}
// 抛出函数
defineExpose({
	onOpen
})
</script>
