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.

76 lines
1.6 KiB

// pages/courses/courses.js
const app = getApp();
Page({
options: {},
data: {
courses: [],
loading: true,
page: 1,
show_join_course_modal:false,
loaded_all: false,
},
search_courses: function({detail: {value}}){
this.setData({ loaded_all: false });
this.options.search = value;
this.fetch_courses(this.options).then(res => {
console.log(res);
this.set_courses(res.courses);
if (res.courses.length<=10) {
this.setData({ loaded_all: true })
}
})
},
show_join_course_modal: function(event){
this.setData({show_join_course_modal: true});
},
cancel_join_course_modal: function(event){
this.setData({show_join_course_modal: false});
},
fetch_courses: function(options){
return app.api("courses")(options)
},
set_courses: function(courses){
this.setData({courses: courses});
},
add_courses: function(courses){
this.setData({
courses:[...this.data.courses, ...courses],
})
},
onLoad: function (options) {
this.fetch_courses().then(res=>{
console.log(res);
this.set_courses(res.courses);
})
},
onShow: function () {
},
onReachBottom: function () {
if(!this.data.loaded_all){
wx.pageScrollTo({
selector: ".loading"
})
this.fetch_courses({ page: this.data.page + 1 ,...this.options})
.then(res => {
this.setData({ page: this.data.page + 1});
if(res.courses.length==0){
this.setData({loaded_all: true})
}else{
this.add_courses(res.courses);
}
})
}
},
onShareAppMessage: function () {
}
})