|
|
|
@ -303,6 +303,40 @@ function checkLoginStatus() { |
|
|
|
return !!(openid && userId); |
|
|
|
} |
|
|
|
|
|
|
|
// 格式化日期时间函数
|
|
|
|
function formatDateTime(dateString) { |
|
|
|
if (!dateString) return ''; |
|
|
|
|
|
|
|
// 尝试解析日期字符串
|
|
|
|
const date = new Date(dateString); |
|
|
|
|
|
|
|
// 检查是否是有效的日期对象
|
|
|
|
if (isNaN(date.getTime())) { |
|
|
|
// 如果解析失败,返回原始字符串
|
|
|
|
return dateString; |
|
|
|
} |
|
|
|
|
|
|
|
// 如果是 ISO 格式的字符串(包含 T 字符),则转换为本地时间格式,只保留日期部分
|
|
|
|
if (typeof dateString === 'string' && dateString.includes('T')) { |
|
|
|
const year = date.getFullYear(); |
|
|
|
const month = (date.getMonth() + 1).toString().padStart(2, '0'); |
|
|
|
const day = date.getDate().toString().padStart(2, '0'); |
|
|
|
return `${year}-${month}-${day}`; |
|
|
|
} |
|
|
|
|
|
|
|
// 对于其他格式的字符串,尝试提取日期部分
|
|
|
|
if (typeof dateString === 'string') { |
|
|
|
// 检查是否包含空格,提取空格前的日期部分
|
|
|
|
const spaceIndex = dateString.indexOf(' '); |
|
|
|
if (spaceIndex !== -1) { |
|
|
|
return dateString.substring(0, spaceIndex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 如果以上都不匹配,直接返回
|
|
|
|
return dateString; |
|
|
|
} |
|
|
|
|
|
|
|
// 处理净重、件数、规格和价格数据,将逗号分隔的字符串转换为一一对应的数组
|
|
|
|
function processWeightAndQuantityData(weightSpecString, quantityString, specString, priceString) { |
|
|
|
console.log('===== 处理净重、件数、规格和价格数据 ====='); |
|
|
|
@ -2484,12 +2518,17 @@ Page({ |
|
|
|
// 提取省份信息
|
|
|
|
const province = extractProvince(goods.region || ''); |
|
|
|
|
|
|
|
// 格式化日期
|
|
|
|
const updatedAt = goods.updated_at || goods.updatedAt; |
|
|
|
const formattedDate = formatDateTime(updatedAt); |
|
|
|
|
|
|
|
return { |
|
|
|
...goods, |
|
|
|
price: priceString, // 确保price字段是字符串类型
|
|
|
|
mediaItems: processMediaUrls(goods.imageUrls), |
|
|
|
weightQuantityData: weightQuantityData, |
|
|
|
province: province // 添加省份字段
|
|
|
|
province: province, // 添加省份字段
|
|
|
|
formattedDate: formattedDate // 添加格式化的日期字段
|
|
|
|
}; |
|
|
|
}).filter(goods => { |
|
|
|
// 只有当当前商品有明确的规格时才进行筛选
|
|
|
|
@ -2697,12 +2736,17 @@ Page({ |
|
|
|
// 处理数据
|
|
|
|
const weightQuantityData = processWeightAndQuantityData(weightSpecString, quantityString, '', priceString); |
|
|
|
|
|
|
|
// 格式化日期
|
|
|
|
const updatedAt = product.updated_at || product.updatedAt; |
|
|
|
const formattedDate = formatDateTime(updatedAt); |
|
|
|
|
|
|
|
return { |
|
|
|
...product, |
|
|
|
price: priceString, // 确保price字段是字符串类型
|
|
|
|
mediaItems: processMediaUrls(product.imageUrls), |
|
|
|
province: province, // 添加省份字段
|
|
|
|
weightQuantityData: weightQuantityData // 添加价格处理数据
|
|
|
|
weightQuantityData: weightQuantityData, // 添加价格处理数据
|
|
|
|
formattedDate: formattedDate // 添加格式化的日期字段
|
|
|
|
}; |
|
|
|
}); |
|
|
|
console.log('所有商品详情获取完成,有效商品数量:', validProducts.length); |
|
|
|
@ -2754,12 +2798,17 @@ Page({ |
|
|
|
// 处理数据
|
|
|
|
const weightQuantityData = processWeightAndQuantityData(weightSpecString, quantityString, '', priceString); |
|
|
|
|
|
|
|
// 格式化日期
|
|
|
|
const updatedAt = product.updated_at || product.updatedAt; |
|
|
|
const formattedDate = formatDateTime(updatedAt); |
|
|
|
|
|
|
|
return { |
|
|
|
...product, |
|
|
|
price: priceString, // 确保price字段是字符串类型
|
|
|
|
mediaItems: processMediaUrls(product.imageUrls), |
|
|
|
province: province, // 添加省份字段
|
|
|
|
weightQuantityData: weightQuantityData // 添加价格处理数据
|
|
|
|
weightQuantityData: weightQuantityData, // 添加价格处理数据
|
|
|
|
formattedDate: formattedDate // 添加格式化的日期字段
|
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
|