From 4126fbbcb16dd8d127f2b2a7a589088f0a6ba969 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:50:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=BA=93=E5=AD=98=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=90=88=E5=B9=B6=E6=80=BB=E6=95=B0?= =?UTF-8?q?=EF=BC=9AminOrder=20+=20quantity=20=3D=20totalStock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 36 +++++++++--------------------------- pages/index/index.wxml | 6 +----- pages/index/index.wxss | 16 +--------------- 3 files changed, 11 insertions(+), 47 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index 8ca2738..24d82a3 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -47,9 +47,6 @@ Page({ page: 1, pageSize: 8, - // 库存总数 - totalInventory: 0, - // 商品数据缓存 goodsCache: [], categoryQueryCache: {}, @@ -419,19 +416,6 @@ 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) { @@ -466,6 +450,11 @@ Page({ // 确保商品ID的一致性 const productId = product.productId || product.id; + // 计算库存总数 + const minOrder = parseInt(product.minOrder) || 0; + const quantity = parseInt(product.quantity) || 0; + const totalStock = minOrder + quantity; + return { ...product, id: productId, // 统一使用id字段 @@ -488,7 +477,8 @@ Page({ isReserved: false, isFavorite: false, currentImageIndex: 0, - imageUrls: formattedImageUrls + imageUrls: formattedImageUrls, + totalStock: totalStock // 合并后的库存总数 } }) @@ -557,16 +547,12 @@ 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, - totalInventory: totalInventory + page: this.data.page + 1 }) }, @@ -625,16 +611,12 @@ 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, - totalInventory: totalInventory + page: this.data.page + 1 }) }, diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 4b87923..a3d0c09 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -120,10 +120,6 @@ - - - 库存总数:{{totalInventory}}件 - {{item.sourceType || ''}} {{item.negotiateStatus}} - 库存:{{item.minOrder || item.quantity || '暂无'}} + 库存:{{item.totalStock || '暂无'}} 已有{{item.reservedCount || 0}}人收藏 diff --git a/pages/index/index.wxss b/pages/index/index.wxss index 9c8157f..7da9d9a 100644 --- a/pages/index/index.wxss +++ b/pages/index/index.wxss @@ -148,21 +148,7 @@ page { padding-bottom: calc(env(safe-area-inset-bottom) ); } -/* 库存总数显示样式 */ -.total-inventory-section { - background: #fff; - padding: 20rpx 30rpx; - border-bottom: 1rpx solid #eee; - text-align: center; -} - -.total-inventory-text { - font-size: 32rpx; - font-weight: bold; - color: #333; - } - - .goods-list { +.goods-list { height: auto; box-sizing: border-box; background: #f5f5f5;