<template>
	<xn-form-container
		:title="'过磅记录详情'"
		:width="1200"
		v-model:open="open"
		:destroy-on-close="true"
		@close="onClose"
	>
		<a-descriptions>
			<a-descriptions-item span="3" label="车次编码">{{ formData.carNumber }}</a-descriptions-item>
			<a-descriptions-item label="车牌号码">{{ formData.licensePlate }}</a-descriptions-item>
			<a-descriptions-item span="2" label="车牌颜色">{{ formData.plateColor }}</a-descriptions-item>
<!--			<a-descriptions-item label="发货单位">{{ formData.shippingCompany }}</a-descriptions-item>
			<a-descriptions-item label="收货单位">{{ formData.receiptCompany }}</a-descriptions-item>
			<a-descriptions-item label="运输单位">{{ formData.transportCompany }}</a-descriptions-item>-->
			<!-- <a-descriptions-item label="运输路线">{{ formData.transportRoute }}</a-descriptions-item> -->
			<a-descriptions-item label="货品名称">{{ formData.goodsName }}</a-descriptions-item>
			<a-descriptions-item label="货品规格">{{ formData.goodsModel }}</a-descriptions-item>
			<a-descriptions-item label="司机姓名">{{ formData.driverName }}</a-descriptions-item>
			<a-descriptions-item label="订单名称">{{ formData.orderName }}</a-descriptions-item>
			<a-descriptions-item label="订单编号">{{ formData.orderNumber }}</a-descriptions-item>
			<a-descriptions-item label="客户名称">{{ formData.customerName }}</a-descriptions-item>
			<a-descriptions-item label="司机电话">{{ formData.driverMobile }}</a-descriptions-item>
<!--			<a-descriptions-item label="过磅人">{{ formData.extKey1 }}</a-descriptions-item>
			<a-descriptions-item label="打印时间">{{ formData.extKey2 }}</a-descriptions-item>-->
		</a-descriptions>
		<a-divider></a-divider>
		<a-descriptions>
			<a-descriptions-item label="毛重"
				><a-tag color="blue">{{ formData.grossWeight }} 吨</a-tag></a-descriptions-item
			>
			<a-descriptions-item label="皮重"
				><a-tag color="orange">{{ formData.tareWeight }} 吨</a-tag></a-descriptions-item
			>
			<a-descriptions-item label="净重"
				><a-tag color="green">{{ formData.netWeight }} 吨</a-tag></a-descriptions-item
			>
		</a-descriptions>
		<a-divider></a-divider>
		<a-descriptions title="过毛">
			<a-descriptions-item label="过磅时间">{{ formData.grossTime }}</a-descriptions-item>
		</a-descriptions>
		<a-space>
			<a-image :width="200" :src="formData.grossPlateName" />
			<a-image :width="200" :src="formData.grossLicenseName" />
		</a-space>
		<a-space style="margin-top: 15px; margin-left: 10px">
			<a-image v-if="formData.grossCaptureHead != null" :width="200" :src="formData.grossCaptureHead" />
			<a-image v-if="formData.grossCaptureTail != null" :width="200" :src="formData.grossCaptureTail" />
			<a-image v-if="formData.grossCaptureBody != null" :width="200" :src="formData.grossCaptureBody" />
		</a-space>
		<a-space style="margin-top: 15px; margin-left: 10px">
			<a-image v-if="formData.grossCaptureWare != null" :width="200" :src="formData.grossCaptureWare" />
			<a-image v-if="formData.grossCapturePoundRoom != null" :width="200" :src="formData.grossCapturePoundRoom" />
		</a-space>
		<a-divider></a-divider>
		<a-descriptions title="过皮" style="margin-top: 15px">
			<a-descriptions-item label="过磅时间">{{ formData.tareTime }}</a-descriptions-item>
		</a-descriptions>
		<a-space>
			<a-image :width="200" :src="formData.tarePlateName" />
			<a-image :width="200" :src="formData.tareLicenseName" />
		</a-space>
		<a-space style="margin-top: 15px; margin-left: 10px">
			<a-image v-if="formData.tareCaptureHead != null" :width="200" :src="formData.tareCaptureHead" />
			<a-image v-if="formData.tareCaptureTail != null" :width="200" :src="formData.tareCaptureTail" />
			<a-image v-if="formData.tareCaptureBody != null" :width="200" :src="formData.tareCaptureBody" />
		</a-space>
		<a-space style="margin-top: 15px; margin-left: 10px">
			<a-image v-if="formData.tareCaptureWare != null" :width="200" :src="formData.tareCaptureWare" />
			<a-image v-if="formData.tareCapturePoundRoom != null" :width="200" :src="formData.tareCapturePoundRoom" />
		</a-space>
		<a-divider></a-divider>
		<a-descriptions title="司机确认" style="margin-top: 15px">
		</a-descriptions>
		<a-space>
			<a-image :width="200" :src="formData.driverSign" />
		</a-space>
		<a-divider></a-divider>
		<a-descriptions title="司机回签" style="margin-top: 15px">
			<a-descriptions-item label="卸货重量"><a-tag color="green">{{ formData.unloadWeight }} 吨</a-tag></a-descriptions-item>
		</a-descriptions>
		<a-space>
			<div v-for="(item,index) in fileList " :key="item.value">
				<a-image :width="200" :src="item.url" />
			</div>

		</a-space>
		<a-divider></a-divider>
		<a-descriptions title="签收审核" style="margin-top: 15px">
		</a-descriptions>
		<a-space>
			<a-image :width="200" :src="formData.auditSign" />
		</a-space>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
		</template>
	</xn-form-container>
