Browse Source

优化讲价功能:根据价格范围动态调整价格调整单位和提示阈值

Xfy
徐飞洋 2 weeks ago
parent
commit
039ac1b520
  1. 39
      pages/goods-detail/goods-detail.js
  2. 19
      pages/goods-detail/goods-detail.wxml

39
pages/goods-detail/goods-detail.js

@ -770,23 +770,28 @@ Page({
}
}
const minPrice = middlePrice - 5;
const maxPrice = middlePrice + 5;
const priceRange = middlePrice < 20 ? 1 : 5;
const minPrice = middlePrice - priceRange;
const maxPrice = middlePrice + priceRange;
const defaultPrice = parseFloat(middlePrice.toFixed(2));
const priceThreshold = middlePrice < 20 ? 0.1 : 2;
console.log('计算后的价格数据:', {
middlePrice: middlePrice,
minPrice: minPrice,
maxPrice: maxPrice,
defaultPrice: defaultPrice
defaultPrice: defaultPrice,
priceThreshold: priceThreshold
});
this.setData({
showBargainModal: true,
bargainPrice: defaultPrice,
basePrice: middlePrice, // 设置基础价格
selectedSpecIndex: 0, // 默认选中第一条规格
minPrice: minPrice,
maxPrice: maxPrice,
priceThreshold: priceThreshold, // 设置价格判断阈值
sliderProgress: 50 // 默认滑块位置
}, () => {
console.log('setData 完成后的 bargainPrice:', this.data.bargainPrice);
@ -827,16 +832,19 @@ Page({
}
}
const minPrice = middlePrice - 5;
const maxPrice = middlePrice + 5;
const priceRange = middlePrice < 20 ? 1 : 5;
const minPrice = middlePrice - priceRange;
const maxPrice = middlePrice + priceRange;
const currentPrice = parseFloat(middlePrice.toFixed(2));
const priceThreshold = middlePrice < 20 ? 0.3 : 2;
console.log('选择规格 - 价格数据:', {
index: index,
middlePrice: middlePrice,
minPrice: minPrice,
maxPrice: maxPrice,
currentPrice: currentPrice
currentPrice: currentPrice,
priceThreshold: priceThreshold
});
this.setData({
@ -844,6 +852,8 @@ Page({
minPrice: minPrice,
maxPrice: maxPrice,
bargainPrice: currentPrice,
basePrice: middlePrice, // 更新基础价格
priceThreshold: priceThreshold, // 更新价格判断阈值
sliderProgress: 50
});
},
@ -871,7 +881,8 @@ Page({
});
if (bargainPrice > minPrice) {
const newPrice = parseFloat((bargainPrice - 1).toFixed(2));
const step = bargainPrice < 20 ? 0.1 : 1;
const newPrice = parseFloat((bargainPrice - step).toFixed(2));
console.log('计算新价格:', newPrice);
this.updatePrice(newPrice);
}
@ -887,7 +898,8 @@ Page({
});
if (bargainPrice < maxPrice) {
const newPrice = parseFloat((bargainPrice + 1).toFixed(2));
const step = bargainPrice < 20 ? 0.1 : 1;
const newPrice = parseFloat((bargainPrice + step).toFixed(2));
console.log('计算新价格:', newPrice);
this.updatePrice(newPrice);
}
@ -980,7 +992,7 @@ Page({
// 滑块移动
onSliderMove(e) {
try {
const { minPrice, maxPrice } = this.data;
const { minPrice, maxPrice, bargainPrice } = this.data;
if (!minPrice || !maxPrice) return;
const touch = e.touches[0];
@ -996,7 +1008,14 @@ Page({
progress = Math.max(0, Math.min(100, progress));
const priceRange = maxPrice - minPrice;
const price = Math.round(minPrice + (progress / 100) * priceRange);
let price = minPrice + (progress / 100) * priceRange;
if (bargainPrice < 20) {
price = Math.round(price * 10) / 10;
} else {
price = Math.round(price);
}
const clampedPrice = Math.max(minPrice, Math.min(maxPrice, price));
this.setData({

19
pages/goods-detail/goods-detail.wxml

@ -496,6 +496,25 @@
</view>
<text class="slider-max-price">¥{{maxPrice}}</text>
</view>
<!-- 立即成交提示 -->
<view wx:if="{{bargainPrice > (basePrice + priceThreshold)}}" class="price-reasonable-tip" style="display: flex; align-items: center; justify-content: center; margin-top: 20rpx; padding: 16rpx; background: linear-gradient(135deg, #fefce8 0%, #fef9c3 100%); border-radius: 12rpx; border: 1rpx solid #fde68a;">
<text style="font-size: 36rpx; margin-right: 12rpx;">🎊</text>
<text style="font-size: 28rpx; color: #d97706; font-weight: 500;">当前出价高于商家报价,可立即成交</text>
</view>
<!-- 价格建议提示 -->
<view wx:elif="{{bargainPrice < (basePrice - priceThreshold)}}" class="price-reasonable-tip" style="display: flex; align-items: center; justify-content: center; margin-top: 20rpx; padding: 16rpx; background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%); border-radius: 12rpx; border: 1rpx solid #bae6fd;">
<text style="font-size: 36rpx; margin-right: 12rpx;">😅</text>
<text style="font-size: 28rpx; color: #0ea5e9; font-weight: 500;">基于商品的市场价值,成交率低</text>
</view>
<!-- 价格合理性提示 -->
<view wx:else class="price-reasonable-tip" style="display: flex; align-items: center; justify-content: center; margin-top: 20rpx; padding: 16rpx; background: linear-gradient(135deg, #fffbe6 0%, #f7f3d7 100%); border-radius: 12rpx; border: 1rpx solid #ffe7ba;">
<text style="font-size: 36rpx; margin-right: 12rpx;">🤲</text>
<text style="font-size: 28rpx; color: #d48806; font-weight: 500;">该价格区间合理,预估24h内可成交</text>
</view>
</view>
<!-- 价格输入弹窗 -->

Loading…
Cancel
Save