diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 1ca7f53..91a42b1 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -198,10 +198,6 @@ 📣 招商 - - 📊 - 管理 - diff --git a/pages/profile/index.js b/pages/profile/index.js index 95a117a..8b46b2d 100644 --- a/pages/profile/index.js +++ b/pages/profile/index.js @@ -24,7 +24,8 @@ Page({ userTags: [], needPhoneAuth: false, // 是否需要重新授权手机号 locationInfo: '', // 位置信息 - hasLocationAuth: false // 是否已经授权位置 + hasLocationAuth: false, // 是否已经授权位置 + isInPersonnel: false // 用户手机号是否在personnel表中 }, onLoad() { @@ -93,6 +94,33 @@ Page({ // 先使用本地存储的用户类型更新标签,后续会被服务器返回的最新值覆盖 this.updateUserTags(userId, user.type) } + + // 检查用户手机号是否在personnel表中 + this.checkPhoneInPersonnel() + }, + + // 检查用户手机号是否在personnel表中 + checkPhoneInPersonnel() { + const userInfo = this.data.userInfo + const phoneNumber = userInfo.phoneNumber + + if (!phoneNumber) { + this.setData({ isInPersonnel: false }) + return + } + + console.log('开始检查手机号是否在personnel表中:', phoneNumber) + + // 引入API服务 + const API = require('../../utils/api.js') + + API.checkPhoneInPersonnel(phoneNumber).then(isInPersonnel => { + console.log('用户手机号是否在personnel表中:', isInPersonnel) + this.setData({ isInPersonnel }) + }).catch(err => { + console.error('检查personnel表失败:', err) + this.setData({ isInPersonnel: false }) + }) }, // 更新用户标签 @@ -168,6 +196,9 @@ Page({ this.syncUserTypeFromServer(userId, serverUserInfo.type) } + // 重新检查用户手机号是否在personnel表中 + this.checkPhoneInPersonnel() + console.log('用户信息已更新,昵称:', updatedUserInfo.name, '手机号:', updatedUserInfo.phoneNumber, '身份:', serverUserInfo.type) } }).catch(err => { @@ -187,15 +218,18 @@ Page({ } app.globalData.userInfo = updatedUserInfo - wx.setStorageSync('userInfo', updatedUserInfo) - this.setData({ userInfo: updatedUserInfo }) + wx.setStorageSync('userInfo', updatedUserInfo) + this.setData({ userInfo: updatedUserInfo }) - // 同步更新用户身份信息(当前身份由数据库决定) - if (serverUserInfo.type) { - this.syncUserTypeFromServer(userId, serverUserInfo.type) - } + // 同步更新用户身份信息(当前身份由数据库决定) + if (serverUserInfo.type) { + this.syncUserTypeFromServer(userId, serverUserInfo.type) + } + + // 重新检查用户手机号是否在personnel表中 + this.checkPhoneInPersonnel() - console.log('用户信息已更新(备选方案):', updatedUserInfo) + console.log('用户信息已更新(备选方案):', updatedUserInfo) } }).catch(validateErr => { console.error('从服务器获取用户信息失败(包括备选方案):', validateErr) @@ -964,10 +998,10 @@ Page({ }); }, - // 跳转到订单页面 + // 跳转到商品管理页面 goToOrders() { wx.navigateTo({ - url: '/pages/order/index' + url: '/pages/goods/index' }); }, diff --git a/pages/profile/index.wxml b/pages/profile/index.wxml index b823fa2..6042e8f 100644 --- a/pages/profile/index.wxml +++ b/pages/profile/index.wxml @@ -43,6 +43,10 @@ 📦 订单 + + 📦 + 货源管理 + diff --git a/utils/api.js b/utils/api.js index eb47a93..2cc0f0a 100644 --- a/utils/api.js +++ b/utils/api.js @@ -1757,7 +1757,8 @@ module.exports = { getPersonnelData: function () { console.log('获取personnel表数据...'); return new Promise((resolve) => { - request('/api/managers', 'GET', {}) // 使用现有的managers接口查询采购员数据 + // 使用POST请求直接查询personnel表的所有数据 + request('/api/personnel/getAll', 'POST', {}) .then(res => { console.log('获取personnel表数据成功:', res); // 适配不同的数据返回格式 @@ -1767,7 +1768,19 @@ module.exports = { }) .catch(err => { console.error('获取personnel表数据失败:', err); - resolve([]); + // 失败时使用旧的managers接口作为备选 + request('/api/managers', 'GET', { type: 'buyer' }) // 查询采购员 + .then(res => { + console.log('使用备选接口获取personnel表数据成功:', res); + // 适配不同的数据返回格式 + const data = res && res.data && Array.isArray(res.data) ? res.data : + res && Array.isArray(res) ? res : []; + resolve(data); + }) + .catch(err => { + console.error('备选接口也失败:', err); + resolve([]); + }); }); }); }, @@ -1828,6 +1841,34 @@ module.exports = { }); }, + // 检查手机号是否在personnel表中 + checkPhoneInPersonnel: function (phoneNumber) { + console.log('API.checkPhoneInPersonnel - phoneNumber:', phoneNumber); + return new Promise((resolve) => { + // 如果没有电话号码,直接返回false + if (!phoneNumber) { + console.log('没有电话号码'); + resolve(false); + return; + } + + // 使用/api/personnel/get接口根据电话号码直接查询 + request('/api/personnel/get', 'POST', { phone: phoneNumber }) + .then(res => { + console.log('检查手机号结果:', res); + if (res && res.success && res.data && res.data.length > 0) { + resolve(true); + } else { + resolve(false); + } + }) + .catch(err => { + console.error('检查手机号失败:', err); + resolve(false); + }); + }); + }, + // 检查用户是否为客服(通过查询personnel表) checkIfUserIsCustomerService: function (phoneNumber = null) { console.log('API.checkIfUserIsCustomerService - phoneNumber:', phoneNumber);