|
|
@ -11,6 +11,88 @@ function getSourceTypeColor(sourceType) { |
|
|
return colorMap[sourceType] || '#4d9dff'; |
|
|
return colorMap[sourceType] || '#4d9dff'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 格式化分享标题 - 按优先级: 规格、地区、数量(鸡场直销-三方货源)、蛋黄颜色、蛋壳颜色
|
|
|
|
|
|
function formatShareTitle(goodsDetail) { |
|
|
|
|
|
console.log('===== formatShareTitle 开始 ====='); |
|
|
|
|
|
console.log('goodsDetail:', JSON.stringify(goodsDetail, null, 2)); |
|
|
|
|
|
|
|
|
|
|
|
const titleParts = []; |
|
|
|
|
|
|
|
|
|
|
|
// 1. 规格 (specification/spec)
|
|
|
|
|
|
const specification = (goodsDetail.specification || goodsDetail.spec || goodsDetail.specs || '').trim(); |
|
|
|
|
|
console.log('specification:', specification); |
|
|
|
|
|
if (specification) { |
|
|
|
|
|
titleParts.push(specification); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 2. 地区 (region)
|
|
|
|
|
|
const region = (goodsDetail.region || '').trim(); |
|
|
|
|
|
console.log('region:', region); |
|
|
|
|
|
if (region) { |
|
|
|
|
|
titleParts.push(region); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 数量 + (鸡场直销-三方货源)
|
|
|
|
|
|
const quantity = (goodsDetail.quantity || '').trim(); |
|
|
|
|
|
const sourceType = (goodsDetail.sourceType || '').trim(); |
|
|
|
|
|
console.log('quantity:', quantity, 'sourceType:', sourceType); |
|
|
|
|
|
if (quantity) { |
|
|
|
|
|
const sourceLabel = sourceType ? `(${sourceType})` : ''; |
|
|
|
|
|
titleParts.push(`${quantity}件${sourceLabel}`); |
|
|
|
|
|
} else if (sourceType) { |
|
|
|
|
|
titleParts.push(`(${sourceType})`); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 4. 蛋黄颜色 (yolk)
|
|
|
|
|
|
const yolk = (goodsDetail.yolk || '').trim(); |
|
|
|
|
|
console.log('yolk:', yolk); |
|
|
|
|
|
if (yolk) { |
|
|
|
|
|
titleParts.push(yolk); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 5. 蛋壳颜色 (eggshell) - 使用品种(breed)作为备选
|
|
|
|
|
|
const eggshell = (goodsDetail.eggshell || goodsDetail.shell || goodsDetail.breed || '').trim(); |
|
|
|
|
|
console.log('eggshell:', eggshell); |
|
|
|
|
|
if (eggshell) { |
|
|
|
|
|
titleParts.push(eggshell); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 6. 货源描述 (description)
|
|
|
|
|
|
const description = (goodsDetail.description || goodsDetail.shareTitle || '').trim(); |
|
|
|
|
|
console.log('description:', description); |
|
|
|
|
|
if (description) { |
|
|
|
|
|
titleParts.push(description); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 过滤空值后组合标题
|
|
|
|
|
|
const validParts = titleParts.filter(part => part && part.length > 0); |
|
|
|
|
|
const result = validParts.join(' '); |
|
|
|
|
|
|
|
|
|
|
|
console.log('titleParts:', titleParts); |
|
|
|
|
|
console.log('validParts:', validParts); |
|
|
|
|
|
console.log('最终标题:', result); |
|
|
|
|
|
console.log('===== formatShareTitle 结束 ====='); |
|
|
|
|
|
|
|
|
|
|
|
if (validParts.length > 0) { |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果没有匹配的数据,返回默认标题
|
|
|
|
|
|
return goodsDetail.name ? `优质鸡蛋 - ${goodsDetail.name}` : '优质鸡蛋货源'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取适合分享的图片 - 优先使用正方形图片填满分享框
|
|
|
|
|
|
function getShareImageUrl(goodsDetail) { |
|
|
|
|
|
const imageUrls = goodsDetail.imageUrls || []; |
|
|
|
|
|
|
|
|
|
|
|
if (imageUrls.length > 0) { |
|
|
|
|
|
// 返回第一张图片作为分享图片
|
|
|
|
|
|
return imageUrls[0]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return '/images/你有好蛋.png'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 媒体类型判断函数
|
|
|
// 媒体类型判断函数
|
|
|
function isVideoUrl(url) { |
|
|
function isVideoUrl(url) { |
|
|
if (!url || typeof url !== 'string') { |
|
|
if (!url || typeof url !== 'string') { |
|
|
@ -202,7 +284,7 @@ Page({ |
|
|
// 分享给朋友/群聊
|
|
|
// 分享给朋友/群聊
|
|
|
onShareAppMessage() { |
|
|
onShareAppMessage() { |
|
|
const goodsDetail = this.data.goodsDetail || {}; |
|
|
const goodsDetail = this.data.goodsDetail || {}; |
|
|
const title = goodsDetail.name ? `优质鸡蛋 - ${goodsDetail.name}` : '优质鸡蛋货源'; |
|
|
const title = formatShareTitle(goodsDetail); |
|
|
|
|
|
|
|
|
// 获取联系人、电话号码和地区信息
|
|
|
// 获取联系人、电话号码和地区信息
|
|
|
const contactName = goodsDetail.product_contact || ''; |
|
|
const contactName = goodsDetail.product_contact || ''; |
|
|
@ -235,14 +317,14 @@ Page({ |
|
|
return { |
|
|
return { |
|
|
title: title, |
|
|
title: title, |
|
|
path: sharePath, |
|
|
path: sharePath, |
|
|
imageUrl: goodsDetail.imageUrls && goodsDetail.imageUrls.length > 0 ? goodsDetail.imageUrls[0] : '/images/你有好蛋.png' |
|
|
imageUrl: getShareImageUrl(goodsDetail) |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 分享到朋友圈
|
|
|
// 分享到朋友圈
|
|
|
onShareTimeline() { |
|
|
onShareTimeline() { |
|
|
const goodsDetail = this.data.goodsDetail || {}; |
|
|
const goodsDetail = this.data.goodsDetail || {}; |
|
|
const title = goodsDetail.name ? `优质鸡蛋 - ${goodsDetail.name}` : '优质鸡蛋货源'; |
|
|
const title = formatShareTitle(goodsDetail); |
|
|
|
|
|
|
|
|
// 获取联系人、电话号码和地区信息
|
|
|
// 获取联系人、电话号码和地区信息
|
|
|
const contactName = goodsDetail.product_contact || ''; |
|
|
const contactName = goodsDetail.product_contact || ''; |
|
|
@ -272,7 +354,7 @@ Page({ |
|
|
return { |
|
|
return { |
|
|
title: title, |
|
|
title: title, |
|
|
query: contactQuery, |
|
|
query: contactQuery, |
|
|
imageUrl: goodsDetail.imageUrls && goodsDetail.imageUrls.length > 0 ? goodsDetail.imageUrls[0] : '/images/你有好蛋.png' |
|
|
imageUrl: getShareImageUrl(goodsDetail) |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
@ -415,6 +497,18 @@ Page({ |
|
|
console.log('移除收藏状态变化事件监听'); |
|
|
console.log('移除收藏状态变化事件监听'); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
onReady: function () { |
|
|
|
|
|
wx.updateShareMenu({ |
|
|
|
|
|
withShareTicket: true, |
|
|
|
|
|
success: () => { |
|
|
|
|
|
console.log('分享菜单配置成功'); |
|
|
|
|
|
}, |
|
|
|
|
|
fail: (err) => { |
|
|
|
|
|
console.log('分享菜单配置失败:', err); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
loadGoodsDetail: function (productId, preloadedData = null, contactFromShare = null) { |
|
|
loadGoodsDetail: function (productId, preloadedData = null, contactFromShare = null) { |
|
|
// 首先显示预加载的数据,确保UI快速响应
|
|
|
// 首先显示预加载的数据,确保UI快速响应
|
|
|
|