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.

133 lines
3.2 KiB

5 years ago
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 getDataForRender = class_ => ({
name: class_.get('name'),
objectId: class_.get('objectId')
});
Page({
/**
页面的初始数据data用于与.wxlm文件绑定
classes: 课程列表 type: Array
元素class: 课程信息 class.objectId 唯一
class.objectId 课程唯一主键
class.name 课程名称
*/
data: {
//classes: [{objectId: "232323", "name":"测试"}]
classes: []
5 years ago
},
presences: [],
5 years ago
classes: [],
del_class: function(event){
class_id = event.currentTarget.dataset.class_id;
class_name = event.currentTarget.dataset.class_name;
presence = this.presences.filter(presence=>presence.get("class").id==class_id)[0];
pull_classes = this.pull_classes.bind(this);
wx.showModal({
title: '退出学习',
content: '退出学习会清零你该门课程的分数',
success(res) {
if (res.confirm) {
wx.showLoading({
title: '请稍候',
})
presence.destroy().then(() => {
pull_classes();
wx.hideLoading();
wx.showToast({
title: '退出成功',
icon: "success"
})
},
() => {
wx.hideLoading();
wx.showToast({
title: '操作失败',
icon: "none"
})
}).catch(error => console.error(error.message));
} } });
},
5 years ago
enter_class: function(event){
console.log(event);
var class_id = event.currentTarget.dataset.class_id;
var class_name = event.currentTarget.dataset.class_name;
wx.navigateTo({
url: "../classroom/classroom?class_id="+class_id+"&"+"class_name="+class_name,
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
5 years ago
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
pull_classes: function(){
console.log("classes.pull_classes");
var query = new AV.Query("Presence");
query.equalTo("user", AV.User.current());
query.include("class");
query.find().then((presences) => {
this.presences = presences;
this.classes = presences.map((presence) => {return presence.get("class")});
console.log(this.classes);
this.setData(jsonify({ classes: this.classes }));
})
},
5 years ago
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
console.log("classes.onShow()");
this.pull_classes();
5 years ago
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.pull_classes();
5 years ago
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})