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.

181 lines
4.4 KiB

const AV = require("../../lib/av-live-query-weapp-min")
const Presence = require("../../model/presence")
const Class = require("../../model/class")
const { jsonify } = require('../../utils/leancloudutils');
// pages/classsetting/classsetting.js
Page({
/**
* 页面的初始数据
*/
class: null,
data: {
classname:"",
new_classname:"",
presences:[],
teacher_id: ""
},
update_classname: function({detail: {value}}){
this.setData({new_classname:value})
},
change_name:function(event){
let {new_classname} =this.data
this.class.set("name", new_classname).save().then(()=>{
wx.showToast({
title:"更新成功"
});
this.setData({classname: new_classname});
},()=>{
wx.showToast({
title:"操作失败",
icon:"none"
})
});
},
del_class:function(event){
class_ = this.class;
wx.showModal({
title: '确认',
content: '删除课程会删除该课程相关的一切数据',
success: res=>{
if(res.confirm){
wx.showLoading({
title: '请稍候',
})
query_presence = new AV.Query("Presence");
query_presence.equalTo("class", class_);
query_presence.find().then(AV.Object.destroyAll);
query_message = new AV.Query("Message");
query_message.equalTo("class", class_);
query_message.find().then(AV.Object.destroyAll);
query_file = new AV.Query("File_");
query_file.equalTo("class", class_);
query_file.find().then(files=>{
filelist = files.map(file=>file.get("fileid"));
wx.cloud.deleteFile({
fileList: filelist,
success: res => {
// handle success
console.log(res.fileList)
},
fail: console.error
})
AV.Object.destroyAll(files)});
class_.destroy().then(()=>{
wx.hideLoading();
wx.showToast({
title: '删除成功',
});
wx.navigateBack({
delta: 2
})
});
}
}
})
},
del_student:function(event){
presence_id = event.currentTarget.dataset.id;
pull_presences = this.pull_presences.bind(this);
wx.showModal({
title: '确认',
content: '是否将该学员从课程中移除?',
success: res => {
if (res.confirm) {
AV.Object.createWithoutData("Presence", presence_id).destroy().then(()=>{
pull_presences();
wx.showToast({
title: '移除成功',
})}, ()=>{
wx.showToast({
title: '移除失败',
icon:"none"
})
});
}
}
})
},
pull_presences:function(){
query = new AV.Query("Presence");
query.equalTo("class", this.class);
query.include("user");
query.find().then(this.set_presences);
},
set_presences:function(presences){
presences = presences.map(presence=>{
user = presence.get("user");
presence.set("student_username", user.get("username"));
presence.set("student_name", user.get("name"));
presence.set("student_id", user.get("objectId"))
return presence;
})
this.setData(jsonify({presences}));
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
classname = options.classname;
class_id = options.class_id;
teacher_id = options.teacher_id;
console.log(teacher_id);
this.class = AV.Object.createWithoutData("Class_", class_id);
this.setData({
teacher_id: teacher_id,
classname:classname
});
this.pull_presences();
console.log(this.data);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.pull_presences();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})