From b78e3d6c537ac8b25ecea9452582fd405b097885 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:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BA=93=E5=AD=98=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=80=BB=E8=BE=91=EF=BC=9A=E6=94=AF=E6=8C=81=E9=80=97?= =?UTF-8?q?=E5=8F=B7=E5=88=86=E9=9A=94=E6=95=B0=E5=AD=97=E7=9A=84=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index 24d82a3..d06468b 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -450,9 +450,18 @@ Page({ // 确保商品ID的一致性 const productId = product.productId || product.id; - // 计算库存总数 - const minOrder = parseInt(product.minOrder) || 0; - const quantity = parseInt(product.quantity) || 0; + // 计算库存总数 - 支持逗号分隔的数字字符串 + 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; return {