|
|
@ -3861,6 +3861,22 @@ Page({ |
|
|
// 只有一个规格,直接跳转
|
|
|
// 只有一个规格,直接跳转
|
|
|
const selectedSpec = currentSpecifications[0]; |
|
|
const selectedSpec = currentSpecifications[0]; |
|
|
|
|
|
|
|
|
|
|
|
// 显示加载提示
|
|
|
|
|
|
wx.showLoading({ |
|
|
|
|
|
title: '正在获取对比数据...', |
|
|
|
|
|
mask: true |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 提取规格信息用于查询
|
|
|
|
|
|
const specification = selectedSpec.weightSpec || selectedSpec.display || ''; |
|
|
|
|
|
console.log('准备通过规格查询商品,规格:', specification); |
|
|
|
|
|
|
|
|
|
|
|
// 调用API获取相同规格的商品数据
|
|
|
|
|
|
API.getProductsBySpecification(specification) |
|
|
|
|
|
.then(comparisonProducts => { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
console.log('获取到的对比商品数据:', comparisonProducts); |
|
|
|
|
|
|
|
|
// 构建要传递的数据
|
|
|
// 构建要传递的数据
|
|
|
const goodsData = { |
|
|
const goodsData = { |
|
|
id: currentGoods.id || currentGoods.productId, |
|
|
id: currentGoods.id || currentGoods.productId, |
|
|
@ -3877,7 +3893,8 @@ Page({ |
|
|
frequency: currentGoods.frequency || 0, |
|
|
frequency: currentGoods.frequency || 0, |
|
|
status: currentGoods.status || 'published', |
|
|
status: currentGoods.status || 'published', |
|
|
totalStock: currentGoods.totalStock || '充足', |
|
|
totalStock: currentGoods.totalStock || '充足', |
|
|
selectedSpec: selectedSpec |
|
|
selectedSpec: selectedSpec, |
|
|
|
|
|
comparisonProducts: comparisonProducts // 添加对比商品数据
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
console.log('准备跳转到对比价格页面,传递的数据:', goodsData); |
|
|
console.log('准备跳转到对比价格页面,传递的数据:', goodsData); |
|
|
@ -3896,6 +3913,48 @@ Page({ |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(error => { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
console.error('获取对比商品数据失败:', error); |
|
|
|
|
|
|
|
|
|
|
|
// 即使获取对比数据失败,也继续跳转到对比价格页面
|
|
|
|
|
|
const goodsData = { |
|
|
|
|
|
id: currentGoods.id || currentGoods.productId, |
|
|
|
|
|
name: currentGoods.name || '', |
|
|
|
|
|
price: currentGoods.price || '', |
|
|
|
|
|
imageUrls: currentGoods.imageUrls || [], |
|
|
|
|
|
region: currentGoods.region || '', |
|
|
|
|
|
weightQuantityData: currentGoods.weightQuantityData || [], |
|
|
|
|
|
category: selectedCategory, |
|
|
|
|
|
yolk: currentGoods.yolk || '', |
|
|
|
|
|
sourceType: currentGoods.sourceType || '', |
|
|
|
|
|
supplyStatus: currentGoods.supplyStatus || '', |
|
|
|
|
|
mediaItems: currentGoods.mediaItems || [], |
|
|
|
|
|
frequency: currentGoods.frequency || 0, |
|
|
|
|
|
status: currentGoods.status || 'published', |
|
|
|
|
|
totalStock: currentGoods.totalStock || '充足', |
|
|
|
|
|
selectedSpec: selectedSpec, |
|
|
|
|
|
comparisonProducts: [] // 空数组,表示获取失败
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
console.log('获取对比数据失败,准备跳转到对比价格页面,传递的数据:', goodsData); |
|
|
|
|
|
|
|
|
|
|
|
// 跳转到对比价格页面
|
|
|
|
|
|
wx.navigateTo({ |
|
|
|
|
|
url: `/pages/compare_price/index?goodsData=${encodeURIComponent(JSON.stringify(goodsData))}`, |
|
|
|
|
|
success: function () { |
|
|
|
|
|
console.log('成功跳转到对比价格页面'); |
|
|
|
|
|
}, |
|
|
|
|
|
fail: function (error) { |
|
|
|
|
|
console.error('跳转到对比价格页面失败:', error); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '跳转失败,请稍后重试', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
} else if (currentSpecifications.length > 1) { |
|
|
} else if (currentSpecifications.length > 1) { |
|
|
// 存在多个规格,弹出弹窗让用户选择
|
|
|
// 存在多个规格,弹出弹窗让用户选择
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
@ -3924,7 +3983,8 @@ Page({ |
|
|
frequency: currentGoods.frequency || 0, |
|
|
frequency: currentGoods.frequency || 0, |
|
|
status: currentGoods.status || 'published', |
|
|
status: currentGoods.status || 'published', |
|
|
totalStock: currentGoods.totalStock || '充足', |
|
|
totalStock: currentGoods.totalStock || '充足', |
|
|
selectedSpec: null |
|
|
selectedSpec: null, |
|
|
|
|
|
comparisonProducts: [] // 空数组,因为没有规格
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
console.log('准备跳转到对比价格页面,传递的数据:', goodsData); |
|
|
console.log('准备跳转到对比价格页面,传递的数据:', goodsData); |
|
|
@ -4000,6 +4060,22 @@ Page({ |
|
|
const selectedCategory = this.data.selectedCategory || currentGoods.category || '全部'; |
|
|
const selectedCategory = this.data.selectedCategory || currentGoods.category || '全部'; |
|
|
const selectedSpec = this.data.selectedSpec; |
|
|
const selectedSpec = this.data.selectedSpec; |
|
|
|
|
|
|
|
|
|
|
|
// 显示加载提示
|
|
|
|
|
|
wx.showLoading({ |
|
|
|
|
|
title: '正在获取对比数据...', |
|
|
|
|
|
mask: true |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 提取规格信息用于查询
|
|
|
|
|
|
const specification = selectedSpec.weightSpec || selectedSpec.display || ''; |
|
|
|
|
|
console.log('准备通过规格查询商品,规格:', specification); |
|
|
|
|
|
|
|
|
|
|
|
// 调用API获取相同规格的商品数据
|
|
|
|
|
|
API.getProductsBySpecification(specification) |
|
|
|
|
|
.then(comparisonProducts => { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
console.log('获取到的对比商品数据:', comparisonProducts); |
|
|
|
|
|
|
|
|
// 显示提示信息
|
|
|
// 显示提示信息
|
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: `已选择${selectedCategory} ${selectedSpec.display}`, |
|
|
title: `已选择${selectedCategory} ${selectedSpec.display}`, |
|
|
@ -4028,7 +4104,8 @@ Page({ |
|
|
frequency: currentGoods.frequency || 0, |
|
|
frequency: currentGoods.frequency || 0, |
|
|
status: currentGoods.status || 'published', |
|
|
status: currentGoods.status || 'published', |
|
|
totalStock: currentGoods.totalStock || '充足', |
|
|
totalStock: currentGoods.totalStock || '充足', |
|
|
selectedSpec: selectedSpec |
|
|
selectedSpec: selectedSpec, |
|
|
|
|
|
comparisonProducts: comparisonProducts // 添加对比商品数据
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
console.log('准备跳转到对比价格页面,传递的数据:', goodsData); |
|
|
console.log('准备跳转到对比价格页面,传递的数据:', goodsData); |
|
|
@ -4050,6 +4127,63 @@ Page({ |
|
|
}, 1500); |
|
|
}, 1500); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(error => { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
console.error('获取对比商品数据失败:', error); |
|
|
|
|
|
|
|
|
|
|
|
// 即使获取对比数据失败,也继续跳转到对比价格页面
|
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: `已选择${selectedCategory} ${selectedSpec.display}`, |
|
|
|
|
|
icon: 'info', |
|
|
|
|
|
duration: 1500, |
|
|
|
|
|
success: () => { |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
// 关闭弹窗
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showCompareModal: false |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 构建要传递的数据
|
|
|
|
|
|
const goodsData = { |
|
|
|
|
|
id: currentGoods.id || currentGoods.productId, |
|
|
|
|
|
name: currentGoods.name || '', |
|
|
|
|
|
price: currentGoods.price || '', |
|
|
|
|
|
imageUrls: currentGoods.imageUrls || [], |
|
|
|
|
|
region: currentGoods.region || '', |
|
|
|
|
|
weightQuantityData: currentGoods.weightQuantityData || [], |
|
|
|
|
|
category: selectedCategory, |
|
|
|
|
|
yolk: currentGoods.yolk || '', |
|
|
|
|
|
sourceType: currentGoods.sourceType || '', |
|
|
|
|
|
supplyStatus: currentGoods.supplyStatus || '', |
|
|
|
|
|
mediaItems: currentGoods.mediaItems || [], |
|
|
|
|
|
frequency: currentGoods.frequency || 0, |
|
|
|
|
|
status: currentGoods.status || 'published', |
|
|
|
|
|
totalStock: currentGoods.totalStock || '充足', |
|
|
|
|
|
selectedSpec: selectedSpec, |
|
|
|
|
|
comparisonProducts: [] // 空数组,表示获取失败
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
console.log('获取对比数据失败,准备跳转到对比价格页面,传递的数据:', goodsData); |
|
|
|
|
|
|
|
|
|
|
|
// 跳转到对比价格页面
|
|
|
|
|
|
wx.navigateTo({ |
|
|
|
|
|
url: `/pages/compare_price/index?goodsData=${encodeURIComponent(JSON.stringify(goodsData))}`, |
|
|
|
|
|
success: function () { |
|
|
|
|
|
console.log('成功跳转到对比价格页面'); |
|
|
|
|
|
}, |
|
|
|
|
|
fail: function (error) { |
|
|
|
|
|
console.error('跳转到对比价格页面失败:', error); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '跳转失败,请稍后重试', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, 1500); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 关闭对比价格弹窗
|
|
|
// 关闭对比价格弹窗
|
|
|
|