修复货位分页:使用真实page_size+解析total实现上拉加载

This commit is contained in:
97694732@qq.com 2026-06-04 17:09:50 +08:00
parent 1413010c16
commit 6705a6a560

View File

@ -886,6 +886,7 @@ export default {
popupLocLoadingMore: false, popupLocLoadingMore: false,
popupLocationSearch: '', popupLocationSearch: '',
popupAllLocationList: [], popupAllLocationList: [],
popupLocTotal: 0,
popupRefreshing: false, popupRefreshing: false,
_pendingPreselectWh: null, _pendingPreselectWh: null,
_pendingPreselectLoc: null, _pendingPreselectLoc: null,
@ -1378,31 +1379,46 @@ export default {
} }
}, },
async loadPopupLocations(warehouseId) { async loadPopupLocations(warehouseId, keepExisting = false) {
this.popupLoadingLocation = true if (!keepExisting) {
this.popupLocPage = 1 this.popupLoadingLocation = true
this.popupLocHasMore = true this.popupLocPage = 1
this.popupAllLocationList = [] this.popupLocHasMore = true
this.popupAllLocationList = []
this.popupLocTotal = 0
}
try { try {
const res = await getLocationList({ const res = await getLocationList({
warehouse_id: warehouseId, type: 1, status: 1, warehouse_id: warehouseId, type: 1, status: 1,
page: 1, page_size: 999 page: this.popupLocPage, page_size: this.popupLocPageSize
}) })
console.log('【货位列表】load响应:', JSON.stringify(res)) console.log('【货位列表】load响应:', JSON.stringify(res))
// // { code:0, data:{ list:[], total:100 } } { list:[], total:100 }
let list = [] let newList = []
let totalCount = 0
if (res.code === 0 && res.data) { if (res.code === 0 && res.data) {
list = res.data.list || res.data.records || [] newList = res.data.list || res.data.records || []
totalCount = res.data.total || 0
} else if (res.list || res.records) {
newList = res.list || res.records || []
totalCount = res.total || 0
} }
if (list.length === 0) { if (newList.length > 0) {
list = res.list || res.records || [] if (keepExisting) {
} this.popupLocationList = [...this.popupLocationList, ...newList]
if (list.length > 0) { this.popupAllLocationList = [...this.popupAllLocationList, ...newList]
this.popupLocationList = list } else {
this.popupAllLocationList = list this.popupLocationList = newList
this.popupLocHasMore = false this.popupAllLocationList = newList
}
this.popupLocTotal = totalCount
this.popupLocHasMore = this.popupLocPage * this.popupLocPageSize < totalCount
} else { } else {
console.warn('货位列表为空', JSON.stringify(res)) if (!keepExisting) {
this.popupLocationList = []
this.popupAllLocationList = []
}
this.popupLocHasMore = false
} }
} catch (e) { } catch (e) {
console.error('加载货位失败:', e) console.error('加载货位失败:', e)
@ -1418,7 +1434,9 @@ export default {
this.popupLocationList = this.popupAllLocationList this.popupLocationList = this.popupAllLocationList
this.popupLocHasMore = false this.popupLocHasMore = false
} finally { } finally {
this.popupLoadingLocation = false if (!keepExisting) {
this.popupLoadingLocation = false
}
} }
}, },
@ -1481,25 +1499,8 @@ export default {
this.popupLocLoadingMore = true this.popupLocLoadingMore = true
this.popupLocPage++ this.popupLocPage++
const wh = this.popupWarehouseList[this.popupActiveWhIndex] const wh = this.popupWarehouseList[this.popupActiveWhIndex]
if (!wh) return if (!wh) { this.popupLocLoadingMore = false; return }
getLocationList({ this.loadPopupLocations(wh.id, true).catch(() => {
warehouse_id: wh.id, type: 1, status: 1,
page: this.popupLocPage, page_size: this.popupLocPageSize
}).then(res => {
if (res.code === 0 && res.data && res.data.list) {
const newList = res.data.list
if (newList.length === 0) {
this.popupLocHasMore = false
} else {
this.popupLocationList = [...this.popupLocationList, ...newList]
this.popupAllLocationList = [...this.popupAllLocationList, ...newList]
const total = res.data.total || 0
this.popupLocHasMore = this.popupLocPage * this.popupLocPageSize < total
}
} else {
this.popupLocHasMore = false
}
}).catch(() => {
this.popupLocPage-- this.popupLocPage--
}).finally(() => { }).finally(() => {
this.popupLocLoadingMore = false this.popupLocLoadingMore = false