fix(SkuSelector): 修正价格显示逻辑避免价格错误
- 调整fakeSku中price字段优先使用product.price,确保价格正确显示 - 修改currentPrice计算顺序,使price优先于salePrice,符合实际售价需求 - 统一价格逻辑,避免SKU弹窗和商品详情页价格不一致问题 - 添加注释说明ShopGoods和ShopGoodsSku中price与salePrice的区别及优先级规则
This commit is contained in:
@@ -157,7 +157,7 @@ const SkuSelector: React.FC<SkuSelectorProps> = ({
|
||||
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<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 currentImage = selectedSku?.image || product?.image || (product?.files?.split(',')[0]) || ''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user