From 33094e51ced08526d2393ad7246d9f3d7566829e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Fri, 2 Jan 2026 11:42:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E9=A6=96=E9=A1=B5=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E6=80=BB=E6=95=B0=E6=98=BE=E7=A4=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E8=AE=A1=E7=AE=97=E5=B9=B6=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=95=86=E5=93=81=E7=9A=84=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E6=80=BB=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 28 ++++++++++++++++++++++++++-- pages/index/index.wxml | 4 ++++ pages/index/index.wxss | 16 +++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) 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}}件 +