|
|
|
@ -1365,6 +1365,15 @@ Page({ |
|
|
|
initialTouch: null, // 初始触摸点
|
|
|
|
// 对比价格相关状态
|
|
|
|
showCompareModal: false, // 是否显示对比价格弹窗
|
|
|
|
compareStep: 1, // 当前步骤(1:选择品种,2:选择规格)
|
|
|
|
categoryOptions: ['全部', '绿壳', '粉壳', '褐壳'], // 品种选项
|
|
|
|
categoryIcons: ['🥚', '🥚', '🥚', '🥚'], // 品种图标
|
|
|
|
categoryDescriptions: ['所有品种', '绿壳鸡蛋', '粉壳鸡蛋', '褐壳鸡蛋'], // 品种描述
|
|
|
|
selectedCategoryIndex: 0, // 选中的品种索引
|
|
|
|
selectedCategory: '', // 选中的品种
|
|
|
|
selectedSpecIndex: 0, // 选中的规格索引
|
|
|
|
selectedSpec: null, // 选中的规格
|
|
|
|
currentSpecifications: [], // 当前商品的规格列表
|
|
|
|
activeTab: 'home', // 当前激活的选项卡,'home'表示首页数据,'favorite'表示收藏数据
|
|
|
|
homeGoods: [], // 首页商品数据
|
|
|
|
favoriteGoods: [], // 收藏商品数据
|
|
|
|
@ -3691,7 +3700,7 @@ Page({ |
|
|
|
|
|
|
|
// 对比价格功能:处理按钮点击事件
|
|
|
|
onCompareClick: function () { |
|
|
|
console.log('用户点击了对比价格按钮,准备跳转到对比价格页面'); |
|
|
|
console.log('用户点击了对比价格按钮,准备显示对比价格弹窗'); |
|
|
|
|
|
|
|
// 检查用户登录状态
|
|
|
|
const openid = wx.getStorageSync('openid'); |
|
|
|
@ -3731,110 +3740,135 @@ Page({ |
|
|
|
// 即使失败也不影响主流程
|
|
|
|
}); |
|
|
|
|
|
|
|
// 检查用户身份证认证状态
|
|
|
|
let idcardstatus = ''; |
|
|
|
const users = wx.getStorageSync('users') || {}; |
|
|
|
const userInfo = wx.getStorageSync('userInfo') || {}; |
|
|
|
|
|
|
|
if (userId && users[userId] && users[userId].idcardstatus) { |
|
|
|
idcardstatus = users[userId].idcardstatus; |
|
|
|
} else if (userInfo.idcardstatus) { |
|
|
|
idcardstatus = userInfo.idcardstatus; |
|
|
|
} |
|
|
|
|
|
|
|
console.log('用户身份证认证状态:', idcardstatus); |
|
|
|
|
|
|
|
// 获取当前商品的信息
|
|
|
|
const currentGoods = this.data.goodsDetail; |
|
|
|
const currentCategory = currentGoods.category || ''; |
|
|
|
const currentSpecifications = currentGoods.weightQuantityData || []; |
|
|
|
|
|
|
|
// 定义种类选项
|
|
|
|
const categoryOptions = ['全部', '绿壳', '粉壳', '褐壳', '土鸡蛋']; |
|
|
|
|
|
|
|
// 找到当前商品种类在选项中的索引,默认为0(全部)
|
|
|
|
let defaultCategoryIndex = 0; |
|
|
|
if (currentCategory) { |
|
|
|
const index = categoryOptions.indexOf(currentCategory); |
|
|
|
const index = this.data.categoryOptions.indexOf(currentCategory); |
|
|
|
if (index !== -1) { |
|
|
|
defaultCategoryIndex = index; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 显示种类选择对话框
|
|
|
|
wx.showActionSheet({ |
|
|
|
itemList: categoryOptions, |
|
|
|
success: (categoryRes) => { |
|
|
|
const selectedCategoryIndex = categoryRes.tapIndex; |
|
|
|
const selectedCategory = categoryOptions[selectedCategoryIndex]; |
|
|
|
|
|
|
|
// 构建规格选择列表
|
|
|
|
const specList = currentSpecifications.map((spec, index) => { |
|
|
|
return spec.display || spec.weightSpec || `规格${index + 1}`; |
|
|
|
// 初始化弹窗状态
|
|
|
|
this.setData({ |
|
|
|
showCompareModal: true, |
|
|
|
compareStep: 1, |
|
|
|
selectedCategoryIndex: defaultCategoryIndex, |
|
|
|
selectedCategory: this.data.categoryOptions[defaultCategoryIndex], |
|
|
|
selectedSpecIndex: 0, |
|
|
|
selectedSpec: currentSpecifications.length > 0 ? currentSpecifications[0] : null, |
|
|
|
currentSpecifications: currentSpecifications |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 选择品种
|
|
|
|
selectCategory: function (e) { |
|
|
|
const index = e.currentTarget.dataset.index; |
|
|
|
this.setData({ |
|
|
|
selectedCategoryIndex: index, |
|
|
|
selectedCategory: this.data.categoryOptions[index] |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 选择规格
|
|
|
|
selectSpec: function (e) { |
|
|
|
const index = e.currentTarget.dataset.index; |
|
|
|
this.setData({ |
|
|
|
selectedSpecIndex: index, |
|
|
|
selectedSpec: this.data.currentSpecifications[index] |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 进入下一步
|
|
|
|
nextStep: function () { |
|
|
|
if (!this.data.selectedCategory) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请选择品种', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
compareStep: 2 |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 返回上一步
|
|
|
|
prevStep: function () { |
|
|
|
this.setData({ |
|
|
|
compareStep: 1 |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 确认对比
|
|
|
|
confirmCompare: function () { |
|
|
|
if (!this.data.selectedSpec) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请选择规格', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const currentGoods = this.data.goodsDetail; |
|
|
|
const selectedCategory = this.data.selectedCategory; |
|
|
|
const selectedSpec = this.data.selectedSpec; |
|
|
|
|
|
|
|
// 显示提示信息
|
|
|
|
wx.showToast({ |
|
|
|
title: `已选择${selectedCategory} ${selectedSpec.display}`, |
|
|
|
icon: 'info', |
|
|
|
duration: 1500, |
|
|
|
success: () => { |
|
|
|
setTimeout(() => { |
|
|
|
// 关闭弹窗
|
|
|
|
this.setData({ |
|
|
|
showCompareModal: false |
|
|
|
}); |
|
|
|
|
|
|
|
// 显示规格选择对话框
|
|
|
|
wx.showActionSheet({ |
|
|
|
itemList: specList, |
|
|
|
success: (specRes) => { |
|
|
|
const selectedSpecIndex = specRes.tapIndex; |
|
|
|
const selectedSpec = currentSpecifications[selectedSpecIndex]; |
|
|
|
|
|
|
|
// 显示提示信息
|
|
|
|
// 构建要传递的数据
|
|
|
|
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 |
|
|
|
}; |
|
|
|
|
|
|
|
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: `已选择${selectedCategory} ${selectedSpec.display}`, |
|
|
|
icon: 'info', |
|
|
|
duration: 1500, |
|
|
|
success: () => { |
|
|
|
setTimeout(() => { |
|
|
|
// 构建要传递的数据
|
|
|
|
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 |
|
|
|
}; |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
title: '跳转失败,请稍后重试', |
|
|
|
icon: 'none' |
|
|
|
}); |
|
|
|
}, |
|
|
|
fail: (res) => { |
|
|
|
console.log('选择规格失败:', res); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
fail: (res) => { |
|
|
|
console.log('选择种类失败:', res); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, 1500); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 关闭对比价格弹窗
|
|
|
|
|