|
|
|
@ -727,18 +727,124 @@ Page({ |
|
|
|
|
|
|
|
// 显示讲价弹窗
|
|
|
|
showBargainModal() { |
|
|
|
console.log('===== 显示讲价弹窗开始 ====='); |
|
|
|
console.log('当前 goodsDetail:', this.data.goodsDetail); |
|
|
|
|
|
|
|
const weightQuantityData = this.data.goodsDetail.weightQuantityData || []; |
|
|
|
console.log('weightQuantityData:', weightQuantityData); |
|
|
|
|
|
|
|
let middlePrice = 800; // 默认值
|
|
|
|
|
|
|
|
if (weightQuantityData.length > 0) { |
|
|
|
const selectedSpec = weightQuantityData[0]; |
|
|
|
console.log('选中的规格:', selectedSpec); |
|
|
|
|
|
|
|
if (selectedSpec) { |
|
|
|
// 尝试从多个可能的价格字段获取价格
|
|
|
|
let priceValue = selectedSpec.price; |
|
|
|
console.log('从 price 字段获取价格:', priceValue); |
|
|
|
|
|
|
|
if (!priceValue && selectedSpec.display) { |
|
|
|
// 从display字段中提取价格,支持多种格式
|
|
|
|
// 匹配 ¥156元、¥156元、¥156、¥156 等格式
|
|
|
|
const priceMatch = selectedSpec.display.match(/[¥¥]([0-9.]+)/); |
|
|
|
console.log('从 display 字段提取价格:', priceMatch); |
|
|
|
if (priceMatch && priceMatch[1]) { |
|
|
|
priceValue = priceMatch[1]; |
|
|
|
console.log('提取到的价格:', priceValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (priceValue) { |
|
|
|
// 提取价格数字
|
|
|
|
const priceStr = priceValue.toString(); |
|
|
|
const priceNum = parseFloat(priceStr.replace(/[^0-9.]/g, '')); |
|
|
|
console.log('价格字符串:', priceStr); |
|
|
|
console.log('解析后的价格数字:', priceNum); |
|
|
|
|
|
|
|
if (!isNaN(priceNum)) { |
|
|
|
middlePrice = priceNum; |
|
|
|
console.log('设置 middlePrice 为:', middlePrice); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const minPrice = middlePrice - 5; |
|
|
|
const maxPrice = middlePrice + 5; |
|
|
|
const defaultPrice = parseFloat(middlePrice.toFixed(2)); |
|
|
|
|
|
|
|
console.log('计算后的价格数据:', { |
|
|
|
middlePrice: middlePrice, |
|
|
|
minPrice: minPrice, |
|
|
|
maxPrice: maxPrice, |
|
|
|
defaultPrice: defaultPrice |
|
|
|
}); |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
showBargainModal: true, |
|
|
|
bargainPrice: '', |
|
|
|
selectedSpecIndex: 0 // 默认选中第一条规格
|
|
|
|
bargainPrice: defaultPrice, |
|
|
|
selectedSpecIndex: 0, // 默认选中第一条规格
|
|
|
|
minPrice: minPrice, |
|
|
|
maxPrice: maxPrice, |
|
|
|
sliderProgress: 50 // 默认滑块位置
|
|
|
|
}, () => { |
|
|
|
console.log('setData 完成后的 bargainPrice:', this.data.bargainPrice); |
|
|
|
console.log('setData 完成后的 minPrice:', this.data.minPrice); |
|
|
|
console.log('setData 完成后的 maxPrice:', this.data.maxPrice); |
|
|
|
console.log('===== 显示讲价弹窗结束 ====='); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 选择规格
|
|
|
|
selectSpec(e) { |
|
|
|
const index = e.currentTarget.dataset.index; |
|
|
|
const weightQuantityData = this.data.goodsDetail.weightQuantityData || []; |
|
|
|
let middlePrice = 800; // 默认值
|
|
|
|
|
|
|
|
if (weightQuantityData.length > index) { |
|
|
|
const selectedSpec = weightQuantityData[index]; |
|
|
|
if (selectedSpec) { |
|
|
|
// 尝试从多个可能的价格字段获取价格
|
|
|
|
let priceValue = selectedSpec.price; |
|
|
|
if (!priceValue && selectedSpec.display) { |
|
|
|
// 从display字段中提取价格,支持多种格式
|
|
|
|
// 匹配 ¥156元、¥156元、¥156、¥156 等格式
|
|
|
|
const priceMatch = selectedSpec.display.match(/[¥¥]([0-9.]+)/); |
|
|
|
if (priceMatch && priceMatch[1]) { |
|
|
|
priceValue = priceMatch[1]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (priceValue) { |
|
|
|
// 提取价格数字
|
|
|
|
const priceStr = priceValue.toString(); |
|
|
|
const priceNum = parseFloat(priceStr.replace(/[^0-9.]/g, '')); |
|
|
|
if (!isNaN(priceNum)) { |
|
|
|
middlePrice = priceNum; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const minPrice = middlePrice - 5; |
|
|
|
const maxPrice = middlePrice + 5; |
|
|
|
const currentPrice = parseFloat(middlePrice.toFixed(2)); |
|
|
|
|
|
|
|
console.log('选择规格 - 价格数据:', { |
|
|
|
index: index, |
|
|
|
middlePrice: middlePrice, |
|
|
|
minPrice: minPrice, |
|
|
|
maxPrice: maxPrice, |
|
|
|
currentPrice: currentPrice |
|
|
|
}); |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
selectedSpecIndex: index |
|
|
|
selectedSpecIndex: index, |
|
|
|
minPrice: minPrice, |
|
|
|
maxPrice: maxPrice, |
|
|
|
bargainPrice: currentPrice, |
|
|
|
sliderProgress: 50 |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
@ -750,11 +856,163 @@ Page({ |
|
|
|
// 隐藏讲价弹窗
|
|
|
|
hideBargainModal() { |
|
|
|
this.setData({ |
|
|
|
showBargainModal: false, |
|
|
|
bargainPrice: '' |
|
|
|
showBargainModal: false |
|
|
|
// 不重置 bargainPrice,保持其数字类型
|
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 减少价格
|
|
|
|
decreasePrice() { |
|
|
|
const { bargainPrice, minPrice } = this.data; |
|
|
|
console.log('减少价格:', { |
|
|
|
bargainPrice: bargainPrice, |
|
|
|
minPrice: minPrice, |
|
|
|
canDecrease: bargainPrice > minPrice |
|
|
|
}); |
|
|
|
|
|
|
|
if (bargainPrice > minPrice) { |
|
|
|
const newPrice = parseFloat((bargainPrice - 1).toFixed(2)); |
|
|
|
console.log('计算新价格:', newPrice); |
|
|
|
this.updatePrice(newPrice); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 增加价格
|
|
|
|
increasePrice() { |
|
|
|
const { bargainPrice, maxPrice } = this.data; |
|
|
|
console.log('增加价格:', { |
|
|
|
bargainPrice: bargainPrice, |
|
|
|
maxPrice: maxPrice, |
|
|
|
canIncrease: bargainPrice < maxPrice |
|
|
|
}); |
|
|
|
|
|
|
|
if (bargainPrice < maxPrice) { |
|
|
|
const newPrice = parseFloat((bargainPrice + 1).toFixed(2)); |
|
|
|
console.log('计算新价格:', newPrice); |
|
|
|
this.updatePrice(newPrice); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 更新价格和滑块位置
|
|
|
|
updatePrice(newPrice) { |
|
|
|
const { minPrice, maxPrice } = this.data; |
|
|
|
const clampedPrice = Math.max(minPrice, Math.min(maxPrice, newPrice)); |
|
|
|
const progress = ((clampedPrice - minPrice) / (maxPrice - minPrice)) * 100; |
|
|
|
const finalPrice = parseFloat(clampedPrice.toFixed(2)); |
|
|
|
|
|
|
|
console.log('更新价格:', { |
|
|
|
inputPrice: newPrice, |
|
|
|
clampedPrice: clampedPrice, |
|
|
|
finalPrice: finalPrice, |
|
|
|
progress: progress |
|
|
|
}); |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
bargainPrice: finalPrice, |
|
|
|
sliderProgress: Math.max(0, Math.min(100, progress)) |
|
|
|
}, () => { |
|
|
|
console.log('价格更新完成:', this.data.bargainPrice); |
|
|
|
console.log('bargainPrice 类型:', typeof this.data.bargainPrice); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 显示价格输入弹窗
|
|
|
|
showPriceInput() { |
|
|
|
const currentPrice = this.data.bargainPrice; |
|
|
|
const priceStr = !isNaN(currentPrice) ? currentPrice.toString() : '0'; |
|
|
|
|
|
|
|
console.log('显示价格输入弹窗:', { |
|
|
|
currentPrice: currentPrice, |
|
|
|
priceStr: priceStr |
|
|
|
}); |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
showPriceInputModal: true, |
|
|
|
tempPrice: priceStr |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 临时价格输入处理
|
|
|
|
onTempPriceInput(e) { |
|
|
|
this.setData({ |
|
|
|
tempPrice: e.detail.value |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 取消价格输入
|
|
|
|
cancelPriceInput() { |
|
|
|
this.setData({ |
|
|
|
showPriceInputModal: false, |
|
|
|
tempPrice: '' |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 确认价格输入
|
|
|
|
confirmPriceInput() { |
|
|
|
const { tempPrice, minPrice, maxPrice } = this.data; |
|
|
|
const price = parseFloat(tempPrice); |
|
|
|
|
|
|
|
console.log('确认价格输入:', { |
|
|
|
tempPrice: tempPrice, |
|
|
|
price: price, |
|
|
|
minPrice: minPrice, |
|
|
|
maxPrice: maxPrice, |
|
|
|
isPriceValid: !isNaN(price) |
|
|
|
}); |
|
|
|
|
|
|
|
if (!isNaN(price)) { |
|
|
|
const clampedPrice = Math.max(minPrice, Math.min(maxPrice, price)); |
|
|
|
console.log('计算后的价格:', clampedPrice); |
|
|
|
this.updatePrice(clampedPrice); |
|
|
|
} |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
showPriceInputModal: false, |
|
|
|
tempPrice: '' |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
// 滑块开始触摸
|
|
|
|
onSliderStart(e) { |
|
|
|
// 可以在这里添加触摸开始的逻辑
|
|
|
|
}, |
|
|
|
|
|
|
|
// 滑块移动
|
|
|
|
onSliderMove(e) { |
|
|
|
try { |
|
|
|
const { minPrice, maxPrice } = this.data; |
|
|
|
if (!minPrice || !maxPrice) return; |
|
|
|
|
|
|
|
const touch = e.touches[0]; |
|
|
|
if (!touch) return; |
|
|
|
|
|
|
|
const clientX = touch.clientX; |
|
|
|
|
|
|
|
const screenWidth = wx.getWindowInfo().windowWidth; |
|
|
|
const sliderWidth = screenWidth * 0.8; |
|
|
|
const sliderLeft = (screenWidth - sliderWidth) / 2; |
|
|
|
|
|
|
|
let progress = ((clientX - sliderLeft) / sliderWidth) * 100; |
|
|
|
progress = Math.max(0, Math.min(100, progress)); |
|
|
|
|
|
|
|
const priceRange = maxPrice - minPrice; |
|
|
|
const price = Math.round(minPrice + (progress / 100) * priceRange); |
|
|
|
const clampedPrice = Math.max(minPrice, Math.min(maxPrice, price)); |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
sliderProgress: progress, |
|
|
|
bargainPrice: clampedPrice |
|
|
|
}); |
|
|
|
} catch (error) { |
|
|
|
console.error('滑块移动错误:', error); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
// 滑块结束触摸
|
|
|
|
onSliderEnd(e) { |
|
|
|
// 可以在这里添加触摸结束的逻辑
|
|
|
|
}, |
|
|
|
|
|
|
|
// 讲价输入处理
|
|
|
|
onBargainInput(e) { |
|
|
|
this.setData({ |
|
|
|
@ -765,7 +1023,7 @@ Page({ |
|
|
|
// 提交讲价
|
|
|
|
submitBargain() { |
|
|
|
const bargainPrice = this.data.bargainPrice; |
|
|
|
if (!bargainPrice) { |
|
|
|
if (!bargainPrice || isNaN(bargainPrice)) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请输入预期价格', |
|
|
|
icon: 'none' |
|
|
|
@ -903,8 +1161,8 @@ Page({ |
|
|
|
|
|
|
|
// 隐藏讲价弹窗
|
|
|
|
this.setData({ |
|
|
|
showBargainModal: false, |
|
|
|
bargainPrice: '' |
|
|
|
showBargainModal: false |
|
|
|
// 不重置 bargainPrice,保持其数字类型
|
|
|
|
}); |
|
|
|
|
|
|
|
// 跳转到聊天页面
|
|
|
|
@ -1064,8 +1322,15 @@ Page({ |
|
|
|
showCommentModal: false, // 是否显示评论弹窗
|
|
|
|
// 讲价弹窗相关数据
|
|
|
|
showBargainModal: false, // 是否显示讲价弹窗
|
|
|
|
bargainPrice: '', // 讲价价格
|
|
|
|
bargainPrice: 0, // 讲价价格,初始化为数字0
|
|
|
|
selectedSpecIndex: 0, // 选中的规格索引,默认选中第一条
|
|
|
|
// 价格调整相关数据
|
|
|
|
minPrice: 0, // 最低价格,初始化为0
|
|
|
|
maxPrice: 0, // 最高价格,初始化为0
|
|
|
|
isPriceReasonable: true, // 价格是否合理
|
|
|
|
sliderProgress: 50, // 滑块进度
|
|
|
|
showPriceInputModal: false, // 是否显示价格输入弹窗
|
|
|
|
tempPrice: '', // 临时价格
|
|
|
|
// 删除评论相关数据
|
|
|
|
showDeleteConfirmModal: false, // 是否显示删除确认弹窗
|
|
|
|
commentToDelete: null, // 要删除的评论对象
|
|
|
|
|