Files
2025-08-10 11:28:38 +08:00

197 lines
5.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { baseUrl } from "../../../request";
Page({
data: {
// 用于存储输入框数据
nickName: '',
phoneNumber: '',
selectedSortField: '员工数量', // 默认选择"待选择"
selectedSortOrder: '升序', // 默认选择升序
sortFieldsByManager: ['员工数量', '推广人数', '下单数量', '总订单金额', '净成交金额'],
sortFieldsBySupervisor: ['推广人数', '下单数量', '总订单金额', '净成交金额'],
sortOrders: ['升序', '降序'],
items: [], // 用于存储查询结果
role: '', // 假设初始为主管角色,可以根据实际情况动态设置
k: 1
},
// 主管名称输入
onNameInput(e) {
this.setData({
nickName: e.detail.value
});
},
// 手机号输入
onPhoneInput(e) {
this.setData({
phoneNumber: e.detail.value
});
},
// 选择排序字段
onSortFieldChange(e) {
const { role } = this.data;
const sortFieldsMap = {
'员工数量': 'empCount',
'推广人数': 'promoCount',
'下单数量': 'orderCount',
'总订单金额': 'totalAmount',
'净成交金额': 'netAmount'
};
const selectedField = this.data.sortFieldsByManager[e.detail.value] || this.data.sortFieldsBySupervisor[e.detail.value];
this.setData({
selectedSortField: selectedField,
sortField: sortFieldsMap[selectedField], // 默认是 id
});
},
// 选择排序顺序
onSortOrderChange(e) {
const selectedOrder = e.detail.value === '0' ? 'ascend' : 'descend';
this.setData({
selectedSortOrder: selectedOrder === 'ascend' ? '升序' : '降序',
sortOrder: selectedOrder,
});
},
// 搜索按钮点击
onSearch() {
const { role } = this.data;
// // —— 新增:校验主管名称 ——
// const nameRegex = /^[\u4e00-\u9fa5]+$/;
// if (!this.data.nickName) {
// wx.showToast({ title: '主管名称不能为空', icon: 'none' });
// return;
// }
// if (!nameRegex.test(this.data.nickName)) {
// wx.showToast({ title: '主管名称只能为汉字', icon: 'none' });
// return;
// }
// // —— 新增:校验手机号 ——
// if (!this.data.phoneNumber) {
// wx.showToast({ title: '手机号不能为空', icon: 'none' });
// return;
// }
// if (this.data.phoneNumber.length < 11) {
// wx.showToast({ title: '手机号不够11位', icon: 'none' });
// return;
// }
// 原排序条件校验,保持不变
// if (this.data.selectedSortField === '待选择') {
// wx.showToast({
// title: '排序条件不能为空',
// icon: 'none'
// });
// return;
// }
// 显示加载中
wx.showLoading({
title: '加载中...',
mask: true // 显示遮罩层
});
const requestData = {
nickName: this.data.nickName,
phoneNumber: this.data.phoneNumber,
sortField: this.data.sortField || '',
sortOrder: this.data.sortOrder || 'ascend'
};
if(role === 'manager') {
wx.request({
url: baseUrl + '/perform/rank/supervisor', // 替换为实际API地址
method: 'POST',
header: {
Authorization: wx.getStorageSync('token')
},
data: requestData,
success: (res) => {
console.log('看看后端--->', res.data);
// 请求成功后隐藏loading
wx.hideLoading();
if (res.data.code === 1) {
this.setData({
items: res.data.data
});
} else {
wx.showToast({
title: '没有数据',
icon: 'none'
});
}
},
fail: () => {
// 请求失败后隐藏loading
wx.hideLoading();
console.log('111');
wx.showToast({
title: '请求失败',
icon: 'none'
});
}
});
} else if( role === 'supervisor' || role === 'staff') {
wx.request({
url: baseUrl + '/perform/rank/staff', // 替换为实际API地址
method: 'POST',
header: {
Authorization: wx.getStorageSync('token')
},
data: requestData,
success: (res) => {
console.log('看看后端--->', res.data);
// 请求成功后隐藏loading
wx.hideLoading();
if (res.data.code === 1) {
this.setData({
items: res.data.data
});
} else {
wx.showToast({
title: '没有数据',
icon: 'none'
});
}
},
fail: () => {
// 请求失败后隐藏loading
wx.hideLoading();
wx.showToast({
title: '请求失败',
icon: 'none'
});
}
});
}
},
onLoad(options) {
// 根据身份确定角色
const role = options.role;
this.setData({k: options.k})
if (role === 'staff') this.setData({selectedSortField: '推广人数'})
console.log('角色---->',options.role);
this.setData({ role });
let showRole = '';
switch (options.role) {
case 'manager':
showRole = '主管';
break;
case 'supervisor':
showRole = '员工';
break;
case 'staff':
showRole = '员工'
}
this.setData({ showRole });
this.onSearch()
}
});