Commit d8a43b52 by Lin

feat(CreateOrder):在创建和修改订单时增强客户资料回填逻辑

- 实现了检查缺失客户信息并从客户资料API获取详细信息的方法。
- 增加了在订单表单中回填缺失字段的逻辑,且不会覆盖已有值,确保数据一致性。
1 parent 0f6577a6
...@@ -155,6 +155,8 @@ export default { ...@@ -155,6 +155,8 @@ export default {
this.subOrderList = this.prepareSubOrderListFromOrder(paramsData) this.subOrderList = this.prepareSubOrderListFromOrder(paramsData)
const customerId = paramsData.customer?.customerId const customerId = paramsData.customer?.customerId
if (customerId) { if (customerId) {
// 编辑/修改订单时,订单快照中的客户车型、车架号等字段可能缺失,需从客户建档详情补全
this.fetchAndBackfillCustomerProfile(customerId, paramsData.customer)
this.fetchGoodsOrderRemark(customerId) this.fetchGoodsOrderRemark(customerId)
} }
} }
...@@ -2001,6 +2003,51 @@ export default { ...@@ -2001,6 +2003,51 @@ export default {
} }
return subOrderList return subOrderList
}, },
// 判断订单客户信息是否需要从建档详情补全(任一关键字段缺失即触发)
needsCustomerProfileBackfill(customer = {}) {
const profileFields = ['standNo', 'carSeriesId', 'carSeriesName', 'carBrandId', 'carBrand', 'carChildsBrandId', 'carChildsBrandName']
return profileFields.some(field => customer[field] == null || customer[field] === '')
},
// 将客户建档详情接口返回的数据回填到订单表单,仅补缺失字段,不覆盖已有值
applyCustomerProfileBackfill(res, customer = {}) {
if (!res || typeof res !== 'object') return
// 与 detailFiles.vue findVisitsInfo 保持一致:建档接口的车型字段需映射为订单使用的 carChildsBrand 字段
if (res.carChildsBrandId) res.carChildsBrandId = res.carSeriesId
if (res.carChildsBrandName) res.carChildsBrandName = res.carSeriesName
const profileFields = ['standNo', 'carSeriesId', 'carSeriesName', 'carBrandId', 'carBrand', 'carChildsBrandId', 'carChildsBrandName']
if (!this.orderObj.customer) this.$set(this.orderObj, 'customer', {})
profileFields.forEach(field => {
if ((customer[field] == null || customer[field] === '') && res[field] != null && res[field] !== '') {
customer[field] = res[field]
this.$set(this.orderObj.customer, field, res[field])
}
})
// standNo 同时存在于 orderObj 顶层与 customer 对象,需同步回填
if ((this.orderObj.standNo == null || this.orderObj.standNo === '') && res.standNo) {
this.$set(this.orderObj, 'standNo', res.standNo)
}
// 拼接车型展示文案:一级品牌-子品牌-车系(与 applyOrderEchoFromRest 回显逻辑一致)
const c = this.orderObj.customer
if (c.carBrandId && (this.orderObj.carBrand == null || this.orderObj.carBrand === '')) {
this.$set(this.orderObj, 'carBrand', `${c.carBrand}-${c.carChildsBrandName}-${c.carSeriesName}`)
}
},
// 调用客户建档详情接口(customerProfileInfoAPI),补全订单中缺失的客户车型与车架号信息
async fetchAndBackfillCustomerProfile(customerId, customer = {}) {
if (!customerId || !this.needsCustomerProfileBackfill(customer)) return
try {
const res = await uni.$api.customerApi.customerProfileInfoAPI({ id: customerId })
this.applyCustomerProfileBackfill(res, customer)
console.log('补全客户详情***', res)
} catch (e) {
console.error('获取客户详情失败', e)
}
},
async fetchGoodsOrderRemark(customerId) { async fetchGoodsOrderRemark(customerId) {
console.log('获取订单备注***', customerId) console.log('获取订单备注***', customerId)
if (!customerId) return if (!customerId) return
...@@ -2025,6 +2072,8 @@ export default { ...@@ -2025,6 +2072,8 @@ export default {
const customerId = customerInfo.customer?.customerId const customerId = customerInfo.customer?.customerId
if (customerId) { if (customerId) {
// 选择客户带入订单时,同样可能存在车型/车架号缺失,优先补全后再拉取备注
await this.fetchAndBackfillCustomerProfile(customerId, customerInfo.customer)
await this.fetchGoodsOrderRemark(customerId) await this.fetchGoodsOrderRemark(customerId)
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!