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.

74 lines
1.7 KiB

const app = getApp();
Component({
properties: {
course_id: Number,
id_: Number,
course_identity:Number,
refresh: {
type: Number,
observer: function (r) {
if (r) {
this.refresh();
this.setData({ refresh: false });
}
}
}
},
data: {
},
attached(){
this.refresh();
},
methods: {
onChoose(e){
},
onChange(e){
let {detail:{value}} = e;
this.sort_type = value?'id':'';
this.refresh();
},
refresh(){
let {course_id, course_identity} = this.data;
let {sort_type=''} = this;
wx.showLoading({
title: '加载中',
});
if(sort_type!='id')
app.api("weapps.courses.students")({course_id, limit:1000}).then(res=>{
var {students,students_count} = res;
this.setData({students,students_count}, wx.hideLoading);
if(!this.imageMap)
this.imageMap = new Map();
for(var item of students){
for(var stu of item.items){
this.imageMap.set(stu.user_id, stu.image_url);
}
}
});
else
app.api("courses.students")({course_id, limit:10000})
.then(res=>{
var students;
if(this.imageMap)
students = res.students.map(i=>{
i.image_url = this.imageMap.get(i.user_id);
return i;
})
if(res.students.length>0)
students = [{letter:"#", items:res.students}];
else
students = [];
var {students_count} = res;
this.setData({ students, students_count}, wx.hideLoading);
});
let ext = {course_id, course_identity};
this.setData({ext});
}
}
})