|
|
@ -725,6 +725,176 @@ Page({ |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 显示讲价弹窗
|
|
|
|
|
|
showBargainModal() { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showBargainModal: true, |
|
|
|
|
|
bargainPrice: '' |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 隐藏讲价弹窗
|
|
|
|
|
|
hideBargainModal() { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showBargainModal: false, |
|
|
|
|
|
bargainPrice: '' |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 讲价输入处理
|
|
|
|
|
|
onBargainInput(e) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
bargainPrice: e.detail.value |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 提交讲价
|
|
|
|
|
|
submitBargain() { |
|
|
|
|
|
const bargainPrice = this.data.bargainPrice; |
|
|
|
|
|
if (!bargainPrice) { |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '请输入预期价格', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const contactName = this.data.goodsDetail.product_contact; |
|
|
|
|
|
const contactPhone = this.data.goodsDetail.contact_phone; |
|
|
|
|
|
|
|
|
|
|
|
if (!contactPhone) { |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '未找到联系电话', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查用户登录状态
|
|
|
|
|
|
const openid = wx.getStorageSync('openid'); |
|
|
|
|
|
const userId = wx.getStorageSync('userId'); |
|
|
|
|
|
|
|
|
|
|
|
if (!openid || !userId) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showOneKeyLoginModal: true |
|
|
|
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取当前用户的手机号
|
|
|
|
|
|
let userPhone = ''; |
|
|
|
|
|
try { |
|
|
|
|
|
const userInfo = wx.getStorageSync('userInfo'); |
|
|
|
|
|
if (userInfo && userInfo.phoneNumber) { |
|
|
|
|
|
userPhone = userInfo.phoneNumber; |
|
|
|
|
|
} else { |
|
|
|
|
|
const users = wx.getStorageSync('users') || {}; |
|
|
|
|
|
const userId = wx.getStorageSync('userId'); |
|
|
|
|
|
if (userId && users[userId] && users[userId].phoneNumber) { |
|
|
|
|
|
userPhone = users[userId].phoneNumber; |
|
|
|
|
|
} else { |
|
|
|
|
|
userPhone = wx.getStorageSync('phoneNumber'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
console.error('获取用户手机号失败:', e); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 验证手机号
|
|
|
|
|
|
if (!userPhone) { |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '请先登录获取手机号', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 显示加载提示
|
|
|
|
|
|
wx.showLoading({ |
|
|
|
|
|
title: '正在发送讲价请求...', |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 构建商品数据(用于聊天页面展示)
|
|
|
|
|
|
const goodsDetail = this.data.goodsDetail; |
|
|
|
|
|
const goodsData = { |
|
|
|
|
|
id: goodsDetail.id || '', |
|
|
|
|
|
name: goodsDetail.name || '', |
|
|
|
|
|
imageUrl: (goodsDetail.imageUrls && goodsDetail.imageUrls.length > 0) ? |
|
|
|
|
|
(goodsDetail.imageUrls.find(url => !isVideoUrl(url)) || |
|
|
|
|
|
goodsDetail.imageUrls.find(url => isVideoUrl(url)) || |
|
|
|
|
|
goodsDetail.videoCoverUrl || '') : |
|
|
|
|
|
(goodsDetail.videoCoverUrl || ''), |
|
|
|
|
|
price: goodsDetail.price || '', |
|
|
|
|
|
region: goodsDetail.region || '', |
|
|
|
|
|
displaySpecification: goodsDetail.displaySpecification || goodsDetail.specification || goodsDetail.spec || goodsDetail.specs || '', |
|
|
|
|
|
displayYolk: goodsDetail.displayYolk || goodsDetail.yolk || '', |
|
|
|
|
|
sourceType: goodsDetail.sourceType || '', |
|
|
|
|
|
totalStock: goodsDetail.totalStock || goodsDetail.stock || '', |
|
|
|
|
|
supplyStatus: goodsDetail.supplyStatus || goodsDetail.status === 'sold_out' ? '' : (goodsDetail.supplyStatus || ''), |
|
|
|
|
|
status: goodsDetail.status || '' |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 构建结构化商品消息(第一条消息)
|
|
|
|
|
|
const goodsMessage = buildShareGoodsMessage(goodsDetail); |
|
|
|
|
|
const structuredGoodsMessage = JSON.stringify({ |
|
|
|
|
|
type: 'goods', |
|
|
|
|
|
text: goodsMessage, |
|
|
|
|
|
goodsData: goodsData |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 构建讲价价格消息(第二条消息)
|
|
|
|
|
|
const bargainPriceMessage = `【讲价】预期价格:${bargainPrice}元`; |
|
|
|
|
|
|
|
|
|
|
|
// 调用API创建聊天记录并发送消息
|
|
|
|
|
|
API.fixChatRecordsPair(userPhone, contactPhone).then(res => { |
|
|
|
|
|
console.log('聊天建立成功:', res); |
|
|
|
|
|
|
|
|
|
|
|
// 发送第一条消息:商品信息
|
|
|
|
|
|
return API.sendMessage(userPhone, contactPhone, structuredGoodsMessage); |
|
|
|
|
|
}).then(() => { |
|
|
|
|
|
console.log('商品信息消息发送成功'); |
|
|
|
|
|
|
|
|
|
|
|
// 发送第二条消息:讲价价格
|
|
|
|
|
|
return API.sendMessage(userPhone, contactPhone, bargainPriceMessage); |
|
|
|
|
|
}).then(sendRes => { |
|
|
|
|
|
console.log('讲价价格消息发送成功:', sendRes); |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
|
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '讲价请求已发送', |
|
|
|
|
|
icon: 'success' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 隐藏讲价弹窗
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
showBargainModal: false, |
|
|
|
|
|
bargainPrice: '' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 跳转到聊天页面
|
|
|
|
|
|
const chatSessionId = contactPhone; |
|
|
|
|
|
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(err => { |
|
|
|
|
|
wx.hideLoading(); |
|
|
|
|
|
console.error('发送讲价消息失败:', err); |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '发送失败,请重试', |
|
|
|
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
// 评论输入处理
|
|
|
// 评论输入处理
|
|
|
onCommentInput(e) { |
|
|
onCommentInput(e) { |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
@ -856,6 +1026,9 @@ Page({ |
|
|
showContent: '', // 显示内容(用于兼容)
|
|
|
showContent: '', // 显示内容(用于兼容)
|
|
|
// 评论弹窗相关数据
|
|
|
// 评论弹窗相关数据
|
|
|
showCommentModal: false, // 是否显示评论弹窗
|
|
|
showCommentModal: false, // 是否显示评论弹窗
|
|
|
|
|
|
// 讲价弹窗相关数据
|
|
|
|
|
|
showBargainModal: false, // 是否显示讲价弹窗
|
|
|
|
|
|
bargainPrice: '', // 讲价价格
|
|
|
// 删除评论相关数据
|
|
|
// 删除评论相关数据
|
|
|
showDeleteConfirmModal: false, // 是否显示删除确认弹窗
|
|
|
showDeleteConfirmModal: false, // 是否显示删除确认弹窗
|
|
|
commentToDelete: null, // 要删除的评论对象
|
|
|
commentToDelete: null, // 要删除的评论对象
|
|
|
|