diff --git a/pages/index/index.js b/pages/index/index.js index 8cbfb5e..8ca2738 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -47,6 +47,9 @@ Page({ page: 1, pageSize: 8, + // 库存总数 + totalInventory: 0, + // 商品数据缓存 goodsCache: [], categoryQueryCache: {}, @@ -416,6 +419,19 @@ Page({ } return ""; }, + + // 计算商品库存总数 + calculateTotalInventory: function(goodsList) { + let total = 0; + goodsList.forEach(good => { + if (good.minOrder && !isNaN(parseInt(good.minOrder))) { + total += parseInt(good.minOrder); + } else if (good.quantity && !isNaN(parseInt(good.quantity))) { + total += parseInt(good.quantity); + } + }); + return total; + }, // 提取地区中的省份信息 extractProvince: function(region) { @@ -541,12 +557,16 @@ Page({ console.log('filteredGoods[1].category:', filteredGoods[1] ? filteredGoods[1].category : 'N/A') } + // 计算库存总数 + const totalInventory = this.calculateTotalInventory(updatedGoods); + this.setData({ goods: updatedGoods, filteredGoods: filteredGoods, loadingMore: false, isLoading: false, - page: this.data.page + 1 + page: this.data.page + 1, + totalInventory: totalInventory }) }, @@ -605,12 +625,16 @@ Page({ const filteredGoods = this.applyFilters(updatedGoods, false) + // 计算库存总数 + const totalInventory = this.calculateTotalInventory(updatedGoods); + this.setData({ goods: updatedGoods, filteredGoods: filteredGoods, loadingMore: false, isLoading: false, - page: this.data.page + 1 + page: this.data.page + 1, + totalInventory: totalInventory }) }, diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 9dd3501..4b87923 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -120,6 +120,10 @@ + + + 库存总数:{{totalInventory}}件 +