小程序提交
This commit is contained in:
178
pages/dashboardModule/performanceRanking/performanceRanking.js
Normal file
178
pages/dashboardModule/performanceRanking/performanceRanking.js
Normal file
@ -0,0 +1,178 @@
|
||||
import { baseUrl } from "../../../request";
|
||||
|
||||
Page({
|
||||
data: {
|
||||
// 用于存储输入框数据
|
||||
nickName: '',
|
||||
phoneNumber: '',
|
||||
selectedSortField: '待选择', // 默认选择"待选择"
|
||||
selectedSortOrder: '升序', // 默认选择升序
|
||||
sortFieldsByManager: ['员工数量', '推广人数', '下单数量', '总订单金额', '净成交金额'],
|
||||
sortFieldsBySupervisor: ['推广人数', '下单数量', '总订单金额', '净成交金额'],
|
||||
sortOrders: ['升序', '降序'],
|
||||
items: [], // 用于存储查询结果
|
||||
role: '', // 假设初始为主管角色,可以根据实际情况动态设置
|
||||
},
|
||||
|
||||
// 主管名称输入
|
||||
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;
|
||||
// 校验:确保主管名称、手机号和排序条件不能为空
|
||||
if (!this.data.nickName || !this.data.phoneNumber) {
|
||||
wx.showToast({
|
||||
title: '主管名称和手机号不能为空',
|
||||
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();
|
||||
|
||||
wx.showToast({
|
||||
title: '请求失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if( role === 'supervisor' ) {
|
||||
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;
|
||||
console.log('角色---->',options.role);
|
||||
this.setData({ role });
|
||||
let showRole = '';
|
||||
switch (options.role) {
|
||||
case 'manager':
|
||||
showRole = '主管';
|
||||
break;
|
||||
case 'supervisor':
|
||||
showRole = '员工';
|
||||
break;
|
||||
}
|
||||
this.setData({ showRole });
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user