|
|
@ -3828,28 +3828,98 @@ Page({ |
|
|
|
|
|
|
|
|
// 获取当前商品的信息
|
|
|
// 获取当前商品的信息
|
|
|
const currentGoods = this.data.goodsDetail; |
|
|
const currentGoods = this.data.goodsDetail; |
|
|
const currentCategory = currentGoods.category || ''; |
|
|
|
|
|
const currentSpecifications = currentGoods.weightQuantityData || []; |
|
|
const currentSpecifications = currentGoods.weightQuantityData || []; |
|
|
|
|
|
|
|
|
// 找到当前商品种类在选项中的索引,默认为0(全部)
|
|
|
// 品种默认选择全部品种
|
|
|
let defaultCategoryIndex = 0; |
|
|
const selectedCategory = '全部'; |
|
|
if (currentCategory) { |
|
|
|
|
|
const index = this.data.categoryOptions.indexOf(currentCategory); |
|
|
|
|
|
if (index !== -1) { |
|
|
|
|
|
defaultCategoryIndex = index; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 初始化弹窗状态
|
|
|
// 检查规格数量
|
|
|
this.setData({ |
|
|
if (currentSpecifications.length === 1) { |
|
|
showCompareModal: true, |
|
|
// 只有一个规格,直接跳转
|
|
|
compareStep: 1, |
|
|
const selectedSpec = currentSpecifications[0]; |
|
|
selectedCategoryIndex: defaultCategoryIndex, |
|
|
|
|
|
selectedCategory: this.data.categoryOptions[defaultCategoryIndex], |
|
|
// 构建要传递的数据
|
|
|
selectedSpecIndex: 0, |
|
|
const goodsData = { |
|
|
selectedSpec: currentSpecifications.length > 0 ? currentSpecifications[0] : null, |
|
|
id: currentGoods.id || currentGoods.productId, |
|
|
currentSpecifications: currentSpecifications |
|
|
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 |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
|
|
// 存在多个规格,弹出弹窗让用户选择
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showCompareModal: true, |
|
|
|
|
|
compareStep: 2, // 直接显示规格选择步骤
|
|
|
|
|
|
selectedCategory: selectedCategory, |
|
|
|
|
|
selectedSpecIndex: 0, |
|
|
|
|
|
selectedSpec: currentSpecifications.length > 0 ? currentSpecifications[0] : null, |
|
|
|
|
|
currentSpecifications: currentSpecifications |
|
|
|
|
|
}); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 没有规格,直接跳转
|
|
|
|
|
|
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: null |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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' |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 选择品种
|
|
|
// 选择品种
|
|
|
@ -3902,7 +3972,8 @@ Page({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const currentGoods = this.data.goodsDetail; |
|
|
const currentGoods = this.data.goodsDetail; |
|
|
const selectedCategory = this.data.selectedCategory; |
|
|
// 品种默认选择全部品种
|
|
|
|
|
|
const selectedCategory = '全部'; |
|
|
const selectedSpec = this.data.selectedSpec; |
|
|
const selectedSpec = this.data.selectedSpec; |
|
|
|
|
|
|
|
|
// 显示提示信息
|
|
|
// 显示提示信息
|
|
|
|