Browse Source

修复客服列表和角色筛选功能

pull/1/head
徐飞洋 3 months ago
parent
commit
bd87a4cde9
  1. 16
      pages/customer-service/index.js
  2. 8
      pages/index/index.js
  3. 4
      pages/index/index.wxml
  4. 16
      server-example/server-mysql.js

16
pages/customer-service/index.js

@ -8,7 +8,8 @@ Page({
searchKeyword: '',
selectedArea: '全部',
totalCount: 0,
onlineCount: 0
onlineCount: 0,
userType: 'seller' // 初始化用户类型,默认为销售员
},
// 获取客服列表的方法
@ -18,9 +19,12 @@ Page({
// 导入API工具并使用正确的请求方法
const api = require('../../utils/api');
// 获取当前用户类型参数
const userType = this.data.userType || 'seller';
const res = await new Promise((resolve, reject) => {
wx.request({
url: 'http://localhost:3003/api/managers',
url: `http://localhost:3003/api/managers?type=${userType}`,
method: 'GET',
timeout: 15000,
header: {
@ -191,7 +195,13 @@ Page({
}
},
onLoad: function () {
onLoad: function (options) {
// 获取页面参数(seller=销售员,buyer=采购员)
this.setData({
userType: options.type || 'seller' // 默认销售员
});
console.log('客服列表页面加载,类型:', this.data.userType);
// 加载客服列表
this.loadCustomerServices();

8
pages/index/index.js

@ -32,11 +32,13 @@ Page({
},
// 跳转到客服列表页面
navigateToCustomerService() {
navigateToCustomerService(e) {
// 获取按钮类型(seller=我要买蛋,buyer=我要卖蛋)
const userType = e.currentTarget.dataset.type;
wx.navigateTo({
url: '/pages/customer-service/index',
url: `/pages/customer-service/index?type=${userType}`,
success: function() {
console.log('成功跳转到客服列表页面');
console.log('成功跳转到客服列表页面,类型:', userType);
},
fail: function(error) {
console.error('跳转到客服列表页面失败:', error);

4
pages/index/index.wxml

@ -27,8 +27,8 @@
</view>
<!-- 第二行 -->
<view class="btn-row full-width">
<button class="btn service-btn" bindtap="navigateToCustomerService">我要买蛋</button>
<button class="btn service-btn" bindtap="navigateToCustomerService">我要卖蛋</button>
<button class="btn service-btn" bindtap="navigateToCustomerService" data-type="seller">我要买蛋</button>
<button class="btn service-btn" bindtap="navigateToCustomerService" data-type="buyer">我要卖蛋</button>
</view>
</view>
<view class="desc" style="margin: 30rpx 0; text-align: center; padding: 0 20rpx;">

16
server-example/server-mysql.js

@ -6481,14 +6481,24 @@ app.get('/api/online-stats', async (req, res) => {
});
}
});
// REST API接口 - 获取客服列表 - 修改为按照用户需求:工位名为采购员且有电话号码
// REST API接口 - 获取客服列表 - 支持按角色类型查询(销售员/采购员)
app.get('/api/managers', async (req, res) => {
try {
// 查询userlogin数据库中的personnel表,获取工位为销售员且有电话号码的用户
// 获取请求参数中的角色类型(seller=销售员,buyer=采购员)
const { type } = req.query;
console.log('获取客服列表请求,类型:', type);
// 根据角色类型确定查询的projectName值
let projectName = '销售员'; // 默认查询销售员
if (type === 'buyer') {
projectName = '采购员'; // 如果类型为buyer,查询采购员
}
// 查询userlogin数据库中的personnel表,获取指定工位且有电话号码的用户
// 根据表结构选择所有需要的字段
const [personnelData] = await sequelize.query(
'SELECT id, managerId, managercompany, managerdepartment, organization, projectName, name, alias, phoneNumber, avatarUrl FROM userlogin.personnel WHERE projectName = ? AND phoneNumber IS NOT NULL AND phoneNumber != "" ORDER BY id ASC',
{ replacements: ['销售员'] }
{ replacements: [projectName] }
);
// 查询chat_online_status表获取客服在线状态(添加错误处理)

Loading…
Cancel
Save