From f7c11889fe5ba3e117aabcd40634072bbf3006be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sat, 27 Jun 2026 00:41:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(SkuSelector):=20=E4=BF=AE=E6=AD=A3=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整fakeSku中price字段优先使用product.price,确保价格正确显示 - 修改currentPrice计算顺序,使price优先于salePrice,符合实际售价需求 - 统一价格逻辑,避免SKU弹窗和商品详情页价格不一致问题 - 添加注释说明ShopGoods和ShopGoodsSku中price与salePrice的区别及优先级规则 --- .workbuddy/memory/2026-06-27.md | 9 +++++++++ src/components/business/SkuSelector/index.tsx | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .workbuddy/memory/2026-06-27.md diff --git a/.workbuddy/memory/2026-06-27.md b/.workbuddy/memory/2026-06-27.md new file mode 100644 index 0000000..6e9dce6 --- /dev/null +++ b/.workbuddy/memory/2026-06-27.md @@ -0,0 +1,9 @@ +# 2026-06-27 工作日志 + +## SKU选择器价格显示错误修复 +- **文件**: `src/components/business/SkuSelector/index.tsx` +- **问题**: 商品详情页价格显示 ¥1019,但点击"立即购买"后SKU弹窗显示 ¥2519 +- **根因**: `currentPrice` 计算式中 `salePrice` 优先级高于 `price`。ShopGoods 模型中 `price`=实际售价(1019),`salePrice`=市场/原价(2519)。当 SKU 未选中时回退到 product 级别,错误地优先取了 salePrice +- **修复**: + 1. 第190行: `currentPrice` 优先级改为 `selectedSku?.price || selectedSku?.salePrice || product?.price || product?.salePrice` + 2. 第160行: 单规格 fakeSku 的 price 字段同样修正为 `product.price || product.salePrice` diff --git a/src/components/business/SkuSelector/index.tsx b/src/components/business/SkuSelector/index.tsx index adbd7d8..e9c9ee0 100644 --- a/src/components/business/SkuSelector/index.tsx +++ b/src/components/business/SkuSelector/index.tsx @@ -157,7 +157,7 @@ const SkuSelector: React.FC = ({ const fakeSku: ShopGoodsSku = { id: 0, goodsId: product.goodsId!, - price: product.salePrice || product.price, + price: product.price || product.salePrice, salePrice: product.salePrice || product.price, stock: product.stock, image: product.image, @@ -187,7 +187,11 @@ const SkuSelector: React.FC = ({ } } - const currentPrice = selectedSku?.salePrice || selectedSku?.price || product?.salePrice || product?.price || '0' + // 价格优先级:SKU售价 > SKU原价 > 商品售价 > 商品原价 > 0 + // 注意:ShopGoods 模型中 price=商品价格(低), salePrice=销售/市场价(高) + // ShopGoodsSku 模型中 price=商品价格, salePrice=市场价格(高) + // 统一以 price 为准,salePrice 仅作兜底展示 + const currentPrice = selectedSku?.price || selectedSku?.salePrice || product?.price || product?.salePrice || '0' const currentStock = selectedSku?.stock ?? product?.stock ?? 0 const currentImage = selectedSku?.image || product?.image || (product?.files?.split(',')[0]) || ''