<template>
	<a-drawer
		:title="'人工补单审批'"
		:width="800"
		:visible="visible"
		:destroy-on-close="true"
		:footer-style="{ textAlign: 'right' }"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-card title="预约信息" :bordered="false">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="企业客户：" name="depotGrainName">
							<a-input v-model:value="formData.depotGrainName" disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="出入库：" name="depotBizType">
							<a-input v-model:value="formData.depotBizType" placeholder="请选择出入库:入库/出库" disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="粮食种类：" name="grainGroup">
							<a-input v-model:value="formData.grainGroup" placeholder="请选择出入库:粮食种类" disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="车牌号码：" name="licensePlate">
							<a-input v-model:value="formData.licensePlate" placeholder="请输入车牌号码" allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="后车牌：" name="licensePlateBack">
							<a-input v-model:value="formData.licensePlateBack" placeholder="" disabled allow-clear/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="粮食类型：" name="grainType">
							<a-input v-model:value="formData.grainType" placeholder="" disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="司机姓名：" name="driverName">
							<a-input v-model:value="formData.driverName" placeholder="" allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="司机电话：" name="driverMobile">
							<a-input v-model:value="formData.driverMobile" placeholder="" allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="预约编号：" name="truckBookId">
							<a-input v-model:value="formData.truckBookId" placeholder="" disabled/>
						</a-form-item>
					</a-col>
				</a-row>
			</a-card>
			<a-card title="过磅信息" :bordered="false">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="车牌颜色：" name="plateColor">
							<a-select v-model:value="formData.plateColor" placeholder="请输入车牌颜色" allow-clear :options="plateColorOptions" disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="毛重(公斤)：" name="grossWeight">
							<a-input-number v-model:value="formData.grossWeight" placeholder="请输入毛重" style="width: 100%" @change="putNetWeight"
											allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="过毛时间：" name="grossTime">
							<a-date-picker v-model:value="formData.grossTime" value-format="YYYY-MM-DD HH:mm:ss" show-time placeholder="请选择过毛时间"
										   style="width: 100%" disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="库位：" name="shedName">
							<a-input v-model:value="formData.shedName" placeholder="请选择库位" :options="depotShedOptions" disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="皮重(公斤)：" name="tareWeight">
							<a-input v-model:value="formData.tareWeight" placeholder="请输入皮重" style="width:100%" @change="putNetWeight" allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="过皮时间：" name="tareTime">
							<a-date-picker v-model:value="formData.tareTime" value-format="YYYY-MM-DD HH:mm:ss" show-time placeholder="请选择过皮时间"
										   style="width: 100%" disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="价格(元/吨)：" name="unitPrice">
							<a-input-number v-model:value="formData.unitPrice" placeholder="请输入价格" :min="0.01" style="width:100%"
											allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="净重(公斤)：" name="netWeight">
							<a-input v-model:value="formData.netWeight" placeholder="请输入净重" allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="总价(元)：" name="totalPrice">
							<a-input v-model:value="formData.totalPrice" allow-clear disabled/>
						</a-form-item>
					</a-col>
				</a-row>
			</a-card>
			<a-card title="扦样信息" v-if="formData.depotBizType === '入库'" :bordered="false">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="水份(%)：" name="samplingShuiFen">
							<a-input v-model:value="formData.samplingShuiFen" placeholder="请输入水份" allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="水容重：" name="samplingRongZhong">
							<a-input v-model:value="formData.samplingRongZhong" placeholder="请输入容重" allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="不完善率：" name="samplingQueShao">
							<a-input v-model:value="formData.samplingQueShao" placeholder="请输入不完善率" allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="霉变：" name="samplingMeiBian">
							<a-input v-model:value="formData.samplingMeiBian" placeholder="请输入霉变" allow-clear disabled/>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="杂质：" name="samplingZaZhi">
							<a-input v-model:value="formData.samplingZaZhi" placeholder="请输入杂质" allow-clear disabled/>
						</a-form-item>
					</a-col>
				</a-row>
			</a-card>
		</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 type="primary" @click="onSubmit('审批驳回')" danger style="margin-left: 8px" :loading="submitLoading">审批驳回</a-button>
		</template>
	</a-drawer>
</template>

<script setup name="depotTruckWeighDoubleForm">
import tool from '@/utils/tool'
import {cloneDeep} from 'lodash-es'
import {required, rules} from '@/utils/formRules'
import depotTruckWeighDoubleApi from '@/api/biz/depotTruckWeighDoubleApi'
import depotTruckWeighPlugApi from '@/api/biz/depotTruckWeighPlugApi'
import fileApi from "@/api/dev/fileApi.js";
import dictOptionsApi from "@/api/biz/dictOptionsApi";
// 抽屉状态
const visible = ref(false)
const emit = defineEmits({successful: null})
const formRef = ref()
// 表单数据
const formData = ref({})
const submitLoading = ref(false)
let grossPlateNames = ref([])
const depotShedOptions = ref([])

// 打开抽屉
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 = (bankOpApprovalState) => {
	formRef.value
		.validate()
		.then(() => {
			submitLoading.value = true
			formData.value.bankOpApprovalState = bankOpApprovalState
			const formDataParam = cloneDeep(formData.value)
			depotTruckWeighPlugApi
				.bankOpApproval(formDataParam, true)
				.then(() => {
					onClose()
					emit('successful')
				})
				.finally(() => {
					submitLoading.value = false
				})
		})
}
// 抛出函数
defineExpose({
	onOpen
})
const plateColorOptions = tool.dictList('车牌颜色')
</script>
