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.

139 lines
3.0 KiB

// pages/mark_detail/mark_detail.js
const app = getApp();
const AV = require("../../lib/av-live-query-weapp-min");
const {jsonify} = require("../../utils/leancloudutils")
Page({
/**
* 页面的初始数据
*/
students_login_name: {},
data: {
grades: [],
loading: true,
exercises: [],
navData: [
{
text: "全部",
login: "*"
},
{
text: '我的',
login: app.client.current_user.login
},
],
currentTab: 0,
navScrollLeft: 0
},
//@todo: 退出课堂姓名的获取??
pull_students:function(){
//@todo limit20=>solve
return app.client.get_course_students({course_id: this.course_id})
.then(res=>{
let students = res.data.students;
for(var student of students){
this.students_login_name[student.login] = student.name;
}
console.log(this.students_login_name);
})
},
pull_grades: function(){
let query = new AV.Query("Grade");
query.equalTo("edu_course_id", this.course_id);
return query.find().then(grades=>{
console.log(grades);
console.log(this.students_login_name);
grades = grades.filter(grade=>{console.log(grade.edu_account_login);return grade.edu_account_login in this.students_login_name});
grades = grades.map(grade=>{
grade.set("name", this.students_login_name[grade.edu_account_login]);
grade = grade.toJSON();
grade["time"]=grade["createdAt"].slice(0, 10);
return grade;
});
this.setData({grades});
console.log(this.data);
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.course_id = options.course_id;
this.course_id = "3518"
console.log(this.course_id);
this.pull_students().then(this.pull_grades);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
switchNav(event) {
var cur = event.currentTarget.dataset.current;
//每个tab选项宽度占1/5
var singleNavWidth = this.data.windowWidth / 3;
//tab选项居中
this.setData({
navScrollLeft: (cur - 1) * singleNavWidth
})
if (this.data.currentTab == cur) {
return false;
} else {
this.setData({
currentTab: cur
})
}
},
switchTab(event) {
var cur = event.detail.current;
var singleNavWidth = this.data.windowWidth / 5;
this.setData({
currentTab: cur,
navScrollLeft: (cur - 1) * singleNavWidth
});
}
})