|
|
|
@ -19,19 +19,29 @@ Page({ |
|
|
|
}, |
|
|
|
|
|
|
|
onLoad: function (options) { |
|
|
|
if (options.id) { |
|
|
|
console.log('聊天详情页面加载 - 传递的参数:', JSON.stringify(options, null, 2)); |
|
|
|
// 同时支持id和userId参数,优先使用userId
|
|
|
|
const chatId = options.userId || options.id; |
|
|
|
if (chatId) { |
|
|
|
console.log('聊天详情页面 - 设置聊天ID:', chatId); |
|
|
|
this.setData({ |
|
|
|
chatId: options.id, |
|
|
|
managerPhone: options.id |
|
|
|
chatId: chatId, |
|
|
|
managerPhone: options.phone || chatId // 使用传递的phone作为managerPhone,否则使用chatId
|
|
|
|
}); |
|
|
|
console.log('聊天详情页面 - 设置客服手机号:', this.data.managerPhone); |
|
|
|
|
|
|
|
if (options.name) { |
|
|
|
if (options.name || options.userName) { |
|
|
|
// 同时支持name和userName参数
|
|
|
|
const chatTitle = decodeURIComponent(options.name || options.userName); |
|
|
|
console.log('聊天详情页面 - 设置聊天标题:', chatTitle); |
|
|
|
this.setData({ |
|
|
|
chatTitle: decodeURIComponent(options.name) |
|
|
|
chatTitle: chatTitle |
|
|
|
}); |
|
|
|
} else { |
|
|
|
this.loadChatTitle(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.error('聊天详情页面 - 未传递有效的聊天ID'); |
|
|
|
} |
|
|
|
this.loadMessages(); // 使用默认值true,首次进入页面时自动滚动到底部
|
|
|
|
this.startTimer(); |
|
|
|
@ -119,9 +129,12 @@ Page({ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
console.log('加载聊天消息 - 聊天ID:', this.data.chatId, '用户手机号:', userPhone); |
|
|
|
// 获取聊天消息
|
|
|
|
API.getChatMessages(this.data.chatId, userPhone).then(res => { |
|
|
|
console.log('加载聊天消息 - API返回:', JSON.stringify(res, null, 2)); |
|
|
|
if (Array.isArray(res)) { |
|
|
|
console.log('加载聊天消息 - API返回消息数量:', res.length); |
|
|
|
// 处理消息并排序
|
|
|
|
const processedMessages = res.map(message => { |
|
|
|
const sender = (message.sender_phone === userPhone) ? 'me' : 'other'; |
|
|
|
@ -185,6 +198,7 @@ Page({ |
|
|
|
} |
|
|
|
}); |
|
|
|
} else { |
|
|
|
console.log('加载聊天消息 - API返回非数组数据:', res); |
|
|
|
this.setData({ |
|
|
|
messages: [], |
|
|
|
loading: false |
|
|
|
|