diff --git a/pages/customer-service/index.js b/pages/customer-service/index.js
index b3ed1a4..5e517c9 100644
--- a/pages/customer-service/index.js
+++ b/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();
diff --git a/pages/index/index.js b/pages/index/index.js
index f254c19..ae91af7 100644
--- a/pages/index/index.js
+++ b/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);
diff --git a/pages/index/index.wxml b/pages/index/index.wxml
index 1774abe..b40a050 100644
--- a/pages/index/index.wxml
+++ b/pages/index/index.wxml
@@ -27,8 +27,8 @@
-
-
+
+
diff --git a/server-example/server-mysql.js b/server-example/server-mysql.js
index fd9ce5f..b679e69 100644
--- a/server-example/server-mysql.js
+++ b/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表获取客服在线状态(添加错误处理)