From a7fe11053793ce2f8f4157e850191326b9b41077 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 14:12:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BA=93=E5=AD=98=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=97=AE=E9=A2=98=EF=BC=9A=E5=B0=860=E4=BB=B6?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=9A=82=E6=97=A0=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 31 +++++++++++++++++++++++++++++-- pages/index/index.wxml | 4 ++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index d06468b..8f18351 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -463,6 +463,11 @@ Page({ const minOrder = calculateTotalStock(product.minOrder); const quantity = calculateTotalStock(product.quantity); const totalStock = minOrder + quantity; + + // 如果库存为0但有其他库存信息,显示"充足"或基于其他字段 + const displayStock = totalStock > 0 ? totalStock : + (product.stock > 0 ? product.stock : + (product.inventory > 0 ? product.inventory : '充足')); return { ...product, @@ -487,7 +492,8 @@ Page({ isFavorite: false, currentImageIndex: 0, imageUrls: formattedImageUrls, - totalStock: totalStock // 合并后的库存总数 + totalStock: displayStock, // 使用优化后的库存显示值 + originalTotalStock: totalStock // 保留原始计算值用于调试 } }) @@ -816,6 +822,25 @@ Page({ // 只有当商品ID不存在时才添加,避免重复 if (!goodsMap.has(productId)) { + // 计算库存总数 - 支持逗号分隔的数字字符串 + const calculateTotalStock = (value) => { + if (!value) return 0; + if (typeof value === 'string') { + // 支持逗号分隔的数字字符串,如 "23,34,24" + return value.split(/[,,、]/).map(item => parseInt(item.trim()) || 0).reduce((sum, num) => sum + num, 0); + } + return parseInt(value) || 0; + }; + + const minOrder = calculateTotalStock(product.minOrder); + const quantity = calculateTotalStock(product.quantity); + const totalStock = minOrder + quantity; + + // 如果库存为0但有其他库存信息,显示"充足"或基于其他字段 + const displayStock = totalStock > 0 ? totalStock : + (product.stock > 0 ? product.stock : + (product.inventory > 0 ? product.inventory : '充足')); + const processedProduct = { ...product, id: productId, // 统一使用id字段 @@ -838,7 +863,9 @@ Page({ isReserved: false, isFavorite: false, currentImageIndex: 0, - imageUrls: formattedImageUrls + imageUrls: formattedImageUrls, + totalStock: displayStock, // 使用优化后的库存显示值 + originalTotalStock: totalStock // 保留原始计算值用于调试 }; goodsMap.set(productId, processedProduct); diff --git a/pages/index/index.wxml b/pages/index/index.wxml index a3d0c09..fc5c592 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -10,7 +10,7 @@ - {{selectedRegion || '全国'}} ▼ + {{selectedRegion || '全国'}} ➤ 🔍 @@ -164,7 +164,7 @@ {{item.sourceType || ''}} {{item.negotiateStatus}} - 库存:{{item.totalStock || '暂无'}} + 库存:{{item.totalStock > 0 ? item.totalStock + '件' : '暂无'}} 已有{{item.reservedCount || 0}}人收藏