|
|
@ -338,6 +338,22 @@ function formatDateTime(dateString) { |
|
|
return dateString; |
|
|
return dateString; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 格式化价格,解决浮点数精度问题
|
|
|
|
|
|
function formatPrice(price) { |
|
|
|
|
|
if (price === null || price === undefined) { |
|
|
|
|
|
return price; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 转换为数字
|
|
|
|
|
|
const numPrice = parseFloat(price); |
|
|
|
|
|
if (isNaN(numPrice)) { |
|
|
|
|
|
return price; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 格式化到一位小数
|
|
|
|
|
|
return parseFloat(numPrice.toFixed(1)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 格式化北京时间的函数
|
|
|
// 格式化北京时间的函数
|
|
|
function formatBeijingTime(dateString) { |
|
|
function formatBeijingTime(dateString) { |
|
|
if (!dateString) return '未知时间'; |
|
|
if (!dateString) return '未知时间'; |
|
|
@ -793,9 +809,9 @@ Page({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const priceRange = middlePrice < 20 ? 1 : 5; |
|
|
const priceRange = middlePrice < 20 ? 1 : 5; |
|
|
const minPrice = middlePrice - priceRange; |
|
|
const minPrice = formatPrice(middlePrice - priceRange); |
|
|
const maxPrice = middlePrice + priceRange; |
|
|
const maxPrice = formatPrice(middlePrice + priceRange); |
|
|
const defaultPrice = parseFloat(middlePrice.toFixed(2)); |
|
|
const defaultPrice = formatPrice(middlePrice); |
|
|
const priceThreshold = middlePrice < 20 ? 0.1 : 2; |
|
|
const priceThreshold = middlePrice < 20 ? 0.1 : 2; |
|
|
|
|
|
|
|
|
console.log('计算后的价格数据:', { |
|
|
console.log('计算后的价格数据:', { |
|
|
@ -855,9 +871,9 @@ Page({ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const priceRange = middlePrice < 20 ? 1 : 5; |
|
|
const priceRange = middlePrice < 20 ? 1 : 5; |
|
|
const minPrice = middlePrice - priceRange; |
|
|
const minPrice = formatPrice(middlePrice - priceRange); |
|
|
const maxPrice = middlePrice + priceRange; |
|
|
const maxPrice = formatPrice(middlePrice + priceRange); |
|
|
const currentPrice = parseFloat(middlePrice.toFixed(2)); |
|
|
const currentPrice = formatPrice(middlePrice); |
|
|
const priceThreshold = middlePrice < 20 ? 0.3 : 2; |
|
|
const priceThreshold = middlePrice < 20 ? 0.3 : 2; |
|
|
|
|
|
|
|
|
console.log('选择规格 - 价格数据:', { |
|
|
console.log('选择规格 - 价格数据:', { |
|
|
@ -926,7 +942,7 @@ Page({ |
|
|
|
|
|
|
|
|
if (bargainPrice > minPrice) { |
|
|
if (bargainPrice > minPrice) { |
|
|
const step = bargainPrice < 20 ? 0.1 : 1; |
|
|
const step = bargainPrice < 20 ? 0.1 : 1; |
|
|
const newPrice = parseFloat((bargainPrice - step).toFixed(2)); |
|
|
const newPrice = formatPrice(bargainPrice - step); |
|
|
console.log('计算新价格:', newPrice); |
|
|
console.log('计算新价格:', newPrice); |
|
|
this.updatePrice(newPrice); |
|
|
this.updatePrice(newPrice); |
|
|
} |
|
|
} |
|
|
@ -943,7 +959,7 @@ Page({ |
|
|
|
|
|
|
|
|
if (bargainPrice < maxPrice) { |
|
|
if (bargainPrice < maxPrice) { |
|
|
const step = bargainPrice < 20 ? 0.1 : 1; |
|
|
const step = bargainPrice < 20 ? 0.1 : 1; |
|
|
const newPrice = parseFloat((bargainPrice + step).toFixed(2)); |
|
|
const newPrice = formatPrice(bargainPrice + step); |
|
|
console.log('计算新价格:', newPrice); |
|
|
console.log('计算新价格:', newPrice); |
|
|
this.updatePrice(newPrice); |
|
|
this.updatePrice(newPrice); |
|
|
} |
|
|
} |
|
|
@ -954,7 +970,7 @@ Page({ |
|
|
const { minPrice, maxPrice } = this.data; |
|
|
const { minPrice, maxPrice } = this.data; |
|
|
const clampedPrice = Math.max(minPrice, Math.min(maxPrice, newPrice)); |
|
|
const clampedPrice = Math.max(minPrice, Math.min(maxPrice, newPrice)); |
|
|
const progress = ((clampedPrice - minPrice) / (maxPrice - minPrice)) * 100; |
|
|
const progress = ((clampedPrice - minPrice) / (maxPrice - minPrice)) * 100; |
|
|
const finalPrice = parseFloat(clampedPrice.toFixed(2)); |
|
|
const finalPrice = formatPrice(clampedPrice); |
|
|
|
|
|
|
|
|
console.log('更新价格:', { |
|
|
console.log('更新价格:', { |
|
|
inputPrice: newPrice, |
|
|
inputPrice: newPrice, |
|
|
@ -1018,8 +1034,10 @@ Page({ |
|
|
|
|
|
|
|
|
if (!isNaN(price)) { |
|
|
if (!isNaN(price)) { |
|
|
const clampedPrice = Math.max(minPrice, Math.min(maxPrice, price)); |
|
|
const clampedPrice = Math.max(minPrice, Math.min(maxPrice, price)); |
|
|
|
|
|
const formattedPrice = formatPrice(clampedPrice); |
|
|
console.log('计算后的价格:', clampedPrice); |
|
|
console.log('计算后的价格:', clampedPrice); |
|
|
this.updatePrice(clampedPrice); |
|
|
console.log('格式化后的价格:', formattedPrice); |
|
|
|
|
|
this.updatePrice(formattedPrice); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
@ -1056,11 +1074,7 @@ Page({ |
|
|
const priceRange = maxPrice - minPrice; |
|
|
const priceRange = maxPrice - minPrice; |
|
|
let price = minPrice + (progress / 100) * priceRange; |
|
|
let price = minPrice + (progress / 100) * priceRange; |
|
|
|
|
|
|
|
|
if (bargainPrice < 20) { |
|
|
price = formatPrice(price); |
|
|
price = Math.round(price * 10) / 10; |
|
|
|
|
|
} else { |
|
|
|
|
|
price = Math.round(price); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const clampedPrice = Math.max(minPrice, Math.min(maxPrice, price)); |
|
|
const clampedPrice = Math.max(minPrice, Math.min(maxPrice, price)); |
|
|
|
|
|
|
|
|
@ -1365,6 +1379,15 @@ Page({ |
|
|
initialTouch: null, // 初始触摸点
|
|
|
initialTouch: null, // 初始触摸点
|
|
|
// 对比价格相关状态
|
|
|
// 对比价格相关状态
|
|
|
showCompareModal: false, // 是否显示对比价格弹窗
|
|
|
showCompareModal: false, // 是否显示对比价格弹窗
|
|
|
|
|
|
compareStep: 1, // 当前步骤(1:选择品种,2:选择规格)
|
|
|
|
|
|
categoryOptions: ['全部', '绿壳', '粉壳', '褐壳'], // 品种选项
|
|
|
|
|
|
categoryIcons: ['🥚', '🥚', '🥚', '🥚'], // 品种图标
|
|
|
|
|
|
categoryDescriptions: ['(所有品种)', '(绿壳鸡蛋)', '(粉壳鸡蛋)', '(褐壳鸡蛋)'], // 品种描述
|
|
|
|
|
|
selectedCategoryIndex: 0, // 选中的品种索引
|
|
|
|
|
|
selectedCategory: '', // 选中的品种
|
|
|
|
|
|
selectedSpecIndex: 0, // 选中的规格索引
|
|
|
|
|
|
selectedSpec: null, // 选中的规格
|
|
|
|
|
|
currentSpecifications: [], // 当前商品的规格列表
|
|
|
activeTab: 'home', // 当前激活的选项卡,'home'表示首页数据,'favorite'表示收藏数据
|
|
|
activeTab: 'home', // 当前激活的选项卡,'home'表示首页数据,'favorite'表示收藏数据
|
|
|
homeGoods: [], // 首页商品数据
|
|
|
homeGoods: [], // 首页商品数据
|
|
|
favoriteGoods: [], // 收藏商品数据
|
|
|
favoriteGoods: [], // 收藏商品数据
|
|
|
@ -3745,7 +3768,7 @@ Page({ |
|
|
|
|
|
|
|
|
// 对比价格功能:处理按钮点击事件
|
|
|
// 对比价格功能:处理按钮点击事件
|
|
|
onCompareClick: function () { |
|
|
onCompareClick: function () { |
|
|
console.log('用户点击了对比价格按钮,准备跳转到对比价格页面'); |
|
|
console.log('用户点击了对比价格按钮,准备显示对比价格弹窗'); |
|
|
|
|
|
|
|
|
// 检查用户登录状态
|
|
|
// 检查用户登录状态
|
|
|
const openid = wx.getStorageSync('openid'); |
|
|
const openid = wx.getStorageSync('openid'); |
|
|
@ -3785,110 +3808,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 currentGoods = this.data.goodsDetail; |
|
|
const currentCategory = currentGoods.category || ''; |
|
|
const currentCategory = currentGoods.category || ''; |
|
|
const currentSpecifications = currentGoods.weightQuantityData || []; |
|
|
const currentSpecifications = currentGoods.weightQuantityData || []; |
|
|
|
|
|
|
|
|
// 定义种类选项
|
|
|
|
|
|
const categoryOptions = ['全部', '绿壳', '粉壳', '褐壳', '土鸡蛋']; |
|
|
|
|
|
|
|
|
|
|
|
// 找到当前商品种类在选项中的索引,默认为0(全部)
|
|
|
// 找到当前商品种类在选项中的索引,默认为0(全部)
|
|
|
let defaultCategoryIndex = 0; |
|
|
let defaultCategoryIndex = 0; |
|
|
if (currentCategory) { |
|
|
if (currentCategory) { |
|
|
const index = categoryOptions.indexOf(currentCategory); |
|
|
const index = this.data.categoryOptions.indexOf(currentCategory); |
|
|
if (index !== -1) { |
|
|
if (index !== -1) { |
|
|
defaultCategoryIndex = index; |
|
|
defaultCategoryIndex = index; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 显示种类选择对话框
|
|
|
// 初始化弹窗状态
|
|
|
wx.showActionSheet({ |
|
|
this.setData({ |
|
|
itemList: categoryOptions, |
|
|
showCompareModal: true, |
|
|
success: (categoryRes) => { |
|
|
compareStep: 1, |
|
|
const selectedCategoryIndex = categoryRes.tapIndex; |
|
|
selectedCategoryIndex: defaultCategoryIndex, |
|
|
const selectedCategory = categoryOptions[selectedCategoryIndex]; |
|
|
selectedCategory: this.data.categoryOptions[defaultCategoryIndex], |
|
|
|
|
|
selectedSpecIndex: 0, |
|
|
|
|
|
selectedSpec: currentSpecifications.length > 0 ? currentSpecifications[0] : null, |
|
|
|
|
|
currentSpecifications: currentSpecifications |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
// 构建规格选择列表
|
|
|
// 选择品种
|
|
|
const specList = currentSpecifications.map((spec, index) => { |
|
|
selectCategory: function (e) { |
|
|
return spec.display || spec.weightSpec || `规格${index + 1}`; |
|
|
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({ |
|
|
const goodsData = { |
|
|
itemList: specList, |
|
|
id: currentGoods.id || currentGoods.productId, |
|
|
success: (specRes) => { |
|
|
name: currentGoods.name || '', |
|
|
const selectedSpecIndex = specRes.tapIndex; |
|
|
price: currentGoods.price || '', |
|
|
const selectedSpec = currentSpecifications[selectedSpecIndex]; |
|
|
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.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))}`, |
|
|
wx.navigateTo({ |
|
|
success: function () { |
|
|
url: `/pages/compare_price/index?goodsData=${encodeURIComponent(JSON.stringify(goodsData))}`, |
|
|
console.log('成功跳转到对比价格页面'); |
|
|
success: function () { |
|
|
|
|
|
console.log('成功跳转到对比价格页面'); |
|
|
|
|
|
}, |
|
|
|
|
|
fail: function (error) { |
|
|
|
|
|
console.error('跳转到对比价格页面失败:', error); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '跳转失败,请稍后重试', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, 1500); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
}, |
|
|
fail: (res) => { |
|
|
fail: function (error) { |
|
|
console.log('选择规格失败:', res); |
|
|
console.error('跳转到对比价格页面失败:', error); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '跳转失败,请稍后重试', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, 1500); |
|
|
fail: (res) => { |
|
|
} |
|
|
console.log('选择种类失败:', res); |
|
|
}); |
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 关闭对比价格弹窗
|
|
|
// 关闭对比价格弹窗
|
|
|
|