|
|
|
@ -127,22 +127,6 @@ Page({ |
|
|
|
if (Array.isArray(goodsData.price)) { |
|
|
|
goodsData.price = goodsData.price[0]; |
|
|
|
} |
|
|
|
// 格式化价格,最多显示一位小数
|
|
|
|
goodsData.price = formatPrice(goodsData.price); |
|
|
|
} |
|
|
|
|
|
|
|
// 处理原始价格
|
|
|
|
if (goodsData.originalPrice) { |
|
|
|
// 如果原始价格是字符串且包含逗号,只取第一个价格
|
|
|
|
if (typeof goodsData.originalPrice === 'string' && goodsData.originalPrice.includes(',')) { |
|
|
|
goodsData.originalPrice = goodsData.originalPrice.split(',')[0].trim(); |
|
|
|
} |
|
|
|
// 如果原始价格是数组,只取第一个价格
|
|
|
|
if (Array.isArray(goodsData.originalPrice)) { |
|
|
|
goodsData.originalPrice = goodsData.originalPrice[0]; |
|
|
|
} |
|
|
|
// 格式化原始价格,最多显示一位小数
|
|
|
|
goodsData.originalPrice = formatPrice(goodsData.originalPrice); |
|
|
|
} |
|
|
|
|
|
|
|
// 处理当前商品的地区信息,只显示省份
|
|
|
|
@ -287,102 +271,124 @@ Page({ |
|
|
|
} |
|
|
|
|
|
|
|
// 处理商品数据
|
|
|
|
const processedGoods = filteredGoods.map(item => { |
|
|
|
// 首先清理 imageUrls 字段(如果存在)
|
|
|
|
if (item.imageUrls && Array.isArray(item.imageUrls)) { |
|
|
|
item.imageUrls = item.imageUrls.map(url => { |
|
|
|
return url.trim().replace(/[`]/g, ''); |
|
|
|
}); |
|
|
|
|
|
|
|
// 使用processMediaUrls函数处理媒体数据
|
|
|
|
item.mediaItems = processMediaUrls(item.imageUrls); |
|
|
|
|
|
|
|
// 确保图片优先显示:将图片类型的媒体项移到数组前面
|
|
|
|
if (item.mediaItems && item.mediaItems.length > 1) { |
|
|
|
const imageItems = item.mediaItems.filter(media => media.type === 'image'); |
|
|
|
const videoItems = item.mediaItems.filter(media => media.type === 'video'); |
|
|
|
item.mediaItems = [...imageItems, ...videoItems]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 清理 mediaItems 中的 URL
|
|
|
|
if (item.mediaItems && Array.isArray(item.mediaItems)) { |
|
|
|
item.mediaItems = item.mediaItems.map(media => { |
|
|
|
if (media.url) { |
|
|
|
// 去除 URL 中的反引号和空格
|
|
|
|
media.url = media.url.trim().replace(/[`]/g, ''); |
|
|
|
// 确保媒体类型正确
|
|
|
|
if (!media.type) { |
|
|
|
media.type = isVideoUrl(media.url) ? 'video' : 'image'; |
|
|
|
} |
|
|
|
} |
|
|
|
return media; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 处理商品价格,使用选中规格的价格
|
|
|
|
if (specWeight) { |
|
|
|
if (item.weightQuantityData && Array.isArray(item.weightQuantityData)) { |
|
|
|
// 尝试从weightQuantityData中找到对应规格的价格
|
|
|
|
const matchingSpec = item.weightQuantityData.find(spec => { |
|
|
|
if (spec.weightSpec) { |
|
|
|
return spec.weightSpec.trim() === specWeight; |
|
|
|
} |
|
|
|
return false; |
|
|
|
}); |
|
|
|
if (matchingSpec && matchingSpec.price) { |
|
|
|
// 确保价格是一个单一的值,而不是多个价格的组合
|
|
|
|
item.price = matchingSpec.price; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 清理价格字段,确保只显示单一价格
|
|
|
|
if (item.price) { |
|
|
|
// 如果价格是字符串且包含逗号,只取第一个价格
|
|
|
|
if (typeof item.price === 'string' && item.price.includes(',')) { |
|
|
|
item.price = item.price.split(',')[0].trim(); |
|
|
|
} |
|
|
|
// 如果价格是数组,只取第一个价格
|
|
|
|
if (Array.isArray(item.price)) { |
|
|
|
item.price = item.price[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 处理规格信息,将多个净重信息分割成数组
|
|
|
|
item.processedSpecs = []; |
|
|
|
if (item.specification) { |
|
|
|
item.processedSpecs = processSpecifications(item.specification); |
|
|
|
} else if (item.weightSpec) { |
|
|
|
item.processedSpecs = processSpecifications(item.weightSpec); |
|
|
|
} else if (item.grossWeight) { |
|
|
|
item.processedSpecs = processSpecifications(item.grossWeight); |
|
|
|
} else if (selectedSpec) { |
|
|
|
item.processedSpecs = processSpecifications(selectedSpec); |
|
|
|
} |
|
|
|
|
|
|
|
// 处理库存显示逻辑
|
|
|
|
const quantity = item.quantity || item.minOrder || item.stock || item.inventory || item.availableStock || item.totalAvailable; |
|
|
|
const totalStock = quantity; |
|
|
|
|
|
|
|
let displayStock; |
|
|
|
if (totalStock >= 10000) { |
|
|
|
// 库存>=10000时显示"库存充足"
|
|
|
|
displayStock = '充足'; |
|
|
|
} else if (totalStock === 0) { |
|
|
|
// 库存=0时显示"暂无"
|
|
|
|
displayStock = '暂无'; |
|
|
|
} else { |
|
|
|
// 其他情况显示具体数字
|
|
|
|
displayStock = totalStock; |
|
|
|
} |
|
|
|
|
|
|
|
// 更新商品的库存显示
|
|
|
|
item.totalStock = displayStock; |
|
|
|
item.originalTotalStock = totalStock; |
|
|
|
|
|
|
|
return item; |
|
|
|
}); |
|
|
|
const processedGoods = filteredGoods.map(item => { |
|
|
|
// 首先清理 imageUrls 字段(如果存在)
|
|
|
|
if (item.imageUrls && Array.isArray(item.imageUrls)) { |
|
|
|
item.imageUrls = item.imageUrls.map(url => { |
|
|
|
return url.trim().replace(/[`]/g, ''); |
|
|
|
}); |
|
|
|
|
|
|
|
// 使用processMediaUrls函数处理媒体数据
|
|
|
|
item.mediaItems = processMediaUrls(item.imageUrls); |
|
|
|
|
|
|
|
// 确保图片优先显示:将图片类型的媒体项移到数组前面
|
|
|
|
if (item.mediaItems && item.mediaItems.length > 1) { |
|
|
|
const imageItems = item.mediaItems.filter(media => media.type === 'image'); |
|
|
|
const videoItems = item.mediaItems.filter(media => media.type === 'video'); |
|
|
|
item.mediaItems = [...imageItems, ...videoItems]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 清理 mediaItems 中的 URL
|
|
|
|
if (item.mediaItems && Array.isArray(item.mediaItems)) { |
|
|
|
item.mediaItems = item.mediaItems.map(media => { |
|
|
|
if (media.url) { |
|
|
|
// 去除 URL 中的反引号和空格
|
|
|
|
media.url = media.url.trim().replace(/[`]/g, ''); |
|
|
|
// 确保媒体类型正确
|
|
|
|
if (!media.type) { |
|
|
|
media.type = isVideoUrl(media.url) ? 'video' : 'image'; |
|
|
|
} |
|
|
|
} |
|
|
|
return media; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 处理商品价格,使用选中规格的价格
|
|
|
|
if (specWeight) { |
|
|
|
if (item.weightQuantityData && Array.isArray(item.weightQuantityData)) { |
|
|
|
// 尝试从weightQuantityData中找到对应规格的价格
|
|
|
|
const matchingSpec = item.weightQuantityData.find(spec => { |
|
|
|
if (spec.weightSpec) { |
|
|
|
return spec.weightSpec.trim() === specWeight; |
|
|
|
} |
|
|
|
return false; |
|
|
|
}); |
|
|
|
if (matchingSpec && matchingSpec.price) { |
|
|
|
// 确保价格是一个单一的值,而不是多个价格的组合
|
|
|
|
item.price = matchingSpec.price; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 清理价格字段,确保只显示单一价格
|
|
|
|
if (item.price) { |
|
|
|
// 如果价格是字符串且包含逗号,只取第一个价格
|
|
|
|
if (typeof item.price === 'string' && item.price.includes(',')) { |
|
|
|
item.price = item.price.split(',')[0].trim(); |
|
|
|
} |
|
|
|
// 如果价格是数组,只取第一个价格
|
|
|
|
if (Array.isArray(item.price)) { |
|
|
|
item.price = item.price[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 处理规格信息,将多个净重信息分割成数组
|
|
|
|
item.processedSpecs = []; |
|
|
|
if (item.specification) { |
|
|
|
item.processedSpecs = processSpecifications(item.specification); |
|
|
|
} else if (item.weightSpec) { |
|
|
|
item.processedSpecs = processSpecifications(item.weightSpec); |
|
|
|
} else if (item.grossWeight) { |
|
|
|
item.processedSpecs = processSpecifications(item.grossWeight); |
|
|
|
} else if (selectedSpec) { |
|
|
|
item.processedSpecs = processSpecifications(selectedSpec); |
|
|
|
} |
|
|
|
|
|
|
|
// 处理库存显示逻辑
|
|
|
|
const quantity = item.quantity || item.minOrder || item.stock || item.inventory || item.availableStock || item.totalAvailable; |
|
|
|
const totalStock = quantity; |
|
|
|
|
|
|
|
let displayStock; |
|
|
|
if (totalStock >= 10000) { |
|
|
|
// 库存>=10000时显示"库存充足"
|
|
|
|
displayStock = '充足'; |
|
|
|
} else if (totalStock === 0) { |
|
|
|
// 库存=0时显示"暂无"
|
|
|
|
displayStock = '暂无'; |
|
|
|
} else { |
|
|
|
// 其他情况显示具体数字
|
|
|
|
displayStock = totalStock; |
|
|
|
} |
|
|
|
|
|
|
|
// 更新商品的库存显示
|
|
|
|
item.totalStock = displayStock; |
|
|
|
item.originalTotalStock = totalStock; |
|
|
|
|
|
|
|
// 处理地区信息,只显示省份
|
|
|
|
if (item.region) { |
|
|
|
// 提取省份信息
|
|
|
|
const provinceRegex = /^([^省]+省|[^自治区]+自治区|[^直辖市]+直辖市|[^特别行政区]+特别行政区)/; |
|
|
|
const match = item.region.match(provinceRegex); |
|
|
|
if (match) { |
|
|
|
item.region = match[1]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 计算价格涨幅
|
|
|
|
if (goodsData.price) { |
|
|
|
const currentPrice = parseFloat(goodsData.price); |
|
|
|
const itemPrice = parseFloat(item.price); |
|
|
|
if (!isNaN(currentPrice) && !isNaN(itemPrice)) { |
|
|
|
const priceDiff = itemPrice - currentPrice; |
|
|
|
const pricePercent = ((priceDiff / currentPrice) * 100).toFixed(1); |
|
|
|
item.priceDiff = priceDiff; |
|
|
|
item.pricePercent = pricePercent; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return item; |
|
|
|
}); |
|
|
|
|
|
|
|
// 显示提示信息
|
|
|
|
wx.showToast({ |
|
|
|
|