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