fix: 修复订单编辑时客户无法匹配的问题
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Agent
2026-03-28 02:49:37 +00:00
parent 53326f3a48
commit e98b283501

View File

@@ -187,7 +187,8 @@ export default {
remark: '', remark: '',
// 编辑模式 // 编辑模式
editingOrderId: null editingOrderId: null,
tempCustomerId: null // 临时保存编辑时的客户ID
} }
}, },
onLoad(options) { onLoad(options) {
@@ -195,7 +196,10 @@ export default {
this.loadProducts() this.loadProducts()
if (options.orderId) { if (options.orderId) {
this.editingOrderId = options.orderId this.editingOrderId = options.orderId
// 编辑模式:等客户列表加载完成后再加载订单
setTimeout(() => {
this.loadOrder(options.orderId) this.loadOrder(options.orderId)
}, 500)
} }
}, },
methods: { methods: {
@@ -204,10 +208,8 @@ export default {
const detail = await orderApi.getOrderDetail(orderId) const detail = await orderApi.getOrderDetail(orderId)
const order = detail.order const order = detail.order
// 设置订单信息 // 先保存 customerId等 customers 加载完成后匹配
if (order.customerId) { this.tempCustomerId = order.customerId
this.selectedCustomer = this.customers.find(c => c.customerId === order.customerId)
}
this.orderItems = (detail.items || []).map(item => ({ this.orderItems = (detail.items || []).map(item => ({
productId: item.productId, productId: item.productId,
@@ -219,18 +221,29 @@ export default {
})) }))
this.discountRate = order.discountRate this.discountRate = order.discountRate
this.discountMoney = order.discountMoney || 0
this.remark = order.remark || '' this.remark = order.remark || ''
this.paymentMethod = order.paymentMethod || 'cash' this.paymentMethod = order.paymentMethod || 'cash'
this.calcAmount() this.calcAmount()
// 尝试匹配客户
this.matchCustomer()
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
}, },
matchCustomer() {
if (this.tempCustomerId && this.customers.length > 0) {
this.selectedCustomer = this.customers.find(c => c.customerId === this.tempCustomerId)
}
},
async loadCustomers() { async loadCustomers() {
try { try {
const res = await customerApi.getCustomers({ page: 1, pageSize: 100 }) const res = await customerApi.getCustomers({ page: 1, pageSize: 100 })
this.customers = res.records || [] this.customers = res.records || []
// 客户列表加载完成后,尝试匹配编辑订单的客户
this.matchCustomer()
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }