|
|
@ -43,6 +43,22 @@ function processSpecifications(spec) { |
|
|
return specs; |
|
|
return specs; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 格式化价格,最多显示一位小数
|
|
|
|
|
|
function formatPrice(price) { |
|
|
|
|
|
if (price === null || price === undefined) { |
|
|
|
|
|
return price; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 转换为数字
|
|
|
|
|
|
const numPrice = parseFloat(price); |
|
|
|
|
|
if (isNaN(numPrice)) { |
|
|
|
|
|
return price; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 格式化到一位小数
|
|
|
|
|
|
return numPrice.toFixed(1); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Page({ |
|
|
Page({ |
|
|
data: { |
|
|
data: { |
|
|
// 页面数据
|
|
|
// 页面数据
|
|
|
@ -111,6 +127,22 @@ Page({ |
|
|
if (Array.isArray(goodsData.price)) { |
|
|
if (Array.isArray(goodsData.price)) { |
|
|
goodsData.price = goodsData.price[0]; |
|
|
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); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 保存选择的种类、规格和当前商品数据到页面数据
|
|
|
// 保存选择的种类、规格和当前商品数据到页面数据
|
|
|
@ -305,6 +337,22 @@ Page({ |
|
|
if (Array.isArray(item.price)) { |
|
|
if (Array.isArray(item.price)) { |
|
|
item.price = item.price[0]; |
|
|
item.price = item.price[0]; |
|
|
} |
|
|
} |
|
|
|
|
|
// 格式化价格,最多显示一位小数
|
|
|
|
|
|
item.price = formatPrice(item.price); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 处理原始价格
|
|
|
|
|
|
if (item.originalPrice) { |
|
|
|
|
|
// 如果原始价格是字符串且包含逗号,只取第一个价格
|
|
|
|
|
|
if (typeof item.originalPrice === 'string' && item.originalPrice.includes(',')) { |
|
|
|
|
|
item.originalPrice = item.originalPrice.split(',')[0].trim(); |
|
|
|
|
|
} |
|
|
|
|
|
// 如果原始价格是数组,只取第一个价格
|
|
|
|
|
|
if (Array.isArray(item.originalPrice)) { |
|
|
|
|
|
item.originalPrice = item.originalPrice[0]; |
|
|
|
|
|
} |
|
|
|
|
|
// 格式化原始价格,最多显示一位小数
|
|
|
|
|
|
item.originalPrice = formatPrice(item.originalPrice); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 处理规格信息,将多个净重信息分割成数组
|
|
|
// 处理规格信息,将多个净重信息分割成数组
|
|
|
@ -479,73 +527,101 @@ Page({ |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// 清理 mediaItems 中的 URL,去除反引号和空格
|
|
|
// 清理 mediaItems 中的 URL,去除反引号和空格
|
|
|
// 同时处理 imageUrls 字段,将其转换为 mediaItems 格式
|
|
|
// 同时处理 imageUrls 字段,将其转换为 mediaItems 格式
|
|
|
// 处理库存显示逻辑
|
|
|
// 处理库存显示逻辑
|
|
|
const cleanedGoods = filteredGoods.map(item => { |
|
|
const cleanedGoods = filteredGoods.map(item => { |
|
|
// 首先清理 imageUrls 字段(如果存在)
|
|
|
// 首先清理 imageUrls 字段(如果存在)
|
|
|
if (item.imageUrls && Array.isArray(item.imageUrls)) { |
|
|
if (item.imageUrls && Array.isArray(item.imageUrls)) { |
|
|
item.imageUrls = item.imageUrls.map(url => { |
|
|
item.imageUrls = item.imageUrls.map(url => { |
|
|
return url.trim().replace(/[`]/g, ''); |
|
|
return url.trim().replace(/[`]/g, ''); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 使用processMediaUrls函数处理媒体数据
|
|
|
// 使用processMediaUrls函数处理媒体数据
|
|
|
item.mediaItems = processMediaUrls(item.imageUrls); |
|
|
item.mediaItems = processMediaUrls(item.imageUrls); |
|
|
|
|
|
|
|
|
// 确保图片优先显示:将图片类型的媒体项移到数组前面
|
|
|
// 确保图片优先显示:将图片类型的媒体项移到数组前面
|
|
|
if (item.mediaItems && item.mediaItems.length > 1) { |
|
|
if (item.mediaItems && item.mediaItems.length > 1) { |
|
|
const imageItems = item.mediaItems.filter(media => media.type === 'image'); |
|
|
const imageItems = item.mediaItems.filter(media => media.type === 'image'); |
|
|
const videoItems = item.mediaItems.filter(media => media.type === 'video'); |
|
|
const videoItems = item.mediaItems.filter(media => media.type === 'video'); |
|
|
item.mediaItems = [...imageItems, ...videoItems]; |
|
|
item.mediaItems = [...imageItems, ...videoItems]; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 清理 mediaItems 中的 URL
|
|
|
// 清理 mediaItems 中的 URL
|
|
|
if (item.mediaItems && Array.isArray(item.mediaItems)) { |
|
|
if (item.mediaItems && Array.isArray(item.mediaItems)) { |
|
|
item.mediaItems = item.mediaItems.map(media => { |
|
|
item.mediaItems = item.mediaItems.map(media => { |
|
|
if (media.url) { |
|
|
if (media.url) { |
|
|
// 去除 URL 中的反引号和空格
|
|
|
// 去除 URL 中的反引号和空格
|
|
|
media.url = media.url.trim().replace(/[`]/g, ''); |
|
|
media.url = media.url.trim().replace(/[`]/g, ''); |
|
|
// 确保媒体类型正确
|
|
|
// 确保媒体类型正确
|
|
|
if (!media.type) { |
|
|
if (!media.type) { |
|
|
media.type = isVideoUrl(media.url) ? 'video' : 'image'; |
|
|
media.type = isVideoUrl(media.url) ? 'video' : 'image'; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
return media; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 清理价格字段,确保只显示单一价格
|
|
|
|
|
|
if (item.price) { |
|
|
|
|
|
// 如果价格是字符串且包含逗号,只取第一个价格
|
|
|
|
|
|
if (typeof item.price === 'string' && item.price.includes(',')) { |
|
|
|
|
|
item.price = item.price.split(',')[0].trim(); |
|
|
} |
|
|
} |
|
|
return media; |
|
|
// 如果价格是数组,只取第一个价格
|
|
|
}); |
|
|
if (Array.isArray(item.price)) { |
|
|
} |
|
|
item.price = item.price[0]; |
|
|
|
|
|
} |
|
|
|
|
|
// 格式化价格,最多显示一位小数
|
|
|
|
|
|
item.price = formatPrice(item.price); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 处理规格信息,将多个净重信息分割成数组
|
|
|
// 处理原始价格
|
|
|
item.processedSpecs = []; |
|
|
if (item.originalPrice) { |
|
|
if (item.specification) { |
|
|
// 如果原始价格是字符串且包含逗号,只取第一个价格
|
|
|
item.processedSpecs = processSpecifications(item.specification); |
|
|
if (typeof item.originalPrice === 'string' && item.originalPrice.includes(',')) { |
|
|
} else if (item.weightSpec) { |
|
|
item.originalPrice = item.originalPrice.split(',')[0].trim(); |
|
|
item.processedSpecs = processSpecifications(item.weightSpec); |
|
|
} |
|
|
} else if (item.grossWeight) { |
|
|
// 如果原始价格是数组,只取第一个价格
|
|
|
item.processedSpecs = processSpecifications(item.grossWeight); |
|
|
if (Array.isArray(item.originalPrice)) { |
|
|
} |
|
|
item.originalPrice = item.originalPrice[0]; |
|
|
|
|
|
} |
|
|
|
|
|
// 格式化原始价格,最多显示一位小数
|
|
|
|
|
|
item.originalPrice = formatPrice(item.originalPrice); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 处理库存显示逻辑(参考首页的处理方式)
|
|
|
// 处理规格信息,将多个净重信息分割成数组
|
|
|
const quantity = item.quantity || item.minOrder || item.stock || item.inventory || item.availableStock || item.totalAvailable; |
|
|
item.processedSpecs = []; |
|
|
const totalStock = quantity; |
|
|
if (item.specification) { |
|
|
|
|
|
item.processedSpecs = processSpecifications(item.specification); |
|
|
let displayStock; |
|
|
} else if (item.weightSpec) { |
|
|
if (totalStock >= 10000) { |
|
|
item.processedSpecs = processSpecifications(item.weightSpec); |
|
|
// 库存>=10000时显示"库存充足"
|
|
|
} else if (item.grossWeight) { |
|
|
displayStock = '充足'; |
|
|
item.processedSpecs = processSpecifications(item.grossWeight); |
|
|
} else if (totalStock === 0) { |
|
|
} |
|
|
// 库存=0时显示"暂无"
|
|
|
|
|
|
displayStock = '暂无'; |
|
|
|
|
|
} else { |
|
|
|
|
|
// 其他情况显示具体数字
|
|
|
|
|
|
displayStock = totalStock; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 更新商品的库存显示
|
|
|
// 处理库存显示逻辑(参考首页的处理方式)
|
|
|
item.totalStock = displayStock; |
|
|
const quantity = item.quantity || item.minOrder || item.stock || item.inventory || item.availableStock || item.totalAvailable; |
|
|
item.originalTotalStock = totalStock; |
|
|
const totalStock = quantity; |
|
|
|
|
|
|
|
|
|
|
|
let displayStock; |
|
|
|
|
|
if (totalStock >= 10000) { |
|
|
|
|
|
// 库存>=10000时显示"库存充足"
|
|
|
|
|
|
displayStock = '充足'; |
|
|
|
|
|
} else if (totalStock === 0) { |
|
|
|
|
|
// 库存=0时显示"暂无"
|
|
|
|
|
|
displayStock = '暂无'; |
|
|
|
|
|
} else { |
|
|
|
|
|
// 其他情况显示具体数字
|
|
|
|
|
|
displayStock = totalStock; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return item; |
|
|
// 更新商品的库存显示
|
|
|
}); |
|
|
item.totalStock = displayStock; |
|
|
|
|
|
item.originalTotalStock = totalStock; |
|
|
|
|
|
|
|
|
|
|
|
return item; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
console.log('过滤后的商品列表:', cleanedGoods); |
|
|
console.log('过滤后的商品列表:', cleanedGoods); |
|
|
// 检查商品数据结构
|
|
|
// 检查商品数据结构
|
|
|
|