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.

159 lines
3.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const { Class } = require("../../model/class");
const login = require("../../model/user");
const AV = require("../../lib/av-live-query-weapp-min.js");
const { jsonify } = require('../../utils/leancloudutils');
// pages/class/class.js
const app = getApp();
const getDataForRender = class_ => ({
name: class_.get('name'),
objectId: class_.get('objectId')
});
Page({
/**
页面的初始数据data用于与.wxlm文件绑定
classes: 课程列表 type: Array
元素class: 课程信息 class.objectId 唯一
class.objectId 课程唯一主键
class.name 课程名称
*/
options:{},
data: {
categories: [{ name: "所有", value: "",checked:true }, { name: "我管理的", value: "manage" }, { name:"我学习的", value:"study"}],
statuses: [{ name: "所有", value: "",checked:true}, { name:"正在进行", value:"processing"},{name:"已结束",value:"end"}],
courses: [],
loading: true,
},
presences: [],
classes: [],
onCategoryChange: function({detail:{value}}){
this.options["category"] = value;
this.setData({loading: true});
this.pull_courses(this.options);
},
onStatusChange: function ({detail: {value} }){
this.options["status"] = value;
this.setData({loading: true});
this.pull_courses(this.options);
},
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/course?course_id=" + res.data.course_id
});
this.cancel_join_course_modal();
})
.catch(error => {
wx.showToast({
title: error.toString(),
icon: "none"
});
console.warn(error);
})
},
enter_course: function(event){
console.log(event);
let {id, course_name} = event.currentTarget.dataset;
wx.navigateTo({
url: "../course/course?course_id="+id+"&course_name="+course_name,
})
},
pull_courses: function({category="",status=""}={}){
app.client.get_user_courses({
category: category,
status: status,
complete:()=>{console.log("pull_courses complete!!!!!!");this.setData({loading:false})}
})
.then(res=>{
console.log("pull_courses");
console.log(res);
this.setData({courses: res.data.courses});
}).catch(console.error);
console.log(this.data);
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.pull_courses(this.options);
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.pull_courses(this.options);
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})