|
|
|
@ -1,6 +1,16 @@ |
|
|
|
// pages/goods-detail/goods-detail.js
|
|
|
|
const API = require('../../utils/api.js') |
|
|
|
|
|
|
|
// 根据sourceType获取对应的颜色
|
|
|
|
function getSourceTypeColor(sourceType) { |
|
|
|
const colorMap = { |
|
|
|
'三方认证': '#4d9dff', |
|
|
|
'三方未认证': '#ff4d4f', |
|
|
|
'平台货源': '#2ad21f' |
|
|
|
}; |
|
|
|
return colorMap[sourceType] || '#4d9dff'; |
|
|
|
} |
|
|
|
|
|
|
|
// 格式化毛重显示的辅助函数
|
|
|
|
function formatGrossWeight(grossWeight, weight) { |
|
|
|
console.log('===== formatGrossWeight 函数调用 ====='); |
|
|
|
@ -24,6 +34,36 @@ function formatGrossWeight(grossWeight, weight) { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
|
|
|
|
// 提取地区中的省份信息
|
|
|
|
function extractProvince(region) { |
|
|
|
if (!region || typeof region !== 'string') { |
|
|
|
return region; |
|
|
|
} |
|
|
|
|
|
|
|
// 查找各种省份格式的位置
|
|
|
|
const provinceEndIndex = region.indexOf('省'); |
|
|
|
const autonomousRegionEndIndex = region.indexOf('自治区'); |
|
|
|
const municipalityEndIndex = region.indexOf('市'); // 用于直辖市,如北京市、上海市
|
|
|
|
const specialRegionEndIndex = region.indexOf('特别行政区'); // 用于香港、澳门
|
|
|
|
|
|
|
|
if (provinceEndIndex !== -1) { |
|
|
|
// 包含"省"字,提取到"省"字结束
|
|
|
|
return region.substring(0, provinceEndIndex + 1); |
|
|
|
} else if (autonomousRegionEndIndex !== -1) { |
|
|
|
// 包含"自治区",提取到"自治区"结束
|
|
|
|
return region.substring(0, autonomousRegionEndIndex + 3); |
|
|
|
} else if (specialRegionEndIndex !== -1) { |
|
|
|
// 包含"特别行政区",提取到"特别行政区"结束
|
|
|
|
return region.substring(0, specialRegionEndIndex + 5); |
|
|
|
} else if (municipalityEndIndex === 2) { |
|
|
|
// 直辖市(如北京市、上海市),市字在第2个字符位置
|
|
|
|
return region.substring(0, municipalityEndIndex + 1); |
|
|
|
} |
|
|
|
|
|
|
|
// 如果没有找到匹配的格式,返回原字符串
|
|
|
|
return region; |
|
|
|
} |
|
|
|
|
|
|
|
Page({ |
|
|
|
data: { |
|
|
|
goodsDetail: {}, // 当前商品详情
|
|
|
|
@ -128,6 +168,14 @@ Page({ |
|
|
|
// 处理grossWeight为null或无效的情况,返回空字符串以支持文字输入
|
|
|
|
const grossWeightValue = product.grossWeight !== null && product.grossWeight !== undefined ? product.grossWeight : ''; |
|
|
|
|
|
|
|
// 转换supplyStatus字段值
|
|
|
|
let supplyStatusValue = product.supplyStatus || ''; |
|
|
|
// 将"平台货源"、"三方认证"、"三方未认证"修改为"预售"、"现货"
|
|
|
|
if (supplyStatusValue === '平台货源' || supplyStatusValue === '三方认证') { |
|
|
|
supplyStatusValue = '现货'; |
|
|
|
} else if (supplyStatusValue === '三方未认证') { |
|
|
|
supplyStatusValue = '预售'; |
|
|
|
} |
|
|
|
// 转换商品数据格式
|
|
|
|
const formattedGoods = { |
|
|
|
id: productIdStr, |
|
|
|
@ -137,7 +185,7 @@ Page({ |
|
|
|
minOrder: product.minOrder || product.quantity, |
|
|
|
yolk: product.yolk, |
|
|
|
spec: product.spec || product.specification, |
|
|
|
region: product.region, |
|
|
|
region: extractProvince(product.region), |
|
|
|
contact_phone: product.contact_phone || product.contactPhone, |
|
|
|
product_contact: product.product_contact || product.contactName, |
|
|
|
imageUrls: product.imageUrls || product.images || [], |
|
|
|
@ -146,7 +194,10 @@ Page({ |
|
|
|
reservedCount: finalReservationCount, |
|
|
|
created_at: product.created_at || product.createdAt, |
|
|
|
updated_at: product.updated_at || product.updatedAt, |
|
|
|
status: product.status |
|
|
|
status: product.status, |
|
|
|
supplyStatus: supplyStatusValue, |
|
|
|
sourceType: product.sourceType || '', |
|
|
|
sourceTypeColor: getSourceTypeColor(product.sourceType) |
|
|
|
}; |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|