基本完成,修复细节
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
title="新增运送清单"
|
||||
:title="formData.editId ? '编辑运送清单' : '新增运送清单'"
|
||||
width="800px"
|
||||
:close-on-click-modal="false"
|
||||
@close="handleClose"
|
||||
@@ -75,12 +75,12 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="司机姓名" prop="driverName">
|
||||
<el-select v-model="formData.driverName" placeholder="请选择司机" clearable filterable style="width: 100%" @change="handleDriverChange">
|
||||
<el-form-item label="司机姓名" prop="driverId">
|
||||
<el-select v-model="formData.driverId" placeholder="请选择司机" clearable filterable style="width: 100%" @change="handleDriverChange">
|
||||
<el-option
|
||||
v-for="item in driverOptions"
|
||||
:key="item.id"
|
||||
:label="item.username"
|
||||
:label="item.username + (item.mobile ? ' - ' + item.mobile : '')"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
@@ -559,7 +559,7 @@
|
||||
v-model="formData.remark"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
maxlength="500"
|
||||
maxlength="500"
|
||||
show-word-limit
|
||||
placeholder="请输入备注信息(可选)"
|
||||
/>
|
||||
@@ -648,10 +648,12 @@ const showStartLocationMap = ref(false);
|
||||
const showEndLocationMap = ref(false);
|
||||
|
||||
const formData = reactive({
|
||||
editId: null, // 编辑时的运单ID
|
||||
orderId: null,
|
||||
shipper: null,
|
||||
buyer: null,
|
||||
plateNumber: null,
|
||||
driverId: null, // 司机ID(后端用)
|
||||
driverName: null,
|
||||
driverPhone: '',
|
||||
serverId: null, // Integer(设备表主键ID)
|
||||
@@ -737,7 +739,7 @@ const rules = {
|
||||
shipper: [{ required: true, message: '请选择发货方', trigger: 'change' }],
|
||||
buyer: [{ required: true, message: '请选择采购方', trigger: 'change' }],
|
||||
plateNumber: [{ required: true, message: '请选择车牌号', trigger: 'change' }],
|
||||
driverName: [{ required: true, message: '请输入司机姓名', trigger: 'blur' }],
|
||||
driverId: [{ required: true, message: '请选择司机', trigger: 'change' }],
|
||||
driverPhone: [{ required: true, validator: validatePhone, trigger: 'blur' }],
|
||||
estimatedDepartureTime: [{ required: true, message: '请选择预计出发时间', trigger: 'change' }],
|
||||
estimatedArrivalTime: [{ required: true, validator: validateArrivalTime, trigger: 'change' }],
|
||||
@@ -771,32 +773,20 @@ const collarDevices = computed(() => {
|
||||
|
||||
// 完善提交数据 - 只提交DeliveryCreateDto需要的字段
|
||||
const buildSubmitData = () => {
|
||||
// 将发货方和采购方的ID转换为名称
|
||||
let shipperName = '';
|
||||
let buyerName = '';
|
||||
|
||||
if (formData.shipper) {
|
||||
const shipper = supplierList.value.find(item => item.id === formData.shipper);
|
||||
shipperName = shipper ? (shipper.username || shipper.mobile || shipper.name || '') : String(formData.shipper);
|
||||
}
|
||||
|
||||
if (formData.buyer) {
|
||||
const buyer = buyerList.value.find(item => item.id === formData.buyer);
|
||||
buyerName = buyer ? (buyer.username || buyer.mobile || buyer.name || '') : String(formData.buyer);
|
||||
}
|
||||
|
||||
// 将司机ID转换为名称
|
||||
// 将司机ID转换为姓名
|
||||
let driverNameStr = '';
|
||||
if (formData.driverName) {
|
||||
const driver = driverOptions.value.find(item => item.id === formData.driverName);
|
||||
driverNameStr = driver ? (driver.name || driver.mobile || driver.username || '') : String(formData.driverName);
|
||||
if (formData.driverId) {
|
||||
const driver = driverOptions.value.find(item => item.id === formData.driverId);
|
||||
// 使用username作为司机姓名(不要使用mobile)
|
||||
driverNameStr = driver ? (driver.username || '') : '';
|
||||
}
|
||||
|
||||
const data = {
|
||||
// 基本信息
|
||||
shipper: shipperName,
|
||||
buyer: buyerName,
|
||||
shipperId: formData.shipper,
|
||||
buyerId: formData.buyer,
|
||||
plateNumber: formData.plateNumber,
|
||||
driverId: formData.driverId, // 传递司机ID给后端
|
||||
driverName: driverNameStr,
|
||||
driverPhone: formData.driverPhone,
|
||||
|
||||
@@ -871,14 +861,119 @@ const buildSubmitData = () => {
|
||||
return data;
|
||||
};
|
||||
|
||||
// 打开弹窗
|
||||
const open = () => {
|
||||
// 打开弹窗(支持编辑模式)
|
||||
const open = async (editData = null) => {
|
||||
dialogVisible.value = true;
|
||||
loadSupplierAndBuyerList();
|
||||
loadDeviceOptions();
|
||||
loadDriverList();
|
||||
loadVehicleList();
|
||||
loadOrderList();
|
||||
|
||||
// 并行加载所有下拉列表数据
|
||||
await Promise.all([
|
||||
loadSupplierAndBuyerList(),
|
||||
loadDeviceOptions(),
|
||||
loadDriverList(),
|
||||
loadVehicleList(),
|
||||
loadOrderList()
|
||||
]);
|
||||
|
||||
console.log('[OPEN-DIALOG] 所有下拉列表加载完成');
|
||||
console.log('[OPEN-DIALOG] 车辆列表:', vehicleOptions.value);
|
||||
|
||||
// 如果传入了编辑数据,则填充表单
|
||||
if (editData) {
|
||||
fillFormWithEditData(editData);
|
||||
}
|
||||
};
|
||||
|
||||
// 填充编辑数据到表单
|
||||
const fillFormWithEditData = (editData) => {
|
||||
console.log('[EDIT-FILL] 开始填充编辑数据:', editData);
|
||||
|
||||
// editData 包含两个部分:
|
||||
// 1. editData.delivery - 运单基本信息
|
||||
// 2. editData 的根级字段 - supplierId, buyerId, eartagIds, collarIds, serverIds
|
||||
|
||||
const delivery = editData.delivery || editData; // 兼容两种数据结构
|
||||
|
||||
// 基本信息
|
||||
formData.orderId = delivery.orderId || null;
|
||||
|
||||
// 发货方和采购方:优先使用根级的 supplierId 和 buyerId
|
||||
formData.shipper = editData.supplierId || (delivery.supplierId ? parseInt(delivery.supplierId) : null);
|
||||
formData.buyer = editData.buyerId || delivery.buyerId || null;
|
||||
console.log('[EDIT-FILL] 发货方ID:', formData.shipper, '采购方ID:', formData.buyer);
|
||||
|
||||
// 车牌号
|
||||
formData.plateNumber = delivery.licensePlate || '';
|
||||
console.log('[EDIT-FILL] 车牌号:', formData.plateNumber);
|
||||
console.log('[EDIT-FILL] 当前车辆列表:', vehicleOptions.value);
|
||||
|
||||
// 检查车牌号是否在车辆列表中
|
||||
const vehicleExists = vehicleOptions.value.find(v => v.licensePlate === formData.plateNumber);
|
||||
if (!vehicleExists && formData.plateNumber) {
|
||||
console.warn('[EDIT-FILL] ⚠️ 车牌号在车辆列表中不存在:', formData.plateNumber);
|
||||
}
|
||||
|
||||
formData.driverId = delivery.driverId || null;
|
||||
formData.driverPhone = delivery.driverMobile || '';
|
||||
|
||||
// 设备信息:从根级读取
|
||||
if (editData.serverIds && editData.serverIds !== '') {
|
||||
formData.serverId = editData.serverIds;
|
||||
console.log('[EDIT-FILL] 主机ID:', formData.serverId);
|
||||
}
|
||||
|
||||
if (editData.eartagIds && Array.isArray(editData.eartagIds) && editData.eartagIds.length > 0) {
|
||||
formData.eartagIds = editData.eartagIds;
|
||||
console.log('[EDIT-FILL] 耳标IDs:', formData.eartagIds);
|
||||
}
|
||||
|
||||
if (editData.collarIds && Array.isArray(editData.collarIds) && editData.collarIds.length > 0) {
|
||||
formData.collarIds = editData.collarIds;
|
||||
console.log('[EDIT-FILL] 项圈IDs:', formData.collarIds);
|
||||
}
|
||||
|
||||
// 地址和坐标
|
||||
formData.startLocation = delivery.startLocation || '';
|
||||
formData.startLat = delivery.startLat || '';
|
||||
formData.startLon = delivery.startLon || '';
|
||||
formData.endLocation = delivery.endLocation || '';
|
||||
formData.endLat = delivery.endLat || '';
|
||||
formData.endLon = delivery.endLon || '';
|
||||
|
||||
// 时间(需要处理)
|
||||
// estimatedDeliveryTime 对应 estimatedArrivalTime
|
||||
if (delivery.estimatedDeliveryTime) {
|
||||
formData.estimatedArrivalTime = delivery.estimatedDeliveryTime;
|
||||
}
|
||||
|
||||
// 重量信息
|
||||
formData.emptyWeight = delivery.emptyWeight || null;
|
||||
formData.entruckWeight = delivery.entruckWeight || null;
|
||||
formData.landingEntruckWeight = delivery.landingEntruckWeight || null;
|
||||
|
||||
// 照片
|
||||
formData.quarantineTickeyUrl = delivery.quarantineTickeyUrl || '';
|
||||
formData.poundListImg = delivery.poundListImg || '';
|
||||
formData.emptyVehicleFrontPhoto = delivery.emptyVehicleFrontPhoto || '';
|
||||
formData.loadedVehicleFrontPhoto = delivery.loadedVehicleFrontPhoto || '';
|
||||
formData.loadedVehicleWeightPhoto = delivery.loadedVehicleWeightPhoto || '';
|
||||
formData.driverIdCardPhoto = delivery.driverIdCardPhoto || '';
|
||||
formData.destinationPoundListImg = delivery.destinationPoundListImg || '';
|
||||
formData.destinationVehicleFrontPhoto = delivery.destinationVehicleFrontPhoto || '';
|
||||
|
||||
// 视频
|
||||
formData.entruckWeightVideo = delivery.entruckWeightVideo || '';
|
||||
formData.emptyWeightVideo = delivery.emptyWeightVideo || '';
|
||||
formData.cattleLoadingVideo = delivery.cattleLoadingVideo || '';
|
||||
formData.controlSlotVideo = delivery.controlSlotVideo || '';
|
||||
formData.cattleLoadingCircleVideo = delivery.cattleLoadingCircleVideo || '';
|
||||
formData.unloadCattleVideo = delivery.unloadCattleVideo || '';
|
||||
formData.destinationWeightVideo = delivery.destinationWeightVideo || '';
|
||||
|
||||
// 保存编辑的ID,用于区分是新增还是编辑
|
||||
formData.editId = delivery.id;
|
||||
|
||||
console.log('[EDIT-FILL] 表单数据已填充:', formData);
|
||||
ElMessage.success('已加载运单数据');
|
||||
};
|
||||
|
||||
// 加载供应商和采购方列表
|
||||
@@ -1014,6 +1109,8 @@ const handleOrderChange = async (orderId) => {
|
||||
formData.shipper = sellerId ? parseInt(sellerId) : null;
|
||||
formData.buyer = buyerId ? parseInt(buyerId) : null;
|
||||
|
||||
console.log('[订单选择] 选中的订单ID:', orderId);
|
||||
console.log('[订单选择] orderId已保存到formData.orderId:', formData.orderId);
|
||||
ElMessage.success('已自动填充发货方和采购方信息');
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -1027,12 +1124,19 @@ const handleOrderChange = async (orderId) => {
|
||||
// 司机选择变化时自动填充电话
|
||||
const handleDriverChange = (driverId) => {
|
||||
if (driverId) {
|
||||
formData.driverId = driverId; // 保存司机ID用于后端查询
|
||||
const driver = driverOptions.value.find(item => item.id === driverId);
|
||||
if (driver && driver.mobile) {
|
||||
formData.driverPhone = driver.mobile;
|
||||
console.log('[司机选择] 司机ID:', driverId, ', 已自动填充手机号:', driver.mobile);
|
||||
ElMessage.success('已自动填充司机手机号');
|
||||
} else {
|
||||
console.log('[司机选择] 司机ID:', driverId, ', 但未找到手机号');
|
||||
}
|
||||
} else {
|
||||
formData.driverId = null;
|
||||
formData.driverPhone = '';
|
||||
console.log('[司机选择] 司机已清除');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1066,7 +1170,7 @@ const handleCollarChange = (ids) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 更新选中设备的delivery_id
|
||||
// 更新选中设备的delivery_id和car_number
|
||||
const updateSelectedDevicesDeliveryId = async (deliveryId) => {
|
||||
try {
|
||||
const devicesToUpdate = [];
|
||||
@@ -1082,17 +1186,18 @@ const updateSelectedDevicesDeliveryId = async (deliveryId) => {
|
||||
devicesToUpdate.push(...formData.collarDeviceIds);
|
||||
}
|
||||
|
||||
// 批量更新设备的delivery_id
|
||||
// 批量更新设备的delivery_id和car_number
|
||||
for (const deviceId of devicesToUpdate) {
|
||||
await updateDeviceDeliveryId({
|
||||
deviceId: deviceId,
|
||||
deliveryId: deliveryId
|
||||
deliveryId: deliveryId,
|
||||
carNumber: formData.plateNumber // 传递车牌号
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`成功更新 ${devicesToUpdate.length} 个设备的delivery_id`);
|
||||
console.log(`成功更新 ${devicesToUpdate.length} 个设备的delivery_id和car_number: ${formData.plateNumber}`);
|
||||
} catch (error) {
|
||||
console.error('更新设备delivery_id失败:', error);
|
||||
console.error('更新设备delivery_id和car_number失败:', error);
|
||||
// 不阻止流程,只记录错误
|
||||
}
|
||||
};
|
||||
@@ -1135,24 +1240,37 @@ const handleSubmit = () => {
|
||||
}
|
||||
console.groupEnd();
|
||||
|
||||
const res = await createDelivery(submitData);
|
||||
console.group('[CREATE-DELIVERY] 响应日志');
|
||||
let res;
|
||||
// 判断是编辑还是新增
|
||||
if (formData.editId) {
|
||||
// 编辑模式:调用更新接口
|
||||
console.log('[EDIT-DELIVERY] 编辑模式,运单ID:', formData.editId);
|
||||
submitData.deliveryId = formData.editId; // 添加deliveryId字段(后端需要)
|
||||
res = await shippingApi.updateDeliveryInfo(submitData);
|
||||
} else {
|
||||
// 新增模式:调用创建接口
|
||||
console.log('[CREATE-DELIVERY] 新增模式');
|
||||
res = await createDelivery(submitData);
|
||||
}
|
||||
|
||||
console.group(formData.editId ? '[EDIT-DELIVERY] 响应日志' : '[CREATE-DELIVERY] 响应日志');
|
||||
console.log('完整响应:', res);
|
||||
console.groupEnd();
|
||||
|
||||
if (res.code === 200) {
|
||||
// 获取新创建的运送清单ID
|
||||
const newDeliveryId = res.data?.id;
|
||||
// 获取运送清单ID(新增返回data.id,编辑直接用editId)
|
||||
const deliveryId = formData.editId || res.data?.id;
|
||||
|
||||
if (newDeliveryId) {
|
||||
if (deliveryId) {
|
||||
// 更新设备的delivery_id
|
||||
await updateSelectedDevicesDeliveryId(newDeliveryId);
|
||||
await updateSelectedDevicesDeliveryId(deliveryId);
|
||||
}
|
||||
|
||||
ElMessage.success('创建成功');
|
||||
ElMessage.success(formData.editId ? '更新成功' : '创建成功');
|
||||
dialogVisible.value = false;
|
||||
emit('success');
|
||||
} else {
|
||||
ElMessage.error(res.msg || '创建失败');
|
||||
ElMessage.error(res.msg || (formData.editId ? '更新失败' : '创建失败'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.group('[CREATE-DELIVERY] 异常日志');
|
||||
@@ -1353,7 +1471,7 @@ const handleClose = () => {
|
||||
formRef.value?.resetFields();
|
||||
// 清空所有表单字段
|
||||
Object.keys(formData).forEach(key => {
|
||||
if (key === 'orderId') {
|
||||
if (key === 'orderId' || key === 'editId') {
|
||||
formData[key] = null;
|
||||
} else if (typeof formData[key] === 'number') {
|
||||
formData[key] = key === 'cattleCount' ? 1 : null;
|
||||
|
||||
Reference in New Issue
Block a user