You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.1 KiB

Page({
data: {
showModal:false,
showModalNoPledge: false, // 控制无典当信息弹窗的显示
studentId: '',
studentName: '',
questionScore: 0,// 教师输入的分数
currentScore: 0,
pledgeScore: 0,
pledgeStatus: 0,
updatedScore: 0, // 更新后的分数
},
onLoad(options) {
console.log('Received studentId:', options.studentId); // 检查参数传递是否成功
this.setData({
studentId: options.studentId,
});
},
// 处理输入的分数
handleInputScore(e) {
const value = e.detail.value;
const numericValue = Number(value);
// 验证输入是否为有效的数字
if (!isNaN(numericValue)) {
this.setData({
questionScore: numericValue, // 使用 Number 转换为数字
});
} else {
this.setData({
questionScore: 0, // 如果不是数字,重置为 0
});
}
},
submitScore() {
const { studentId, questionScore } = this.data;
console.log('请求数据:', { studentId, questionScore }); // 打印请求数据
// 积分必须是一个数字
if (isNaN(questionScore)) {
wx.showToast({
title: '请输入有效的积分',
icon: 'none',
});
return;
}
// 更新学生积分并处理典当
wx.request({
url: 'http://127.0.0.1:8000/api/update_question_score', // 你的后端 API 地址
method: 'POST',
data: {
studentId: this.data.studentId,
questionScore: this.data.questionScore,
},
success: (res) => {
if (res.statusCode === 200) {
wx.showToast({
title: '积分更新成功',
icon: 'success',
});
// 判断返回的数据中是否有典当信息
const { current_score, pledge_score, pledge_status, updated_score} = res.data;
if (pledge_score && pledge_status === 1) {
// 设置数据并弹出典当信息的弹窗
this.setData({
currentScore: current_score,
pledgeScore: pledge_score,
showModal: true, // 显示典当信息弹窗
});
} else {
this.setData({
updatedScore: updated_score,
showModalNoPledge: true, // 显示无典当信息弹窗
});
}
} else {
wx.showToast({
title: res.data.error || '更新失败',
icon: 'none',
});
}
},
fail: () => {
wx.showToast({
title: '请求失败,请检查网络',
icon: 'none',
});
}
});
},
// 关闭典当信息弹窗
closeModal() {
this.setData({
showModal: false,
});
},
// 关闭无典当信息弹窗
closeModalNoPledge() {
this.setData({
showModalNoPledge: false,
});
},
goTorank() {
console.log('点击了排行榜按钮'); // 添加调试信息
wx.navigateTo({
url: '/pages/teacher/Trank/rank-Mode2/rank-Mode2',
});
},
goBack() {
wx.navigateTo({
url: '/pages/teacher/teacher',
});
},
});