|
|
|
@ -81,6 +81,92 @@ function formatShareTitle(goodsDetail) { |
|
|
|
return goodsDetail.name ? `优质鸡蛋 - ${goodsDetail.name}` : '优质鸡蛋货源'; |
|
|
|
} |
|
|
|
|
|
|
|
// 构建商品分享消息内容
|
|
|
|
function buildShareGoodsMessage(goodsDetail) { |
|
|
|
const parts = []; |
|
|
|
|
|
|
|
// 商品名称
|
|
|
|
if (goodsDetail.name) { |
|
|
|
parts.push(`【商品】${goodsDetail.name}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 规格
|
|
|
|
const specification = (goodsDetail.specification || goodsDetail.spec || goodsDetail.specs || '').trim(); |
|
|
|
if (specification) { |
|
|
|
parts.push(`【规格】${specification}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 地区
|
|
|
|
const region = (goodsDetail.region || '').trim(); |
|
|
|
if (region) { |
|
|
|
parts.push(`【地区】${region}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 数量
|
|
|
|
const quantity = (goodsDetail.quantity || '').trim(); |
|
|
|
if (quantity) { |
|
|
|
parts.push(`【数量】${quantity}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 价格
|
|
|
|
if (goodsDetail.price) { |
|
|
|
parts.push(`【价格】${goodsDetail.price}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 货源类型
|
|
|
|
const sourceType = (goodsDetail.sourceType || '').trim(); |
|
|
|
if (sourceType) { |
|
|
|
parts.push(`【货源】${sourceType}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 联系人
|
|
|
|
if (goodsDetail.product_contact) { |
|
|
|
parts.push(`【联系人】${goodsDetail.product_contact}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 联系电话
|
|
|
|
if (goodsDetail.contact_phone) { |
|
|
|
parts.push(`【电话】${goodsDetail.contact_phone}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 蛋黄颜色
|
|
|
|
const yolk = (goodsDetail.yolk || '').trim(); |
|
|
|
if (yolk) { |
|
|
|
parts.push(`【蛋黄】${yolk}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 蛋壳颜色/品种
|
|
|
|
const eggshell = (goodsDetail.eggshell || goodsDetail.shell || goodsDetail.breed || '').trim(); |
|
|
|
if (eggshell) { |
|
|
|
parts.push(`【蛋壳/品种】${eggshell}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 新鲜程度
|
|
|
|
const freshness = (goodsDetail.freshness || '').trim(); |
|
|
|
if (freshness) { |
|
|
|
parts.push(`【新鲜程度】${freshness}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 备注描述
|
|
|
|
const description = (goodsDetail.description || '').trim(); |
|
|
|
if (description) { |
|
|
|
parts.push(`【备注】${description}`); |
|
|
|
} |
|
|
|
|
|
|
|
// 获取第一张图片作为商品图片
|
|
|
|
const imageUrls = goodsDetail.imageUrls || []; |
|
|
|
const firstImage = imageUrls.find(url => !isVideoUrl(url)); |
|
|
|
|
|
|
|
let message = parts.join('\n'); |
|
|
|
|
|
|
|
// 如果有图片,添加图片链接
|
|
|
|
if (firstImage) { |
|
|
|
message += `\n\n【商品图片】${firstImage}`; |
|
|
|
} |
|
|
|
|
|
|
|
return message; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取适合分享的图片 - 优先使用正方形图片填满分享框
|
|
|
|
function getShareImageUrl(goodsDetail) { |
|
|
|
const imageUrls = goodsDetail.imageUrls || []; |
|
|
|
@ -1379,19 +1465,68 @@ Page({ |
|
|
|
// 使用联系人手机号作为聊天会话ID
|
|
|
|
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' |
|
|
|
}); |
|
|
|
} |
|
|
|
// 构建商品分享消息内容(包含显示文本和结构化数据)
|
|
|
|
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)) || '') : '', |
|
|
|
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 displayText = buildShareGoodsMessage(goodsDetail); |
|
|
|
|
|
|
|
// 发送结构化商品消息(JSON格式,包含goodsData用于展示卡片)
|
|
|
|
const structuredMessage = JSON.stringify({ |
|
|
|
type: 'goods', |
|
|
|
text: displayText, |
|
|
|
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' |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}).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(err => { |
|
|
|
console.error('建立聊天失败:', err); |
|
|
|
|