小程序修改代码

This commit is contained in:
2025-08-18 09:46:18 +08:00
parent 3dc4d64215
commit 2e363f3f1a
3 changed files with 206 additions and 192 deletions

View File

@ -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; // 获取返回的数据
// 更新审核状态和查询结果
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) {
wx.showToast({
title: '请输入身份证',
icon: 'none'
});
return;
}
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() {