</template>

<script setup name="bizRecordForm">
	import tool from '@/utils/tool'
	import { cloneDeep } from 'lodash-es'
	import bizRecordApi from '@/api/biz/bizRecordApi'
	import sysConfig from '@/config/index'

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

	const fileList = ref([])
	// 打开抽屉
	const onOpen = (record) => {
		open.value = true
		tareTypeOptions.value = tool.dictList('TARE_TYPE')
		if (record) {
			/*const param = {
				id: record.id
			}
			bizRecordApi.bizRecordDetail(param).then((data) => {
				formData.value = Object.assign({}, data)
			})*/
			let recordData = cloneDeep(record)
			formData.value = Object.assign({}, recordData)
			fileList.value = []
			if(formData.value.unloadImg!=null){
				for (var i=0;i<formData.value.unloadImg.split(',').length;i++){
					fileList.value.push({
						name: formData.value.unloadName.split(',')[i],
						url:sysConfig.PREVIEW_PATH + formData.value.unloadImg.split(',')[i]
					})
				}
			}
			if(formData.value.grossPlateName.includes("http://218.2.6.74:8065")){
				console.log("str:"+formData.value.grossPlateName.indexOf("preview/"))
				formData.value.grossPlateName = formData.value.grossPlateName.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.grossLicenseName.includes("http://218.2.6.74:8065")){
				formData.value.grossLicenseName = formData.value.grossLicenseName.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.grossCaptureHead.includes("http://218.2.6.74:8065")){
				formData.value.grossCaptureHead = formData.value.grossCaptureHead.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.grossCaptureTail.includes("http://218.2.6.74:8065")){
				formData.value.grossCaptureTail = formData.value.grossCaptureTail.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.grossCaptureBody.includes("http://218.2.6.74:8065")){
				formData.value.grossCaptureBody = formData.value.grossCaptureBody.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.grossCaptureWare.includes("http://218.2.6.74:8065")){
				formData.value.grossCaptureWare = formData.value.grossCaptureWare.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.grossCapturePoundRoom.includes("http://218.2.6.74:8065")){
				formData.value.grossCapturePoundRoom = formData.value.grossCapturePoundRoom.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.tarePlateName.includes("http://218.2.6.74:8065")){
				formData.value.tarePlateName = formData.value.tarePlateName.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.tareLicenseName.includes("http://218.2.6.74:8065")){
				formData.value.tareLicenseName = formData.value.tareLicenseName.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.tareCaptureHead.includes("http://218.2.6.74:8065")){
				formData.value.tareCaptureHead = formData.value.tareCaptureHead.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.tareCaptureTail.includes("http://218.2.6.74:8065")){
				formData.value.tareCaptureTail = formData.value.tareCaptureTail.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.tareCaptureBody.includes("http://218.2.6.74:8065")){
				formData.value.tareCaptureBody = formData.value.tareCaptureBody.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.tareCaptureWare.includes("http://218.2.6.74:8065")){
				formData.value.tareCaptureWare = formData.value.tareCaptureWare.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
			if(formData.value.tareCapturePoundRoom.includes("http://218.2.6.74:8065")){
				formData.value.tareCapturePoundRoom = formData.value.tareCapturePoundRoom.replace("http://218.2.6.74:8065/preview/",sysConfig.PREVIEW_PATH)
			}
		}
	}
	// 关闭抽屉
	const onClose = () => {
		// formRef.value.resetFields()
		formData.value = {}
		open.value = false
	}
	// 抛出函数
	defineExpose({
		onOpen
	})
</script>
