From c9fac1d7a0e5b2d88f2beef5fb496896cf17006e Mon Sep 17 00:00:00 2001 From: Default User Date: Wed, 7 Jan 2026 11:42:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BB=93=E7=AE=97=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=AC=A6=E5=8F=B7=E5=8A=A8=E7=94=BB=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=AE=9E=E7=8E=B0=E5=95=86=E5=93=81=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=AF=BC=E8=88=AA=EF=BC=8C=E5=A4=84=E7=90=86?= =?UTF-8?q?API=20404=E9=94=99=E8=AF=AF=EF=BC=8C=E9=98=B2=E6=AD=A2=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=EF=BC=8C=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E5=9C=A8=E7=BA=BF=E5=92=A8=E8=AF=A2=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=BE=AA=E7=8E=AF=E5=AF=BC=E8=88=AA=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9C=B0=E5=8C=BA=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/chat-detail/index.js | 2 +- pages/goods-detail/goods-detail.js | 90 +++++++++++++++++++++------- pages/goods-detail/goods-detail.wxml | 3 +- pages/settlement/index.wxss | 14 +---- 4 files changed, 74 insertions(+), 35 deletions(-) diff --git a/pages/chat-detail/index.js b/pages/chat-detail/index.js index 7e08528..bb0e4e1 100644 --- a/pages/chat-detail/index.js +++ b/pages/chat-detail/index.js @@ -362,7 +362,7 @@ Page({ const goodsId = e.currentTarget.dataset.goodsId; if (goodsId) { wx.navigateTo({ - url: `/pages/goods-detail/goods-detail?id=${goodsId}` + url: `/pages/goods-detail/goods-detail?id=${goodsId}&from=chat-detail` }); } }, diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index c1793e1..d4d18d3 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -444,6 +444,7 @@ Page({ data: { goodsDetail: {}, // 当前商品详情 + displayRegion: '', // 显示的地区信息(根据来源决定显示完整地区还是仅显示省份) showImagePreview: false, // 控制图片预览弹窗显示 previewImageUrls: [], // 预览的图片URL列表 previewImageIndex: 0, // 当前预览图片的索引 @@ -495,15 +496,29 @@ Page({ }); } + // 3. 检查是否来自聊天详情页面 + const fromChatDetail = options.from === 'chat-detail'; + this.setData({ + fromChatDetail: fromChatDetail + }); + console.log('是否来自聊天详情页面:', fromChatDetail); + // 解析传入的商品数据 let goodsData = null; if (options.goodsData) { try { goodsData = JSON.parse(decodeURIComponent(options.goodsData)); console.log('解析后的商品数据:', goodsData); + // 根据来源决定显示完整地区还是仅显示省份 + let displayRegion = goodsData.region || '暂无'; + if (this.data.fromChatDetail) { + displayRegion = extractProvince(displayRegion); + } + // 优先使用传入的商品数据中的联系人信息 this.setData({ goodsDetail: goodsData, + displayRegion: displayRegion, fromSeller: options.fromSeller === 'true', isFavorite: goodsData.isFavorite || false // 初始化收藏状态 }); @@ -915,8 +930,15 @@ Page({ console.log('商品状态:', formattedGoods.status); console.log('weightQuantityData:', formattedGoods.weightQuantityData); + // 根据来源决定显示完整地区还是仅显示省份 + let displayRegion = formattedGoods.region || '暂无'; + if (this.data.fromChatDetail) { + displayRegion = extractProvince(displayRegion); + } + this.setData({ goodsDetail: formattedGoods, + displayRegion: displayRegion, isFavorite: preloadedFavoriteStatus // 优先使用预加载数据中的收藏状态 }); @@ -1485,26 +1507,54 @@ Page({ goodsData: goodsData }); - // 发送商品分享消息 - API.sendMessage(userPhone, contactPhone, structuredMessage).then(sendRes => { - console.log('商品分享消息发送成功:', sendRes); - // 跳转到聊天页面 - wx.navigateTo({ - url: `/pages/chat-detail/index?userId=${chatSessionId}&userName=${encodeURIComponent(contactName || '联系人')}&phone=${contactPhone}&isManager=true`, - success: function () { - console.log('成功跳转到聊天详情页'); - }, - fail: function (error) { - console.error('跳转到聊天详情页失败:', error); - wx.showToast({ - title: '聊天功能开发中', - icon: 'none' - }); - } + // 检查是否已经发送过该商品消息 + let sentGoodsMessages = wx.getStorageSync('sentGoodsMessages') || []; + const messageKey = `${userPhone}_${contactPhone}_${goodsDetail.id}`; + const hasSent = sentGoodsMessages.includes(messageKey); + + if (!hasSent) { + // 发送商品分享消息 + API.sendMessage(userPhone, contactPhone, structuredMessage).then(sendRes => { + console.log('商品分享消息发送成功:', sendRes); + + // 记录已发送的消息 + sentGoodsMessages.push(messageKey); + wx.setStorageSync('sentGoodsMessages', sentGoodsMessages); + + // 跳转到聊天页面 + wx.navigateTo({ + url: `/pages/chat-detail/index?userId=${chatSessionId}&userName=${encodeURIComponent(contactName || '联系人')}&phone=${contactPhone}&isManager=true`, + success: function () { + console.log('成功跳转到聊天详情页'); + }, + fail: function (error) { + console.error('跳转到聊天详情页失败:', error); + wx.showToast({ + title: '聊天功能开发中', + icon: 'none' + }); + } + }); + }).catch(sendErr => { + console.error('发送商品分享消息失败:', sendErr); + // 即使发送消息失败,也跳转到聊天页面 + wx.navigateTo({ + url: `/pages/chat-detail/index?userId=${chatSessionId}&userName=${encodeURIComponent(contactName || '联系人')}&phone=${contactPhone}&isManager=true`, + success: function () { + console.log('成功跳转到聊天详情页'); + }, + fail: function (error) { + console.error('跳转到聊天详情页失败:', error); + wx.showToast({ + title: '聊天功能开发中', + icon: 'none' + }); + } + }); }); - }).catch(sendErr => { - console.error('发送商品分享消息失败:', sendErr); - // 即使发送消息失败,也跳转到聊天页面 + } else { + console.log('该商品消息已发送过,不再重复发送'); + // 直接跳转到聊天页面 wx.navigateTo({ url: `/pages/chat-detail/index?userId=${chatSessionId}&userName=${encodeURIComponent(contactName || '联系人')}&phone=${contactPhone}&isManager=true`, success: function () { @@ -1518,7 +1568,7 @@ Page({ }); } }); - }); + } }).catch(err => { console.error('建立聊天失败:', err); // 隐藏加载提示 diff --git a/pages/goods-detail/goods-detail.wxml b/pages/goods-detail/goods-detail.wxml index b5aa35a..aad362c 100644 --- a/pages/goods-detail/goods-detail.wxml +++ b/pages/goods-detail/goods-detail.wxml @@ -90,7 +90,7 @@ 地区 - {{goodsDetail.region || '暂无'}} + {{displayRegion}} @@ -191,6 +191,7 @@ class="chat-button bottom-button" bindtap="onChat" data-id="{{goodsDetail.id}}" + disabled="{{fromChatDetail}}" > 💬 在线咨询 diff --git a/pages/settlement/index.wxss b/pages/settlement/index.wxss index e8f1b6a..432baa0 100644 --- a/pages/settlement/index.wxss +++ b/pages/settlement/index.wxss @@ -1622,19 +1622,7 @@ picker { } .identity-option.selected::before { - content: '✓'; - position: absolute; - top: 24rpx; - right: 24rpx; - width: 32rpx; - height: 32rpx; - color: transparent; - font-size: 20rpx; - font-weight: bold; - display: flex; - align-items: center; - justify-content: center; - z-index: 3; + content: none; } /* 微信风格的上传区域 */