ASEMiniProgram/pages/my-grade/my-grade.js

176 lines
3.6 KiB
JavaScript
Raw Permalink Normal View History

// pages/my-grade/my-grade.js
2021-03-31 18:15:01 +00:00
import {getGrade, getSemesters, getSemesterGrades, getCourseGrades, getGradeForParent, getSemestersForParent, getSemesterGradesForParent} from '../../api/course'
2021-03-31 18:15:01 +00:00
Page({
/**
* 页面的初始数据
*/
data: {
2021-03-31 18:15:01 +00:00
gradeInfo: {},
semestersInfo: [],
showSemester: false,
targetSemesterInfo: {},
targetCoursesInfo: [],
targetOpenid: '',
2021-03-31 18:15:01 +00:00
showIndex: 0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.isParent === 'true') {
this.setData({
isParent: true,
targetOpenid: options.openid
})
getGradeForParent(options.openid).then(res => {
console.log(res)
if(res.failedCourse === 0 && res.passedCourse === 0) {
this.setData({
recordNotFound: true
})
}
else {
this.setData({
gradeInfo: res
})
}
}).then(res => {
return getSemestersForParent(options.openid).then(res => {
console.log(res)
this.setData({
semestersInfo: res
})
2021-04-01 14:16:23 +00:00
})
})
} else {
getGrade().then(res => {
2021-03-31 18:15:01 +00:00
console.log(res)
if(res.failedCourse === 0 && res.passedCourse === 0) {
this.setData({
recordNotFound: true
})
}
else {
this.setData({
gradeInfo: res
})
}
}).then(res => {
return getSemesters().then(res => {
console.log(res)
this.setData({
semestersInfo: res
})
2021-03-31 18:15:01 +00:00
})
}).catch(err => {
console.log(err)
2021-03-31 18:15:01 +00:00
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
2021-03-31 18:15:01 +00:00
},
onClickBack() {
this.setData({
showSemester: false,
targetCoursesInfo: [],
targetSemesterInfo: {}
})
},
onClickSemesterItem(e) {
let index = parseInt(e.currentTarget.dataset['index'])
if(this.data.isParent) {
getSemesterGradesForParent(this.data.targetOpenid, this.data.semestersInfo[index].id).then(res => {
2021-03-31 18:15:01 +00:00
console.log(res)
this.setData({
targetSemesterInfo: res
})
return Promise.resolve(this.data.semestersInfo[index].id)
}).then(sem_id => {
return getCourseGrades(sem_id).then(res => {
console.log(res)
this.setData({
targetCoursesInfo: res
})
})
}).then(res => {
this.setData({
showSemester: true,
2021-03-31 18:15:01 +00:00
})
})
} else {
getSemesterGrades(this.data.semestersInfo[index].id).then(res => {
console.log(res)
this.setData({
targetSemesterInfo: res
})
return Promise.resolve(this.data.semestersInfo[index].id)
}).then(sem_id => {
return getCourseGrades(sem_id).then(res => {
console.log(res)
this.setData({
targetCoursesInfo: res
})
})
}).then(res => {
this.setData({
showSemester: true,
})
2021-03-31 18:15:01 +00:00
})
}
}
})