diff --git a/pages/chat-detail/index.js b/pages/chat-detail/index.js
index 29bad04..00009c8 100644
--- a/pages/chat-detail/index.js
+++ b/pages/chat-detail/index.js
@@ -1,10 +1,14 @@
// pages/chat-detail/index.js
+const API = require('../../utils/api.js');
+
Page({
data: {
chatId: null,
messages: [],
inputValue: '',
- loading: false
+ loading: false,
+ chatTitle: '聊天对象',
+ managerPhone: null
},
onLoad: function (options) {
@@ -12,10 +16,73 @@ Page({
this.setData({
chatId: options.id
});
+ // 获取聊天标题
+ this.loadChatTitle();
}
this.loadMessages();
},
+ // 加载聊天标题
+ loadChatTitle: function () {
+ // 从本地存储获取聊天列表
+ const users = wx.getStorageSync('users') || {};
+ const userId = wx.getStorageSync('userId');
+ let userPhone = null;
+
+ // 尝试从users中获取手机号
+ if (userId && users[userId]) {
+ if (users[userId].phoneNumber) {
+ userPhone = users[userId].phoneNumber;
+ } else if (users[userId].phone) {
+ userPhone = users[userId].phone;
+ }
+ }
+
+ // 如果还没有获取到,尝试从全局用户信息获取
+ if (!userPhone) {
+ const userInfo = wx.getStorageSync('userInfo');
+ if (userInfo) {
+ if (userInfo.phoneNumber) {
+ userPhone = userInfo.phoneNumber;
+ } else if (userInfo.phone) {
+ userPhone = userInfo.phone;
+ }
+ }
+ }
+
+ // 如果还没有获取到,尝试从直接存储获取
+ if (!userPhone) {
+ if (wx.getStorageSync('phoneNumber')) {
+ userPhone = wx.getStorageSync('phoneNumber');
+ } else if (wx.getStorageSync('phone')) {
+ userPhone = wx.getStorageSync('phone');
+ }
+ }
+
+ if (userPhone) {
+ // 获取聊天列表
+ API.getChatList(userPhone).then(chatList => {
+ if (Array.isArray(chatList)) {
+ // 找到当前聊天项
+ const currentChat = chatList.find(item => item.id === this.data.chatId);
+ if (currentChat && currentChat.manager_phone) {
+ this.setData({ managerPhone: currentChat.manager_phone });
+ // 获取业务员信息
+ API.getSalesPersonnelInfo(currentChat.manager_phone).then(personnelInfo => {
+ if (personnelInfo && personnelInfo.alias) {
+ this.setData({ chatTitle: personnelInfo.alias });
+ }
+ }).catch(error => {
+ console.error('获取业务员信息失败:', error);
+ });
+ }
+ }
+ }).catch(error => {
+ console.error('获取聊天列表失败:', error);
+ });
+ }
+ },
+
onBack: function () {
wx.navigateBack();
},
diff --git a/pages/chat-detail/index.wxml b/pages/chat-detail/index.wxml
index 009a123..308ea8e 100644
--- a/pages/chat-detail/index.wxml
+++ b/pages/chat-detail/index.wxml
@@ -4,7 +4,7 @@
←