diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index 17ec8f2..4884515 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -11,6 +11,20 @@ function getSourceTypeColor(sourceType) { return colorMap[sourceType] || '#4d9dff'; } +// 计算显示价格 - 处理价格字符串,提取第一个价格 +function calculateDisplayPrice(price) { + if (!price) { + return '暂无价格'; + } + if (typeof price === 'string') { + // 支持多种逗号分隔符:英文逗号、中文逗号、全角逗号 + const priceArray = price.split(/[,,、]/).map(item => item.trim()).filter(item => item); + return priceArray[0] || '暂无价格'; + } + // 如果不是字符串,转换为字符串 + return String(price); +} + // 格式化分享标题 - 按优先级: 地区、规格、数量、蛋黄颜色、蛋壳颜色 function formatShareTitle(goodsDetail) { console.log('===== formatShareTitle 开始 ====='); @@ -357,7 +371,7 @@ function processWeightAndQuantityData(weightSpecString, quantityString, specStri display = `${weightSpecDisplay}————售空`; } else { if (price) { - display = `${weightSpecDisplay}【${quantity}件】${price}元`; + display = `${weightSpecDisplay}【${quantity}件】¥${price}元`; } else { display = `${weightSpecDisplay}【${quantity}件】`; } @@ -908,7 +922,8 @@ Page({ productId: productIdStr, // 直接使用数据库字段名 name: product.productName || product.name || '商品名称', - price: product.price, + price: product.price ? String(product.price) : '', + displayPrice: calculateDisplayPrice(product.price), minOrder: product.minOrder || product.quantity, yolk: product.yolk, spec: product.spec || product.specification || '暂无规格', diff --git a/pages/goods-detail/goods-detail.wxml b/pages/goods-detail/goods-detail.wxml index e61f25a..7b7b4e3 100644 --- a/pages/goods-detail/goods-detail.wxml +++ b/pages/goods-detail/goods-detail.wxml @@ -68,7 +68,7 @@ 价格: - {{goodsDetail.price}} + {{goodsDetail.displayPrice}} (可议价) {{item.name}} {{item.specification || item.spec || item.specs || '暂无规格'}} {{item.quantity || '暂无件数'}}件 - 价格: {{item.price}} + 价格: {{item.price.split(',')[0]}} {{item.province || item.region || '暂无地区'}} @@ -290,7 +290,7 @@ {{item.name}} {{item.specification || item.spec || item.specs || '暂无规格'}} {{item.quantity || '暂无件数'}}件 - 价格: {{item.price}} + 价格: {{item.price.split(',')[0]}} {{item.province || item.region || '暂无地区'}}