fix:全部店铺模式遍历所有店铺请求数据并聚合展示

This commit is contained in:
ShenQiLun 2026-07-01 09:53:43 +08:00
parent bba26b1578
commit 2ad1316c92

View File

@ -53,12 +53,7 @@
<!-- 记录列表 -->
<scroll-view class="record-scroll" scroll-y :refresher-enabled="true" :refresher-triggered="isRefreshing" @refresherrefresh="onRefresh" @scrolltolower="loadMore">
<view class="empty-hint" v-if="!hasShopSelected">
<text class="empty-hint-icon">👆</text>
<text class="empty-hint-text">请在上方选择一个店铺</text>
<text class="empty-hint-desc">选择店铺后即可查看该店铺的上书记录</text>
</view>
<view class="record-list" v-else>
<view class="record-list">
<view class="record-item" v-for="(item, index) in recordList" :key="index">
<view class="record-main">
<!-- 图片 -->
@ -69,6 +64,7 @@
<view class="record-info">
<view class="info-row">
<text class="book-name">{{ item.name }}</text>
<text class="shop-tag" v-if="item._shop_name">{{ item._shop_name }}</text>
</view>
<view class="info-row">
<text class="info-label">ISBN</text>
@ -124,7 +120,7 @@
</view>
<!-- 空状态 -->
<view class="empty-state" v-if="recordList.length === 0 && !isLoading && hasShopSelected">
<view class="empty-state" v-if="recordList.length === 0 && !isLoading">
<text class="empty-icon">📭</text>
<text class="empty-text">暂无上书记录</text>
</view>
@ -167,12 +163,6 @@ export default {
this.loadShopList()
},
computed: {
hasShopSelected() {
return this.shopIndex > 0
}
},
methods: {
//
async loadShopList() {
@ -183,6 +173,8 @@ export default {
const res = await getShopList(params)
this.shopList = res.list || []
this.updateShopNames()
//
this.resetAndFetch()
} catch (e) {
console.error('加载店铺列表失败:', e)
}
@ -233,32 +225,66 @@ export default {
//
async fetchRecords() {
if (this.isLoading || this.loadingMore) return
if (!this.hasShopSelected) {
this.isLoading = false
return
}
this.isLoading = true
try {
const shopId = this.getSelectedShopId()
const params = {
page: this.page,
page_size: this.pageSize,
shop_id: shopId
}
const res = await getShopDetail(params)
const products = res.products || []
if (this.page === 1) {
this.recordList = products
var targets = []
var shopId = this.getSelectedShopId()
if (shopId) {
targets = [{ id: shopId }]
} else {
this.recordList = this.recordList.concat(products)
//
targets = this.shopList
}
this.hasMore = products.length >= this.pageSize
this.stats = {
successCount: res.success_count || 0,
notSentCount: res.not_sent_count || 0,
failedCount: res.failed_count || 0,
total: res.total || 0
if (targets.length === 0) {
this.recordList = []
this.stats = { successCount: 0, notSentCount: 0, failedCount: 0, total: 0 }
this.hasMore = false
this.isLoading = false
return
}
var mergedProducts = this.page === 1 ? [] : this.recordList.slice()
var mergedStats = { successCount: 0, notSentCount: 0, failedCount: 0, total: 0 }
var allLoaded = true
for (var i = 0; i < targets.length; i++) {
try {
const params = {
page: this.page,
page_size: this.pageSize,
shop_id: targets[i].id
}
const res = await getShopDetail(params)
var products = res.products || []
//
var shopDisplayName = res.shop_alias_name || targets[i].shop_alias_name || targets[i].shop_name || ''
for (var pi = 0; pi < products.length; pi++) {
if (shopDisplayName) products[pi]._shop_name = shopDisplayName
}
mergedProducts = mergedProducts.concat(products)
mergedStats.successCount += (res.success_count || 0)
mergedStats.notSentCount += (res.not_sent_count || 0)
mergedStats.failedCount += (res.failed_count || 0)
mergedStats.total += (res.total || 0)
//
if (products.length < this.pageSize) {
// allLoaded
} else {
allLoaded = false
}
} catch (e) {
console.error('获取店铺[' + targets[i].shop_alias_name + ']的上书记录失败:', e)
}
}
//
mergedProducts.sort(function(a, b) {
return (b.created_at || 0) - (a.created_at || 0)
})
this.recordList = mergedProducts
this.hasMore = !allLoaded && targets.length > 0
this.stats = mergedStats
} catch (e) {
console.error('获取上书记录失败:', e)
} finally {
@ -504,6 +530,19 @@ export default {
font-weight: 600;
lines: 1;
overflow: hidden;
white-space: nowrap;
flex: 1;
min-width: 0;
}
.shop-tag {
font-size: 20rpx;
color: #409eff;
background: #d9ecff;
padding: 2rpx 10rpx;
border-radius: 6rpx;
margin-left: 8rpx;
flex-shrink: 0;
}
.info-label {
@ -617,33 +656,6 @@ export default {
100% { transform: rotate(360deg); }
}
/* 提示选择店铺 */
.empty-hint {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 160rpx 40rpx;
}
.empty-hint-icon {
font-size: 60rpx;
margin-bottom: 24rpx;
}
.empty-hint-text {
font-size: 30rpx;
color: #4e5969;
font-weight: 500;
margin-bottom: 12rpx;
}
.empty-hint-desc {
font-size: 26rpx;
color: #909399;
text-align: center;
}
/* 空状态 */
.empty-state {
display: flex;