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.
61 lines
1.5 KiB
61 lines
1.5 KiB
5 years ago
|
const app = getApp();
|
||
|
Component({
|
||
|
properties: {
|
||
|
course_id:Number,
|
||
|
refresh: {
|
||
|
type: Boolean,
|
||
|
observer: function (v) {
|
||
|
if (v) {
|
||
|
this.refresh({refresh:1});
|
||
|
this.setData({ refresh: false });
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
data: {
|
||
|
|
||
|
},
|
||
|
attached(){
|
||
|
this.options = {page:1, limit:20};
|
||
|
this.refresh({refresh:1});
|
||
|
},
|
||
|
methods: {
|
||
|
async refresh({refresh=0}={}){
|
||
|
if (refresh) {
|
||
|
if (refresh == 1) {
|
||
|
this.options.page = 1;
|
||
|
var { options } = this;
|
||
|
} else if (refresh == 2) {
|
||
|
var { page, limit } = this.options;
|
||
|
var options = { page: 1, per_page: page * limit };
|
||
|
}
|
||
|
} else {
|
||
|
this.options.page++;
|
||
|
var { options } = this;
|
||
|
}
|
||
|
let {course_id} = this.data;
|
||
|
let { activities } = await app.api("weapps.courses.course_activities")({ course_id, ...this.options});
|
||
|
if (!refresh)
|
||
|
var activityGroups = this.getActivityGroups(activities, this.data.activityGroups);
|
||
|
else
|
||
|
var activityGroups = this.getActivityGroups(activities);
|
||
|
this.setData({ activityGroups });
|
||
|
return activityGroups;
|
||
|
},
|
||
|
getActivityGroups(activities, groups={}){
|
||
|
for(var item of activities){
|
||
|
var date = item.created_at.split(" ")[0];
|
||
|
if(date in groups)
|
||
|
groups[date].push(item);
|
||
|
else
|
||
|
groups[date] = [item];
|
||
|
}
|
||
|
console.log(groups);
|
||
|
return groups;
|
||
|
},
|
||
|
onReachBottom(){
|
||
|
this.refresh();
|
||
|
}
|
||
|
}
|
||
|
})
|