Commit 09328fe8 by qinjianhui

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

parent 884223e2
...@@ -370,6 +370,7 @@ const weightGet = async () => { ...@@ -370,6 +370,7 @@ const weightGet = async () => {
const open = () => { const open = () => {
isweight.value = true isweight.value = true
weight.stashToCache()
tableData.value = [] tableData.value = []
selectType.value = 'trackingNumber' selectType.value = 'trackingNumber'
logisticsCompanyCode.value = '' logisticsCompanyCode.value = ''
......
...@@ -55,6 +55,7 @@ type AudioFiles = Record<AudioKey, string> ...@@ -55,6 +55,7 @@ type AudioFiles = Record<AudioKey, string>
class Weigh extends Lock { class Weigh extends Lock {
public weightInput: boolean public weightInput: boolean
public list: WeighItem[] public list: WeighItem[]
public cachedList: WeighItem[]
public selectType: string public selectType: string
private audios: AudioFiles private audios: AudioFiles
private audioElements: Map<AudioKey, HTMLAudioElement> private audioElements: Map<AudioKey, HTMLAudioElement>
...@@ -64,6 +65,7 @@ class Weigh extends Lock { ...@@ -64,6 +65,7 @@ class Weigh extends Lock {
this.weightInput = true this.weightInput = true
this.selectType = 'trackingNumber' this.selectType = 'trackingNumber'
this.list = [] this.list = []
this.cachedList = []
this.audios = { this.audios = {
weight_warning: new URL( weight_warning: new URL(
'@/assets/audio/weight_warning.mp3', '@/assets/audio/weight_warning.mp3',
...@@ -102,22 +104,32 @@ class Weigh extends Lock { ...@@ -102,22 +104,32 @@ class Weigh extends Lock {
clear(): void { clear(): void {
this.list = [] this.list = []
this.cachedList = []
this.weightInput = true this.weightInput = true
this.selectType = 'trackingNumber' this.selectType = 'trackingNumber'
} }
stashToCache(): void {
if (this.list.length) {
this.cachedList = [...this.list]
}
this.list = []
this.weightInput = true
}
updatedList(data: WeighItem[]) { updatedList(data: WeighItem[]) {
this.weightInput = true this.weightInput = true
this.list = [...data] this.list = [...data]
} }
// 去重逻辑优化
private deduplicate( private deduplicate(
value: string, value: string,
callback?: (list: WeighItem[]) => void, callback?: (list: WeighItem[]) => void,
): boolean { ): boolean {
const existingIndex = this.list.findIndex( const existingIndex = this.list.findIndex(
(item) => item.trackingNumber === value, (item) =>
item.trackingNumber === value ||
(this.selectType === 'shopNumber' && item.shopNumber === value),
) )
if (existingIndex !== -1) { if (existingIndex !== -1) {
...@@ -233,12 +245,23 @@ class Weigh extends Lock { ...@@ -233,12 +245,23 @@ class Weigh extends Lock {
this.playAudio('weight_warning', '请录入重量') this.playAudio('weight_warning', '请录入重量')
return return
} }
// 去重检查
if (this.deduplicate(value, callback)) { if (this.deduplicate(value, callback)) {
return 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 { try {
const response = await apiCall(params) const response = await apiCall(params)
console.log(211, response) console.log(211, response)
...@@ -250,20 +273,6 @@ class Weigh extends Lock { ...@@ -250,20 +273,6 @@ class Weigh extends Lock {
return 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) { if (this.list?.length) {
const firstLogisticsCode = data[0]?.logisticsCompanyCode 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