fix(SkuSelector): 修正价格显示逻辑避免价格错误

- 调整fakeSku中price字段优先使用product.price,确保价格正确显示
- 修改currentPrice计算顺序,使price优先于salePrice,符合实际售价需求
- 统一价格逻辑,避免SKU弹窗和商品详情页价格不一致问题
- 添加注释说明ShopGoods和ShopGoodsSku中price与salePrice的区别及优先级规则
This commit is contained in:
2026-06-27 00:41:03 +08:00
parent 7f43897a64
commit f7c11889fe
2 changed files with 15 additions and 2 deletions

View File

@@ -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`

View File

@@ -157,7 +157,7 @@ const SkuSelector: React.FC<SkuSelectorProps> = ({
const fakeSku: ShopGoodsSku = { const fakeSku: ShopGoodsSku = {
id: 0, id: 0,
goodsId: product.goodsId!, goodsId: product.goodsId!,
price: product.salePrice || product.price, price: product.price || product.salePrice,
salePrice: product.salePrice || product.price, salePrice: product.salePrice || product.price,
stock: product.stock, stock: product.stock,
image: product.image, image: product.image,
@@ -187,7 +187,11 @@ const SkuSelector: React.FC<SkuSelectorProps> = ({
} }
} }
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 currentStock = selectedSku?.stock ?? product?.stock ?? 0
const currentImage = selectedSku?.image || product?.image || (product?.files?.split(',')[0]) || '' const currentImage = selectedSku?.image || product?.image || (product?.files?.split(',')[0]) || ''