You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
6.2 KiB

// pages/customer-service/detail/index.js
const api = require('../../../utils/api');
Page({
data: {
customerData: null,
customerServices: [
{
id: 1,
managerId: 'PM001',
managercompany: '鸡蛋贸易有限公司',
managerdepartment: '采购部',
organization: '鸡蛋采购组',
projectName: '高级采购经理',
name: '张三',
alias: '张经理',
phoneNumber: '13800138001',
avatarUrl: '',
score: 999,
isOnline: true,
responsibleArea: '华北区鸡蛋采购',
experience: '1-3年',
serviceCount: 200,
purchaseCount: 15000,
profitIncreaseRate: 15,
profitFarmCount: 120,
skills: ['渠道拓展', '供应商维护', '质量把控', '精准把控市场价格']
},
{
id: 2,
managerId: 'PM002',
managercompany: '鸡蛋贸易有限公司',
managerdepartment: '采购部',
organization: '全国采购组',
projectName: '采购经理',
name: '李四',
alias: '李经理',
phoneNumber: '13900139002',
avatarUrl: '',
score: 998,
isOnline: true,
responsibleArea: '全国鸡蛋采购',
experience: '2-3年',
serviceCount: 200,
purchaseCount: 20000,
profitIncreaseRate: 18,
profitFarmCount: 150,
skills: ['精准把控市场价格', '渠道拓展', '供应商维护']
},
{
id: 3,
managerId: 'PM003',
managercompany: '鸡蛋贸易有限公司',
managerdepartment: '采购部',
organization: '华东采购组',
projectName: '采购专员',
name: '王五',
alias: '王专员',
phoneNumber: '13700137003',
avatarUrl: '',
score: 997,
isOnline: false,
responsibleArea: '华东区鸡蛋采购',
experience: '1-2年',
serviceCount: 150,
purchaseCount: 12000,
profitIncreaseRate: 12,
profitFarmCount: 80,
skills: ['质量把控', '供应商维护']
},
{
id: 4,
managerId: 'PM004',
managercompany: '鸡蛋贸易有限公司',
managerdepartment: '采购部',
organization: '华南采购组',
projectName: '高级采购经理',
name: '赵六',
alias: '赵经理',
phoneNumber: '13600136004',
avatarUrl: '',
score: 996,
isOnline: true,
responsibleArea: '华南区鸡蛋采购',
experience: '3-5年',
serviceCount: 250,
purchaseCount: 25000,
profitIncreaseRate: 20,
profitFarmCount: 180,
skills: ['精准把控市场价格', '渠道拓展', '质量把控', '供应商维护']
}
]
},
onLoad: function (options) {
// 获取传递过来的客服ID
const { id } = options;
// 根据ID查找客服数据
const customerData = this.data.customerServices.find(item => item.id === parseInt(id));
if (customerData) {
this.setData({
customerData: customerData
});
// 设置导航栏标题
wx.setNavigationBarTitle({
title: `${customerData.alias} - 客服详情`,
});
} else {
// 如果找不到对应ID的客服,显示错误提示
wx.showToast({
title: '未找到客服信息',
icon: 'none'
});
}
},
onShow() {
// 更新自定义tabBar状态
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
this.getTabBar().setData({
selected: -1 // 不选中任何tab
});
}
},
// 返回上一页
onBack: function () {
wx.navigateBack();
},
// 在线沟通
onChat: function () {
const { customerData } = this.data;
if (!customerData) return;
// 获取当前用户的手机号
let userPhone = '';
try {
// 尝试从不同的存储位置获取手机号
const userInfo = wx.getStorageSync('userInfo');
if (userInfo && userInfo.phoneNumber) {
userPhone = userInfo.phoneNumber;
} else {
// 尝试从其他可能的存储位置获取
const users = wx.getStorageSync('users') || {};
const userId = wx.getStorageSync('userId');
if (userId && users[userId] && users[userId].phoneNumber) {
userPhone = users[userId].phoneNumber;
} else {
userPhone = wx.getStorageSync('phoneNumber');
}
}
} catch (e) {
console.error('获取用户手机号失败:', e);
}
console.log('当前用户手机号:', userPhone);
console.log('客服手机号:', customerData.phoneNumber);
// 验证手机号
if (!userPhone) {
wx.showToast({
title: '请先登录获取手机号',
icon: 'none'
});
return;
}
// 显示加载提示
wx.showLoading({
title: '正在建立聊天...',
});
// 调用API添加聊天记录
api.addChatRecord(userPhone, customerData.phoneNumber).then(res => {
console.log('添加聊天记录成功:', res);
// 隐藏加载提示
wx.hideLoading();
// 导航到聊天详情页面
wx.navigateTo({
url: `/pages/chat-detail/index?id=${customerData.phoneNumber}&name=${customerData.alias}`
});
}).catch(err => {
console.error('添加聊天记录失败:', err);
// 隐藏加载提示
wx.hideLoading();
// 显示错误提示
wx.showToast({
title: '建立聊天失败: ' + (err.message || '请稍后重试'),
icon: 'none'
});
});
},
// 拨打电话
onCall: function () {
const { customerData } = this.data;
if (customerData && customerData.phoneNumber) {
wx.makePhoneCall({
phoneNumber: customerData.phoneNumber,
success: function () {
console.log('拨打电话成功');
},
fail: function () {
console.log('拨打电话失败');
}
});
}
},
// 分享功能
onShareAppMessage: function () {
const { customerData } = this.data;
return {
title: `${customerData?.alias || '优秀客服'} - 鸡蛋贸易平台`,
path: `/pages/customer-service/detail/index?id=${customerData?.id}`,
imageUrl: ''
};
}
});