Browse Source

feat: 优化讲价和咨询功能

Xfy
徐飞洋 2 weeks ago
parent
commit
6b7aff890f
  1. 78
      pages/goods-detail/goods-detail.js
  2. 42
      pages/goods-detail/goods-detail.wxml
  3. 68
      pages/goods-detail/goods-detail.wxss

78
pages/goods-detail/goods-detail.js

@ -729,10 +729,24 @@ Page({
showBargainModal() {
this.setData({
showBargainModal: true,
bargainPrice: ''
bargainPrice: '',
selectedSpecIndex: 0 // 默认选中第一条规格
});
},
// 选择规格
selectSpec(e) {
const index = e.currentTarget.dataset.index;
this.setData({
selectedSpecIndex: index
});
},
// 阻止事件冒泡
stopPropagation() {
// 阻止点击弹窗内容时关闭弹窗
},
// 隐藏讲价弹窗
hideBargainModal() {
this.setData({
@ -759,6 +773,19 @@ Page({
return;
}
// 获取选中的规格信息
const selectedSpecIndex = this.data.selectedSpecIndex;
const weightQuantityData = this.data.goodsDetail.weightQuantityData || [];
const selectedSpec = weightQuantityData[selectedSpecIndex];
if (!selectedSpec) {
wx.showToast({
title: '请选择规格',
icon: 'none'
});
return;
}
const contactName = this.data.goodsDetail.product_contact;
const contactPhone = this.data.goodsDetail.contact_phone;
@ -843,23 +870,32 @@ Page({
});
// 构建讲价价格消息(第二条消息)
const bargainPriceMessage = `【讲价】预期价格:${bargainPrice}`;
const bargainPriceMessage = `【讲价】规格:${selectedSpec.display}预期价格:${bargainPrice}`;
// 调用API创建聊天记录并发送消息
API.fixChatRecordsPair(userPhone, contactPhone).then(res => {
console.log('聊天建立成功:', res);
// 发送第一条消息:商品信息
return API.sendMessage(userPhone, contactPhone, structuredGoodsMessage);
// 发送第一条消息:讲价价格
return API.sendMessage(userPhone, contactPhone, bargainPriceMessage);
}).then(() => {
console.log('商品信息消息发送成功');
console.log('讲价价格消息发送成功');
// 发送第二条消息:讲价价格
return API.sendMessage(userPhone, contactPhone, bargainPriceMessage);
// 发送第二条消息:商品信息
return API.sendMessage(userPhone, contactPhone, structuredGoodsMessage);
}).then(sendRes => {
console.log('讲价价格消息发送成功:', sendRes);
console.log('商品信息消息发送成功:', sendRes);
wx.hideLoading();
// 更新未读消息数(发送了两条消息,增加2)
API.updateUnreadCount(contactPhone, 2)
.then(() => {
console.log('更新未读消息数成功');
})
.catch(error => {
console.error('更新未读消息数失败:', error);
});
wx.showToast({
title: '讲价请求已发送',
icon: 'success'
@ -1029,6 +1065,7 @@ Page({
// 讲价弹窗相关数据
showBargainModal: false, // 是否显示讲价弹窗
bargainPrice: '', // 讲价价格
selectedSpecIndex: 0, // 选中的规格索引,默认选中第一条
// 删除评论相关数据
showDeleteConfirmModal: false, // 是否显示删除确认弹窗
commentToDelete: null, // 要删除的评论对象
@ -2752,9 +2789,26 @@ Page({
const hasSent = sentGoodsMessages.includes(messageKey);
if (!hasSent) {
// 发送商品分享消息
API.sendMessage(userPhone, contactPhone, structuredMessage).then(sendRes => {
console.log('商品分享消息发送成功:', sendRes);
// 构建问候语消息
const greetingMessage = '你好我想了解一下这个商品';
// 先发送商品分享消息
API.sendMessage(userPhone, contactPhone, structuredMessage).then(() => {
console.log('商品分享消息发送成功');
// 再发送问候语
return API.sendMessage(userPhone, contactPhone, greetingMessage);
}).then(sendRes => {
console.log('问候语消息发送成功:', sendRes);
// 更新未读消息数(发送了两条消息,增加2)
API.updateUnreadCount(contactPhone, 2)
.then(() => {
console.log('更新未读消息数成功');
})
.catch(error => {
console.error('更新未读消息数失败:', error);
});
// 记录已发送的消息
sentGoodsMessages.push(messageKey);
@ -2775,7 +2829,7 @@ Page({
}
});
}).catch(sendErr => {
console.error('发送商品分享消息失败:', sendErr);
console.error('发送消息失败:', sendErr);
// 即使发送消息失败,也跳转到聊天页面
wx.navigateTo({
url: `/pages/chat-detail/index?userId=${chatSessionId}&userName=${encodeURIComponent(contactName || '联系人')}&phone=${contactPhone}&isManager=true`,

42
pages/goods-detail/goods-detail.wxml

@ -442,21 +442,43 @@
</view>
<!-- 讲价弹窗 -->
<view class="bargain-modal-overlay" wx:if="{{showBargainModal}}">
<view class="bargain-modal-container">
<view class="bargain-modal-overlay" wx:if="{{showBargainModal}}" bindtap="hideBargainModal">
<view class="bargain-modal-container" catchtap="stopPropagation">
<view class="bargain-modal-title">
讲价
</view>
<view class="bargain-modal-content">
<text class="bargain-hint">请输入您的预期价格(元)</text>
<input
class="bargain-modal-input"
type="digit"
placeholder="请输入价格"
value="{{bargainPrice}}"
bindinput="onBargainInput"
/>
<view class="bargain-spec-section">
<text class="bargain-spec-title">选择规格</text>
<scroll-view class="bargain-spec-scroll" scroll-y="{{true}}">
<view class="bargain-spec-list">
<block wx:for="{{goodsDetail.weightQuantityData}}" wx:key="index">
<view
class="bargain-spec-item {{selectedSpecIndex === index ? 'selected' : ''}}"
bindtap="selectSpec"
data-index="{{index}}"
>
<text class="spec-text">{{item.display}}</text>
<text wx:if="{{item.priceChangeDirection === 'up'}}" class="price-change-arrow up">↑</text>
<text wx:elif="{{item.priceChangeDirection === 'down'}}" class="price-change-arrow down">↓</text>
<text wx:if="{{item.isOffShelf}}" class="spec-off-shelf">已下架</text>
</view>
</block>
</view>
</scroll-view>
</view>
<view class="bargain-price-section">
<text class="bargain-hint">请输入您的预期价格(元)</text>
<input
class="bargain-modal-input"
type="digit"
placeholder="请输入价格"
value="{{bargainPrice}}"
bindinput="onBargainInput"
/>
</view>
</view>
<view class="bargain-modal-buttons">

68
pages/goods-detail/goods-detail.wxss

@ -1530,6 +1530,74 @@ video.slider-media .wx-video-volume-icon {
cursor: not-allowed;
}
/* 讲价弹窗规格选择样式 */
.bargain-spec-section {
margin-bottom: 30rpx;
}
.bargain-spec-title {
font-size: 28rpx;
color: #262626;
font-weight: 600;
margin-bottom: 16rpx;
display: block;
}
.bargain-spec-scroll {
max-height: 400rpx;
border: 2rpx solid #e0e0e0;
border-radius: 10rpx;
background-color: #fafafa;
}
.bargain-spec-list {
padding: 16rpx;
}
.bargain-spec-item {
padding: 24rpx 20rpx;
margin-bottom: 12rpx;
background-color: #ffffff;
border: 2rpx solid #e0e0e0;
border-radius: 10rpx;
display: flex;
align-items: center;
justify-content: space-between;
transition: all 0.3s ease;
}
.bargain-spec-item:last-child {
margin-bottom: 0;
}
.bargain-spec-item.selected {
border-color: #1890ff;
background-color: #e6f7ff;
box-shadow: 0 2rpx 8rpx rgba(24, 144, 255, 0.15);
}
.bargain-spec-item:active {
transform: scale(0.98);
}
.spec-text {
font-size: 28rpx;
color: #333;
font-weight: 500;
flex: 1;
line-height: 1.4;
}
.spec-off-shelf {
color: #ff4d4f;
font-size: 24rpx;
margin-left: 12rpx;
}
.bargain-price-section {
margin-top: 30rpx;
}
.comment-modal-overlay {
position: fixed;
top: 0;

Loading…
Cancel
Save