|
|
@ -444,6 +444,7 @@ Page({ |
|
|
|
|
|
|
|
|
data: { |
|
|
data: { |
|
|
goodsDetail: {}, // 当前商品详情
|
|
|
goodsDetail: {}, // 当前商品详情
|
|
|
|
|
|
displayRegion: '', // 显示的地区信息(根据来源决定显示完整地区还是仅显示省份)
|
|
|
showImagePreview: false, // 控制图片预览弹窗显示
|
|
|
showImagePreview: false, // 控制图片预览弹窗显示
|
|
|
previewImageUrls: [], // 预览的图片URL列表
|
|
|
previewImageUrls: [], // 预览的图片URL列表
|
|
|
previewImageIndex: 0, // 当前预览图片的索引
|
|
|
previewImageIndex: 0, // 当前预览图片的索引
|
|
|
@ -495,15 +496,29 @@ Page({ |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 检查是否来自聊天详情页面
|
|
|
|
|
|
const fromChatDetail = options.from === 'chat-detail'; |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
fromChatDetail: fromChatDetail |
|
|
|
|
|
}); |
|
|
|
|
|
console.log('是否来自聊天详情页面:', fromChatDetail); |
|
|
|
|
|
|
|
|
// 解析传入的商品数据
|
|
|
// 解析传入的商品数据
|
|
|
let goodsData = null; |
|
|
let goodsData = null; |
|
|
if (options.goodsData) { |
|
|
if (options.goodsData) { |
|
|
try { |
|
|
try { |
|
|
goodsData = JSON.parse(decodeURIComponent(options.goodsData)); |
|
|
goodsData = JSON.parse(decodeURIComponent(options.goodsData)); |
|
|
console.log('解析后的商品数据:', goodsData); |
|
|
console.log('解析后的商品数据:', goodsData); |
|
|
|
|
|
// 根据来源决定显示完整地区还是仅显示省份
|
|
|
|
|
|
let displayRegion = goodsData.region || '暂无'; |
|
|
|
|
|
if (this.data.fromChatDetail) { |
|
|
|
|
|
displayRegion = extractProvince(displayRegion); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 优先使用传入的商品数据中的联系人信息
|
|
|
// 优先使用传入的商品数据中的联系人信息
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
goodsDetail: goodsData, |
|
|
goodsDetail: goodsData, |
|
|
|
|
|
displayRegion: displayRegion, |
|
|
fromSeller: options.fromSeller === 'true', |
|
|
fromSeller: options.fromSeller === 'true', |
|
|
isFavorite: goodsData.isFavorite || false // 初始化收藏状态
|
|
|
isFavorite: goodsData.isFavorite || false // 初始化收藏状态
|
|
|
}); |
|
|
}); |
|
|
@ -915,8 +930,15 @@ Page({ |
|
|
console.log('商品状态:', formattedGoods.status); |
|
|
console.log('商品状态:', formattedGoods.status); |
|
|
console.log('weightQuantityData:', formattedGoods.weightQuantityData); |
|
|
console.log('weightQuantityData:', formattedGoods.weightQuantityData); |
|
|
|
|
|
|
|
|
|
|
|
// 根据来源决定显示完整地区还是仅显示省份
|
|
|
|
|
|
let displayRegion = formattedGoods.region || '暂无'; |
|
|
|
|
|
if (this.data.fromChatDetail) { |
|
|
|
|
|
displayRegion = extractProvince(displayRegion); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
goodsDetail: formattedGoods, |
|
|
goodsDetail: formattedGoods, |
|
|
|
|
|
displayRegion: displayRegion, |
|
|
isFavorite: preloadedFavoriteStatus // 优先使用预加载数据中的收藏状态
|
|
|
isFavorite: preloadedFavoriteStatus // 优先使用预加载数据中的收藏状态
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
@ -1485,26 +1507,54 @@ Page({ |
|
|
goodsData: goodsData |
|
|
goodsData: goodsData |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// 发送商品分享消息
|
|
|
// 检查是否已经发送过该商品消息
|
|
|
API.sendMessage(userPhone, contactPhone, structuredMessage).then(sendRes => { |
|
|
let sentGoodsMessages = wx.getStorageSync('sentGoodsMessages') || []; |
|
|
console.log('商品分享消息发送成功:', sendRes); |
|
|
const messageKey = `${userPhone}_${contactPhone}_${goodsDetail.id}`; |
|
|
// 跳转到聊天页面
|
|
|
const hasSent = sentGoodsMessages.includes(messageKey); |
|
|
wx.navigateTo({ |
|
|
|
|
|
url: `/pages/chat-detail/index?userId=${chatSessionId}&userName=${encodeURIComponent(contactName || '联系人')}&phone=${contactPhone}&isManager=true`, |
|
|
if (!hasSent) { |
|
|
success: function () { |
|
|
// 发送商品分享消息
|
|
|
console.log('成功跳转到聊天详情页'); |
|
|
API.sendMessage(userPhone, contactPhone, structuredMessage).then(sendRes => { |
|
|
}, |
|
|
console.log('商品分享消息发送成功:', sendRes); |
|
|
fail: function (error) { |
|
|
|
|
|
console.error('跳转到聊天详情页失败:', error); |
|
|
// 记录已发送的消息
|
|
|
wx.showToast({ |
|
|
sentGoodsMessages.push(messageKey); |
|
|
title: '聊天功能开发中', |
|
|
wx.setStorageSync('sentGoodsMessages', sentGoodsMessages); |
|
|
icon: 'none' |
|
|
|
|
|
}); |
|
|
// 跳转到聊天页面
|
|
|
} |
|
|
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 => { |
|
|
} else { |
|
|
console.error('发送商品分享消息失败:', sendErr); |
|
|
console.log('该商品消息已发送过,不再重复发送'); |
|
|
// 即使发送消息失败,也跳转到聊天页面
|
|
|
// 直接跳转到聊天页面
|
|
|
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`, |
|
|
success: function () { |
|
|
success: function () { |
|
|
@ -1518,7 +1568,7 @@ Page({ |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
}).catch(err => { |
|
|
}).catch(err => { |
|
|
console.error('建立聊天失败:', err); |
|
|
console.error('建立聊天失败:', err); |
|
|
// 隐藏加载提示
|
|
|
// 隐藏加载提示
|
|
|
|