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.
119 lines
2.3 KiB
119 lines
2.3 KiB
// pages/courses/courses.js
|
|
const app = getApp();
|
|
Page({
|
|
|
|
|
|
data: {
|
|
courses: [],
|
|
loading: true,
|
|
page: 1,
|
|
show_join_course_modal:false,
|
|
loaded_all: false,
|
|
},
|
|
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});
|
|
},
|
|
update_invite_code: function({detail: {value}}){
|
|
this.setData({invite_code: value});
|
|
},
|
|
update_identities: function({detail: {value}}){
|
|
this.setData({identities: value})
|
|
},
|
|
join_course: function(event){
|
|
const {invite_code, identities} = this.data;
|
|
let data = {invite_code: invite_code};
|
|
for(var identity of identities){
|
|
data[identity] = 1;
|
|
}
|
|
console.log(data);
|
|
console.log({ ...data });
|
|
app.client.join_course(data)
|
|
.then(res=>{
|
|
console.log(res);
|
|
wx.showToast({
|
|
title: res.data.message
|
|
});
|
|
wx.navigateTo({
|
|
url: "../course_detail/course_detail?course_id="+res.data.course_id
|
|
});
|
|
this.cancel_join_course_modal();
|
|
})
|
|
.catch(error=>{
|
|
wx.showToast({
|
|
title: error.toString(),
|
|
icon: "none"
|
|
});
|
|
console.warn(error);
|
|
})
|
|
|
|
},
|
|
fetch_courses: function(options){
|
|
return app.client.search_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.data.courses);
|
|
})
|
|
},
|
|
|
|
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
|
|
onReachBottom: function () {
|
|
if(!this.data.loaded_all){
|
|
wx.pageScrollTo({
|
|
selector: ".loading"
|
|
})
|
|
this.fetch_courses({ page: this.data.page + 1 })
|
|
.then(res => {
|
|
this.setData({ page: this.data.page + 1});
|
|
if(res.data.courses.length==0){
|
|
this.setData({loaded_all: true})
|
|
}else{
|
|
this.add_courses(res.data.courses);
|
|
}
|
|
})
|
|
}
|
|
},
|
|
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |