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.
138 lines
2.9 KiB
138 lines
2.9 KiB
5 years ago
|
// pages/courses/courses.js
|
||
|
const app = getApp();
|
||
|
Page({
|
||
|
|
||
5 years ago
|
options: {},
|
||
5 years ago
|
data: {
|
||
|
courses: [],
|
||
|
loading: true,
|
||
|
page: 1,
|
||
|
show_join_course_modal:false,
|
||
5 years ago
|
loaded_all: false,
|
||
5 years ago
|
},
|
||
5 years ago
|
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.data.courses);
|
||
|
if (res.data.courses.length<=10) {
|
||
|
this.setData({ loaded_all: true })
|
||
|
}
|
||
|
})
|
||
|
|
||
|
},
|
||
5 years ago
|
show_join_course_modal: function(event){
|
||
5 years ago
|
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})
|
||
|
},
|
||
5 years ago
|
join_course: function (event) {
|
||
|
const { invite_code, identities } = this.data;
|
||
|
let data = { invite_code: invite_code };
|
||
|
for (var identity of identities) {
|
||
5 years ago
|
data[identity] = 1;
|
||
|
}
|
||
|
console.log(data);
|
||
|
console.log({ ...data });
|
||
5 years ago
|
app.client.join_course({ ...data })
|
||
|
.then(res => {
|
||
|
if (res.data.status == 401) {
|
||
5 years ago
|
wx.showToast({
|
||
5 years ago
|
title: "请先登陆",
|
||
5 years ago
|
icon: "none"
|
||
|
});
|
||
5 years ago
|
return;
|
||
|
}
|
||
|
console.log(res);
|
||
|
wx.showToast({
|
||
|
title: res.data.message
|
||
5 years ago
|
})
|
||
5 years ago
|
wx.navigateTo({
|
||
|
url: "../course/course?course_id=" + res.data.course_id
|
||
|
});
|
||
|
this.cancel_join_course_modal();
|
||
|
})
|
||
|
.catch(error => {
|
||
|
wx.showToast({
|
||
|
title: error.toString(),
|
||
|
icon: "none"
|
||
|
});
|
||
|
console.warn(error);
|
||
|
})
|
||
5 years ago
|
|
||
|
},
|
||
|
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 () {
|
||
5 years ago
|
if(!this.data.loaded_all){
|
||
|
wx.pageScrollTo({
|
||
|
selector: ".loading"
|
||
5 years ago
|
})
|
||
5 years ago
|
this.fetch_courses({ page: this.data.page + 1 ,...this.options})
|
||
5 years ago
|
.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);
|
||
5 years ago
|
}
|
||
5 years ago
|
})
|
||
|
}
|
||
5 years ago
|
},
|
||
|
|
||
|
|
||
|
onShareAppMessage: function () {
|
||
|
|
||
|
}
|
||
|
})
|