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