Commit 09328fe8 by qinjianhui

fix: 称重弹框重开时缓存上次未保存数据,按跟踪号/店铺单号命中缓存免调接口

parent 884223e2
......@@ -370,6 +370,7 @@ const weightGet = async () => {
const open = () => {
isweight.value = true
weight.stashToCache()
tableData.value = []
selectType.value = 'trackingNumber'
logisticsCompanyCode.value = ''
......
......@@ -55,6 +55,7 @@ type AudioFiles = Record<AudioKey, string>
class Weigh extends Lock {
public weightInput: boolean
public list: WeighItem[]
public cachedList: WeighItem[]
public selectType: string
private audios: AudioFiles
private audioElements: Map<AudioKey, HTMLAudioElement>
......@@ -64,6 +65,7 @@ class Weigh extends Lock {
this.weightInput = true
this.selectType = 'trackingNumber'
this.list = []
this.cachedList = []
this.audios = {
weight_warning: new URL(
'@/assets/audio/weight_warning.mp3',
......@@ -102,22 +104,32 @@ class Weigh extends Lock {
clear(): void {
this.list = []
this.cachedList = []
this.weightInput = true
this.selectType = 'trackingNumber'
}
stashToCache(): void {
if (this.list.length) {
this.cachedList = [...this.list]
}
this.list = []
this.weightInput = true
}
updatedList(data: WeighItem[]) {
this.weightInput = true
this.list = [...data]
}
// 去重逻辑优化
private deduplicate(
value: string,
callback?: (list: WeighItem[]) => void,
): boolean {
const existingIndex = this.list.findIndex(
(item) => item.trackingNumber === value,
(item) =>
item.trackingNumber === value ||
(this.selectType === 'shopNumber' && item.shopNumber === value),
)
if (existingIndex !== -1) {
......@@ -233,12 +245,23 @@ class Weigh extends Lock {
this.playAudio('weight_warning', '请录入重量')
return
}
// 去重检查
if (this.deduplicate(value, callback)) {
return
}
const cachedItem = this.cachedList.find(
(item) =>
(this.selectType === 'trackingNumber' && item.trackingNumber === value) ||
(this.selectType === 'shopNumber' && item.shopNumber === value),
)
if (cachedItem) {
this.list = [cachedItem, ...this.list]
this.weightInput = !!cachedItem.outWarehouseWeight
callback?.(this.list)
this.playAudio('weight_search_success')
return
}
try {
const response = await apiCall(params)
console.log(211, response)
......@@ -250,20 +273,6 @@ class Weigh extends Lock {
return
}
// const waitWeighingList = data.filter(
// (el) => el.status === 'WAIT_WEIGHING',
// )
// if (waitWeighingList.length === 0) {
// this.playAudio(
// 'weight_search_error',
// `必须是待称重状态的订单下的${
// this.selectType === 'trackingNumber' ? '跟踪号' : '店铺单号'
// }才能使用`,
// )
// return
// }
if (this.list?.length) {
const firstLogisticsCode = data[0]?.logisticsCompanyCode
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment