diff --git a/pages/record/record.vue b/pages/record/record.vue index 13f48be..7a5b742 100644 --- a/pages/record/record.vue +++ b/pages/record/record.vue @@ -53,12 +53,7 @@ - - 👆 - 请在上方选择一个店铺 - 选择店铺后即可查看该店铺的上书记录 - - + @@ -69,6 +64,7 @@ {{ item.name }} + {{ item._shop_name }} ISBN: @@ -124,7 +120,7 @@ - + 📭 暂无上书记录 @@ -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;