后期需求已修改
This commit is contained in:
@@ -14,10 +14,11 @@
|
||||
>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="24">
|
||||
<el-form-item label="关联订单" prop="orderId">
|
||||
<el-form-item label="关联订单" prop="orderIds">
|
||||
<el-select
|
||||
v-model="formData.orderId"
|
||||
placeholder="请选择订单(可选择关联订单)"
|
||||
v-model="formData.orderIds"
|
||||
placeholder="请选择订单(可多选关联订单)"
|
||||
multiple
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
@@ -34,33 +35,6 @@
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="发货方" prop="shipper">
|
||||
<el-select v-model="formData.shipper" placeholder="请选择发货方" clearable filterable style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in supplierList"
|
||||
:key="item.id"
|
||||
:label="item.username || item.mobile"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="采购方" prop="buyer">
|
||||
<el-select v-model="formData.buyer" placeholder="请选择采购方" clearable filterable style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in buyerList"
|
||||
:key="item.id"
|
||||
:label="item.username || item.mobile"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="车牌号" prop="plateNumber">
|
||||
@@ -224,6 +198,19 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="司机运费" prop="freight">
|
||||
<el-input-number
|
||||
v-model="formData.freight"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
placeholder="请输入司机运费"
|
||||
style="width: 100%"
|
||||
>
|
||||
<template #append>元</template>
|
||||
</el-input-number>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row :gutter="20">
|
||||
@@ -924,9 +911,9 @@ import { ref, reactive, computed, watch } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { ElImageViewer } from 'element-plus';
|
||||
import { Plus, UploadFilled, Delete, ZoomIn } from '@element-plus/icons-vue';
|
||||
import { createDelivery, updateDeviceDeliveryId, orderPageQuery, getDeliveryDetail } from '@/api/shipping.js';
|
||||
import { createDelivery, updateDeviceDeliveryId, orderPageQuery, getDeliveryDetail, updateOrderDeliveryId } from '@/api/shipping.js';
|
||||
import * as shippingApi from '@/api/shipping.js';
|
||||
import { memberListByType, driverList as fetchDriverList, vehicleList as fetchVehicleList } from '@/api/userManage.js';
|
||||
import { driverList as fetchDriverList, vehicleList as fetchVehicleList } from '@/api/userManage.js';
|
||||
import { iotDeviceQueryList } from '@/api/hardware.js';
|
||||
import { BaiduMap, BmMapType, BmMarker } from 'vue-baidu-map-3x';
|
||||
import { useUserStore } from '../../store/user';
|
||||
@@ -944,8 +931,6 @@ const isSubmitSuccess = ref(false); // 标记是否刚刚提交成功
|
||||
const serverList = ref([]);
|
||||
const eartagList = ref([]);
|
||||
const collarList = ref([]);
|
||||
const supplierList = ref([]);
|
||||
const buyerList = ref([]);
|
||||
const driverOptions = ref([]);
|
||||
const vehicleOptions = ref([]);
|
||||
const orderList = ref([]);
|
||||
@@ -954,9 +939,7 @@ const showEndLocationMap = ref(false);
|
||||
|
||||
const formData = reactive({
|
||||
editId: null, // 编辑时的运单ID
|
||||
orderId: null,
|
||||
shipper: null,
|
||||
buyer: null,
|
||||
orderIds: [], // 关联订单ID数组(多选)
|
||||
plateNumber: null,
|
||||
driverId: null, // 司机ID(后端用)
|
||||
driverName: null,
|
||||
@@ -976,6 +959,7 @@ const formData = reactive({
|
||||
endLat: '',
|
||||
endLon: '',
|
||||
cattleCount: 1,
|
||||
freight: null, // 司机运费
|
||||
quarantineCertNo: '',
|
||||
remark: '',
|
||||
// 装车相关字段
|
||||
@@ -1039,9 +1023,7 @@ const validateArrivalTime = (rule, value, callback) => {
|
||||
};
|
||||
|
||||
const rules = {
|
||||
orderId: [{ required: false, message: '请选择订单', trigger: 'change' }],
|
||||
shipper: [{ required: true, message: '请选择发货方', trigger: 'change' }],
|
||||
buyer: [{ required: true, message: '请选择采购方', trigger: 'change' }],
|
||||
orderIds: [{ required: false, message: '请选择订单', trigger: 'change' }],
|
||||
plateNumber: [{ required: true, message: '请选择车牌号', trigger: 'change' }],
|
||||
driverId: [{ required: true, message: '请选择司机', trigger: 'change' }],
|
||||
driverPhone: [{ required: true, validator: validatePhone, trigger: 'blur' }],
|
||||
@@ -1086,15 +1068,13 @@ const buildSubmitData = () => {
|
||||
|
||||
const data = {
|
||||
// 基本信息
|
||||
shipperId: formData.shipper,
|
||||
buyerId: formData.buyer,
|
||||
plateNumber: formData.plateNumber,
|
||||
driverId: formData.driverId, // 传递司机ID给后端
|
||||
driverName: driverNameStr,
|
||||
driverPhone: formData.driverPhone,
|
||||
|
||||
// 关联信息
|
||||
orderId: formData.orderId,
|
||||
// 关联信息(将订单ID数组转换为逗号分隔的字符串)
|
||||
orderId: formData.orderIds && formData.orderIds.length > 0 ? formData.orderIds.join(',') : null,
|
||||
|
||||
// 设备ID
|
||||
serverId: formData.serverId,
|
||||
@@ -1120,6 +1100,7 @@ const buildSubmitData = () => {
|
||||
|
||||
// 其他信息
|
||||
cattleCount: formData.cattleCount,
|
||||
freight: formData.freight,
|
||||
quarantineCertNo: formData.quarantineCertNo,
|
||||
remark: formData.remark,
|
||||
|
||||
@@ -1157,7 +1138,7 @@ const buildSubmitData = () => {
|
||||
if (data[key] === undefined) {
|
||||
// 数值类型字段保留null,其他字段转换为空字符串
|
||||
if (key === 'cattleCount' ||
|
||||
key === 'orderId' || key === 'shipperId' || key === 'buyerId' ||
|
||||
key === 'orderIds' ||
|
||||
key === 'driverId' || key === 'serverId') {
|
||||
data[key] = null;
|
||||
} else {
|
||||
@@ -1182,7 +1163,6 @@ const open = async (editData = null) => {
|
||||
|
||||
// 并行加载所有下拉列表数据
|
||||
await Promise.all([
|
||||
loadSupplierAndBuyerList(),
|
||||
loadDeviceOptions(),
|
||||
loadDriverList(),
|
||||
loadVehicleList(),
|
||||
@@ -1257,12 +1237,21 @@ const fillFormWithEditData = (editData) => {
|
||||
|
||||
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;
|
||||
// 基本信息(将逗号分隔的订单ID字符串转换为数组)
|
||||
if (delivery.orderId) {
|
||||
if (typeof delivery.orderId === 'string') {
|
||||
// 如果是字符串,按逗号分割
|
||||
formData.orderIds = delivery.orderId.split(',').map(id => parseInt(id.trim())).filter(id => !isNaN(id));
|
||||
} else if (Array.isArray(delivery.orderId)) {
|
||||
// 如果已经是数组,直接使用
|
||||
formData.orderIds = delivery.orderId;
|
||||
} else {
|
||||
// 如果是单个数字,转换为数组
|
||||
formData.orderIds = [delivery.orderId];
|
||||
}
|
||||
} else {
|
||||
formData.orderIds = [];
|
||||
}
|
||||
|
||||
// 车牌号
|
||||
formData.plateNumber = delivery.licensePlate || '';
|
||||
@@ -1326,6 +1315,9 @@ const fillFormWithEditData = (editData) => {
|
||||
// 牛只数量(从ratedQuantity字段映射)
|
||||
formData.cattleCount = delivery.ratedQuantity || 1;
|
||||
|
||||
// 司机运费
|
||||
formData.freight = delivery.freight || null;
|
||||
|
||||
// 照片
|
||||
formData.quarantineTickeyUrl = delivery.quarantineTickeyUrl || '';
|
||||
formData.poundListImg = delivery.poundListImg || '';
|
||||
@@ -1352,25 +1344,6 @@ const fillFormWithEditData = (editData) => {
|
||||
ElMessage.success('已加载运单数据');
|
||||
};
|
||||
|
||||
// 加载供应商和采购方列表
|
||||
const loadSupplierAndBuyerList = async () => {
|
||||
try {
|
||||
// 加载供应商列表 (type=2)
|
||||
const supplierRes = await memberListByType({ type: 2, pageNum: 1, pageSize: 9999 });
|
||||
if (supplierRes.code === 200) {
|
||||
supplierList.value = supplierRes.data?.rows || supplierRes.data || [];
|
||||
}
|
||||
|
||||
// 加载采购方列表 (type=4)
|
||||
const buyerRes = await memberListByType({ type: 4, pageNum: 1, pageSize: 9999 });
|
||||
if (buyerRes.code === 200) {
|
||||
buyerList.value = buyerRes.data?.rows || buyerRes.data || [];
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载供应商/采购方列表失败', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 加载设备选项
|
||||
const loadDeviceOptions = async () => {
|
||||
try {
|
||||
@@ -1464,121 +1437,11 @@ const loadOrderList = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 订单选择变化时自动填充发货方和采购方
|
||||
const handleOrderChange = async (orderId) => {
|
||||
if (orderId) {
|
||||
try {
|
||||
// 从订单列表中查找选中的订单
|
||||
const order = orderList.value.find(item => item.id === orderId);
|
||||
if (order) {
|
||||
// 处理 buyerId:支持数字、字符串(逗号分隔)和数组格式,取第一个值
|
||||
let buyerId = null;
|
||||
if (order.buyerId) {
|
||||
if (typeof order.buyerId === 'number') {
|
||||
buyerId = order.buyerId;
|
||||
} else if (Array.isArray(order.buyerId) && order.buyerId.length > 0) {
|
||||
buyerId = parseInt(order.buyerId[0]);
|
||||
} else if (typeof order.buyerId === 'string' && order.buyerId.trim() !== '') {
|
||||
const ids = order.buyerId.split(',').map(id => id.trim()).filter(id => id !== '');
|
||||
buyerId = ids.length > 0 ? parseInt(ids[0]) : null;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理 sellerId:支持数字、字符串(逗号分隔)和数组格式,取第一个值
|
||||
let sellerId = null;
|
||||
if (order.sellerId) {
|
||||
if (typeof order.sellerId === 'number') {
|
||||
sellerId = order.sellerId;
|
||||
} else if (Array.isArray(order.sellerId) && order.sellerId.length > 0) {
|
||||
sellerId = parseInt(order.sellerId[0]);
|
||||
} else if (typeof order.sellerId === 'string' && order.sellerId.trim() !== '') {
|
||||
const ids = order.sellerId.split(',').map(id => id.trim()).filter(id => id !== '');
|
||||
sellerId = ids.length > 0 ? parseInt(ids[0]) : null;
|
||||
}
|
||||
}
|
||||
|
||||
// 确保buyerId在buyerList中,如果不在则查询并添加
|
||||
if (buyerId && !buyerList.value.find(item => item.id === buyerId)) {
|
||||
try {
|
||||
// 查询所有类型的用户,找到对应的buyerId
|
||||
const allBuyerRes = await memberListByType({ pageNum: 1, pageSize: 9999 });
|
||||
if (allBuyerRes.code === 200) {
|
||||
const allBuyers = allBuyerRes.data?.rows || allBuyerRes.data || [];
|
||||
const buyerInfo = allBuyers.find(item => item.id === buyerId);
|
||||
if (buyerInfo) {
|
||||
// 如果找到,添加到buyerList中
|
||||
buyerList.value.push(buyerInfo);
|
||||
} else {
|
||||
// 如果找不到,使用订单中的buyerName创建一个临时对象
|
||||
if (order.buyerName) {
|
||||
buyerList.value.push({
|
||||
id: buyerId,
|
||||
username: order.buyerName,
|
||||
mobile: ''
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('查询采购方信息失败', error);
|
||||
// 如果查询失败,使用订单中的buyerName创建一个临时对象
|
||||
if (order.buyerName) {
|
||||
buyerList.value.push({
|
||||
id: buyerId,
|
||||
username: order.buyerName,
|
||||
mobile: ''
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 确保sellerId在supplierList中,如果不在则查询并添加
|
||||
if (sellerId && !supplierList.value.find(item => item.id === sellerId)) {
|
||||
try {
|
||||
// 查询所有类型的用户,找到对应的sellerId
|
||||
const allSupplierRes = await memberListByType({ pageNum: 1, pageSize: 9999 });
|
||||
if (allSupplierRes.code === 200) {
|
||||
const allSuppliers = allSupplierRes.data?.rows || allSupplierRes.data || [];
|
||||
const supplierInfo = allSuppliers.find(item => item.id === sellerId);
|
||||
if (supplierInfo) {
|
||||
// 如果找到,添加到supplierList中
|
||||
supplierList.value.push(supplierInfo);
|
||||
} else {
|
||||
// 如果找不到,使用订单中的sellerName创建一个临时对象
|
||||
if (order.sellerName) {
|
||||
supplierList.value.push({
|
||||
id: sellerId,
|
||||
username: order.sellerName,
|
||||
mobile: ''
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('查询发货方信息失败', error);
|
||||
// 如果查询失败,使用订单中的sellerName创建一个临时对象
|
||||
if (order.sellerName) {
|
||||
supplierList.value.push({
|
||||
id: sellerId,
|
||||
username: order.sellerName,
|
||||
mobile: ''
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 自动填充发货方(卖方)和采购方(买方)
|
||||
formData.shipper = sellerId || null;
|
||||
formData.buyer = buyerId || null;
|
||||
|
||||
|
||||
ElMessage.success('已自动填充发货方和采购方信息');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载订单详情失败', error);
|
||||
}
|
||||
} else {
|
||||
// 清除订单时不清除发货方和采购方,让用户手动选择
|
||||
// 订单选择变化时的处理(多选模式)
|
||||
const handleOrderChange = async (orderIds) => {
|
||||
// 多选模式下,orderIds 是数组
|
||||
if (orderIds && orderIds.length > 0) {
|
||||
console.log('已选择订单:', orderIds);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1752,6 +1615,24 @@ const handleSubmit = () => {
|
||||
if (deliveryId) {
|
||||
// 更新设备的delivery_id
|
||||
await updateSelectedDevicesDeliveryId(deliveryId);
|
||||
|
||||
// 更新关联订单的delivery_id
|
||||
if (formData.orderIds && formData.orderIds.length > 0) {
|
||||
try {
|
||||
const updateOrderRes = await updateOrderDeliveryId({
|
||||
deliveryId: deliveryId,
|
||||
orderIds: formData.orderIds
|
||||
});
|
||||
if (updateOrderRes.code === 200) {
|
||||
console.log('[ORDER-UPDATE] 成功更新订单delivery_id,订单数量:', formData.orderIds.length);
|
||||
} else {
|
||||
console.warn('[ORDER-UPDATE] 更新订单delivery_id失败:', updateOrderRes.msg);
|
||||
}
|
||||
} catch (orderError) {
|
||||
console.error('[ORDER-UPDATE] 更新订单delivery_id异常:', orderError);
|
||||
// 不阻止流程,只记录错误
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 提交成功后立即清除对应模式的缓存
|
||||
@@ -2037,9 +1918,7 @@ const handleClose = () => {
|
||||
// 编辑模式:保存到 editFormData[editId]
|
||||
deliveryFormStore.saveEditFormData(formData.editId, {
|
||||
editId: formData.editId,
|
||||
orderId: formData.orderId,
|
||||
shipper: formData.shipper,
|
||||
buyer: formData.buyer,
|
||||
orderIds: formData.orderIds,
|
||||
plateNumber: formData.plateNumber,
|
||||
driverId: formData.driverId,
|
||||
driverPhone: formData.driverPhone,
|
||||
@@ -2058,6 +1937,7 @@ const handleClose = () => {
|
||||
endLat: formData.endLat,
|
||||
endLon: formData.endLon,
|
||||
cattleCount: formData.cattleCount,
|
||||
freight: formData.freight,
|
||||
quarantineCertNo: formData.quarantineCertNo,
|
||||
remark: formData.remark,
|
||||
emptyWeight: formData.emptyWeight,
|
||||
@@ -2082,9 +1962,7 @@ const handleClose = () => {
|
||||
} else {
|
||||
// 新增模式:保存到 newFormData
|
||||
deliveryFormStore.saveNewFormData({
|
||||
orderId: formData.orderId,
|
||||
shipper: formData.shipper,
|
||||
buyer: formData.buyer,
|
||||
orderIds: formData.orderIds,
|
||||
plateNumber: formData.plateNumber,
|
||||
driverId: formData.driverId,
|
||||
driverPhone: formData.driverPhone,
|
||||
@@ -2103,6 +1981,7 @@ const handleClose = () => {
|
||||
endLat: formData.endLat,
|
||||
endLon: formData.endLon,
|
||||
cattleCount: formData.cattleCount,
|
||||
freight: formData.freight,
|
||||
quarantineCertNo: formData.quarantineCertNo,
|
||||
remark: formData.remark,
|
||||
emptyWeight: formData.emptyWeight,
|
||||
@@ -2133,7 +2012,9 @@ const handleClose = () => {
|
||||
formRef.value?.resetFields();
|
||||
// 清空所有表单字段
|
||||
Object.keys(formData).forEach(key => {
|
||||
if (key === 'orderId' || key === 'editId') {
|
||||
if (key === 'orderIds') {
|
||||
formData[key] = [];
|
||||
} else if (key === 'editId') {
|
||||
formData[key] = null;
|
||||
} else if (typeof formData[key] === 'number') {
|
||||
formData[key] = key === 'cattleCount' ? 1 : null;
|
||||
@@ -2177,9 +2058,7 @@ watch(
|
||||
// 编辑模式:保存到 editFormData[editId]
|
||||
deliveryFormStore.saveEditFormData(formData.editId, {
|
||||
editId: formData.editId,
|
||||
orderId: formData.orderId,
|
||||
shipper: formData.shipper,
|
||||
buyer: formData.buyer,
|
||||
orderIds: formData.orderIds,
|
||||
plateNumber: formData.plateNumber,
|
||||
driverId: formData.driverId,
|
||||
driverPhone: formData.driverPhone,
|
||||
@@ -2222,15 +2101,11 @@ watch(
|
||||
} else {
|
||||
// 新增模式:保存到 newFormData
|
||||
console.log('[CACHE] 保存新增模式数据:', {
|
||||
shipper: formData.shipper,
|
||||
buyer: formData.buyer,
|
||||
plateNumber: formData.plateNumber,
|
||||
driverId: formData.driverId,
|
||||
});
|
||||
deliveryFormStore.saveNewFormData({
|
||||
orderId: formData.orderId,
|
||||
shipper: formData.shipper,
|
||||
buyer: formData.buyer,
|
||||
orderIds: formData.orderIds,
|
||||
plateNumber: formData.plateNumber,
|
||||
driverId: formData.driverId,
|
||||
driverPhone: formData.driverPhone,
|
||||
|
||||
Reference in New Issue
Block a user