From 6b7aff890f6644bd0321f095998808193abe5330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sun, 22 Feb 2026 14:04:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=AE=B2=E4=BB=B7?= =?UTF-8?q?=E5=92=8C=E5=92=A8=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/goods-detail/goods-detail.js | 78 +++++++++++++++++++++++----- pages/goods-detail/goods-detail.wxml | 42 +++++++++++---- pages/goods-detail/goods-detail.wxss | 68 ++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 22 deletions(-) diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index aa23016..87cbde5 100644 --- a/pages/goods-detail/goods-detail.js +++ b/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`, diff --git a/pages/goods-detail/goods-detail.wxml b/pages/goods-detail/goods-detail.wxml index ef2a377..38f6161 100644 --- a/pages/goods-detail/goods-detail.wxml +++ b/pages/goods-detail/goods-detail.wxml @@ -442,21 +442,43 @@ - - + + 讲价 - 请输入您的预期价格(元) - + + 选择规格 + + + + + {{item.display}} + + + 已下架 + + + + + + + + 请输入您的预期价格(元) + + diff --git a/pages/goods-detail/goods-detail.wxss b/pages/goods-detail/goods-detail.wxss index 6c50330..18e4b46 100644 --- a/pages/goods-detail/goods-detail.wxss +++ b/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;