小程序修改代码
This commit is contained in:
@ -14,15 +14,143 @@ Page({
|
||||
sortOrder: 'descend',
|
||||
sortOrders: ['升序', '降序'],
|
||||
items: [], // 用于存储查询结果
|
||||
allItems: [], // 用于存储所有查询数据(用于模糊查询)
|
||||
role: '', // 假设初始为主管角色,可以根据实际情况动态设置
|
||||
k: 1,
|
||||
showRole: ''
|
||||
},
|
||||
|
||||
// 主管名称输入
|
||||
// 页面加载时查询
|
||||
onLoad(options) {
|
||||
const role = options.role;
|
||||
this.setData({ k: options.k })
|
||||
if (role === 'staff') this.setData({ selectedSortField: '推广人数' })
|
||||
this.setData({ role });
|
||||
let showRole = '';
|
||||
switch (options.role) {
|
||||
case 'manager':
|
||||
showRole = '主管';
|
||||
break;
|
||||
case 'supervisor':
|
||||
showRole = '员工';
|
||||
break;
|
||||
case 'staff':
|
||||
showRole = '员工'
|
||||
}
|
||||
this.setData({ showRole });
|
||||
|
||||
// 执行搜索获取所有数据
|
||||
this.onSearch()
|
||||
},
|
||||
|
||||
// 搜索按钮点击
|
||||
onSearch() {
|
||||
const { showRole, role } = this.data;
|
||||
|
||||
// 显示加载中
|
||||
wx.showLoading({
|
||||
title: '加载中...',
|
||||
mask: true // 显示遮罩层
|
||||
});
|
||||
|
||||
if (showRole === '员工') {
|
||||
this.setData({ sortField: 'promoCount' })
|
||||
}
|
||||
|
||||
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) => {
|
||||
wx.hideLoading();
|
||||
if (res.data.code === 1) {
|
||||
this.setData({
|
||||
items: res.data.data,
|
||||
allItems: res.data.data // 将所有数据存储以便后续模糊查询
|
||||
});
|
||||
} else {
|
||||
notLogin(res.data.message)
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.hideLoading();
|
||||
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) => {
|
||||
wx.hideLoading();
|
||||
if (res.data.code === 1) {
|
||||
this.setData({
|
||||
items: res.data.data,
|
||||
allItems: res.data.data // 将所有数据存储以便后续模糊查询
|
||||
});
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '没有数据',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: '请求失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 输入主管名称时保存值
|
||||
onNameInput(e) {
|
||||
const inputValue = e.detail.value;
|
||||
this.setData({
|
||||
nickName: e.detail.value
|
||||
nickName: inputValue
|
||||
});
|
||||
},
|
||||
|
||||
// 模糊查询
|
||||
onSearchWithFilter() {
|
||||
const { nickName, allItems } = this.data;
|
||||
|
||||
// 如果没有输入主管名称,则直接显示所有数据
|
||||
if (!nickName) {
|
||||
this.setData({
|
||||
items: allItems
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 模糊查询
|
||||
const filteredItems = allItems.filter(item =>
|
||||
item.nickName.includes(nickName) // 根据主管名称进行模糊匹配
|
||||
);
|
||||
|
||||
this.setData({
|
||||
items: filteredItems
|
||||
});
|
||||
},
|
||||
|
||||
@ -61,149 +189,10 @@ Page({
|
||||
this.onSearch()
|
||||
},
|
||||
|
||||
// 搜索按钮点击
|
||||
onSearch() {
|
||||
const { showRole, 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 // 显示遮罩层
|
||||
});
|
||||
|
||||
if (showRole === '员工') {
|
||||
this.setData({ sortField: 'promoCount' })
|
||||
}
|
||||
|
||||
const requestData = {
|
||||
nickName: this.data.nickName,
|
||||
phoneNumber: this.data.phoneNumber,
|
||||
sortField: this.data.sortField || '',
|
||||
sortOrder: this.data.sortOrder || 'ascend'
|
||||
};
|
||||
console.log('requestData====>', requestData)
|
||||
|
||||
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 {
|
||||
notLogin(res.data.message)
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
// 请求失败后,隐藏loading
|
||||
wx.hideLoading();
|
||||
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()
|
||||
},
|
||||
|
||||
// 下拉刷新
|
||||
onPullDownRefresh() {
|
||||
this.onSearch()
|
||||
wx.stopPullDownRefresh();
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
|
@ -76,7 +76,8 @@
|
||||
</view>
|
||||
|
||||
<!-- 搜索按钮 -->
|
||||
<view class="btn btn-primary" bindtap="onSearch">搜索</view>
|
||||
<view class="btn btn-primary" bindtap="onSearchWithFilter">搜索</view>
|
||||
|
||||
</view>
|
||||
|
||||
<!-- 结果列表 -->
|
||||
|
@ -7,62 +7,86 @@ Page({
|
||||
},
|
||||
|
||||
// 输入框事件
|
||||
onInput(e) {
|
||||
onInput(e) {
|
||||
const inputIdCard = e.detail.value;
|
||||
// 只允许输入数字
|
||||
const isValidInput = /^[0-9]*$/.test(inputIdCard);
|
||||
|
||||
if (!isValidInput) {
|
||||
this.setData({
|
||||
inputIdCard: e.detail.value // 获取身份证输入
|
||||
inputIdCard: inputIdCard.slice(0, -1) // 删除非数字字符
|
||||
});
|
||||
},
|
||||
wx.showToast({
|
||||
title: '请输入有效的身份证号码',
|
||||
icon: 'none'
|
||||
});
|
||||
} else {
|
||||
this.setData({
|
||||
inputIdCard
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 查询操作
|
||||
onSearch() {
|
||||
const inputIdCard = this.data.inputIdCard;
|
||||
if (!inputIdCard) {
|
||||
wx.showToast({
|
||||
title: '请输入身份证',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 查询操作
|
||||
onSearch() {
|
||||
const inputIdCard = this.data.inputIdCard;
|
||||
|
||||
// 查询的接口
|
||||
wx.request({
|
||||
url: baseUrl + '/advancementApply/query/credential', // 替换为你的后端查询接口
|
||||
method: 'POST',
|
||||
data: { templateString: inputIdCard },
|
||||
success: (res) => {
|
||||
console.log('后端返回---->',res.data);
|
||||
if (res.data.code === 1) {
|
||||
// 假设返回的查询结果是以下格式
|
||||
const result = res.data.data; // 获取返回的数据
|
||||
// 校验身份证号的有效性
|
||||
if (!inputIdCard) {
|
||||
wx.showToast({
|
||||
title: '请输入身份证',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新审核状态和查询结果
|
||||
this.setData({
|
||||
status: result.reviewStatus, // 审核状态
|
||||
result: {
|
||||
name: result.name, // 姓名
|
||||
phone: result.phone, // 手机号
|
||||
idCard: result.idCard, // 身份证号
|
||||
failureReason: result.rejectReason, // 失败原因
|
||||
password: result.userPassword, // 密码(如果有的话)
|
||||
userRole: result.userRole, // 用户级别
|
||||
id: result.id
|
||||
}
|
||||
});
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: res.data.message,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
if (inputIdCard.length !== 18) {
|
||||
wx.showToast({
|
||||
title: '请输入18位身份证号码',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 查询的接口
|
||||
wx.request({
|
||||
url: baseUrl + '/advancementApply/query/credential', // 替换为你的后端查询接口
|
||||
method: 'POST',
|
||||
data: { templateString: inputIdCard },
|
||||
success: (res) => {
|
||||
console.log('后端返回---->', res.data);
|
||||
if (res.data.code === 1) {
|
||||
// 假设返回的查询结果是以下格式
|
||||
const result = res.data.data; // 获取返回的数据
|
||||
|
||||
// 更新审核状态和查询结果
|
||||
this.setData({
|
||||
status: result.reviewStatus, // 审核状态
|
||||
result: {
|
||||
name: result.name, // 姓名
|
||||
phone: result.phone, // 手机号
|
||||
idCard: result.idCard, // 身份证号
|
||||
failureReason: result.rejectReason, // 失败原因
|
||||
password: result.userPassword, // 密码(如果有的话)
|
||||
userRole: result.userRole, // 用户级别
|
||||
id: result.id
|
||||
}
|
||||
});
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '请求失败,请重试',
|
||||
title: res.data.message,
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({
|
||||
title: '请求失败,请重试',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 重新申请操作
|
||||
onReapply() {
|
||||
|
Reference in New Issue
Block a user