classSet.js 5.0 KB
// pages/classSet/classSet.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        showModel: false,
        showModel2: false,
        value: "",
        className:"",
        classid:'',
        list:'',
        jzaddstudents:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let t =this;
        t.setData({
            classid: options.classId
        });

        t.setClass();
    },

    // 班级设置接口
    setClass(){
        let t = this;
        let url = "/api/teacher/systemClassIndex";
        let params = {
            id: t.data.classid
        }
        app.post(url, params).then(res=>{
            console.log(res)
            if(res.data.code == 500){
                wx.showToast({
                  title: res.data.msg,
                  icon:'none'
                })
                
            }else{
                t.setData({
                    list: res.data.msg,
                    className: res.data.msg.name,
                    value:res.data.msg.name,
                    jzaddstudent: res.data.msg.jzaddstudent 
                })
            }
        })
    },
    // 自助添加学生开启
    switch1Change: function (e) {
        let t = this;
        if (e.detail.value == false) {
            t.setData({
                jzaddstudents: 0
            })
        }else{
            t.setData({
                jzaddstudents: 1
            })
        };
        console.log(e)
        let url = '/api/teacher/systemClass';
        let params = {
            id:t.data.classid,
            jzaddstudent: t.data.jzaddstudents
        };
        app.post(url, params).then(res => {
            t.setClass();
            if(res.data.code == 500){
                wx.showModal({
                    title: '提示',
                    content:res.data.msg,
                    showCancel:false

                })
            }
        })
    },
    // 删除班级
    removeFun(){
        let test = wx.getStorageSync('testCount');
        if(test){
            wx.showToast({
              title: '体验账户暂不支持此操作',
              icon:'none'
            })
            this.setData({
                showModel: false,
                showModel2: false
            })
        }else{
            this.setData({
                showModel: true
            })
        }
    },
    // 弹框取消
    maskNo(){
        this.setData({
            showModel: false,
            showModel2: false
        })
    },
    // 弹框确定
    maskOk(){
        let t = this;
        let url = '/api/teacher/systemClassDelte';
        let params = {
            id: t.data.classid 
        };
        app.post(url,params).then(res =>{
            if(res.data.code==500){
                wx.showToast({
                  title: res.data.msg,
                  icon:'none'
                })
            }else{
                wx.navigateBack({
                    delta:1
                })
            }
          
        })
    },
    // 点击班级名称
    theClassFun(){
        this.setData({
            showModel2: true
        })
    },
    // input
    maskChangeFun(e) {
        let t = this;
        let length = e.detail.value.length;
        t.setData({
            length: length,
            value: e.detail.value
        })
    },
    // 添加确定
    maskOk2() {
        let t = this;
        if (t.data.length > 10) {
            wx.showToast({
                title: '学生姓名不得超过10个字符',
                icon: 'none'
            })
        } else if (t.data.value == '') {
            wx.showToast({
                title: '学生姓名不能为空',
                icon: 'none'
            })
        } else {
            let url = "/api/teacher/systemClass";
            let params = {
                id: t.data.classid,
                name: t.data.value
            };
            app.post(url, params).then(res => {
                console.log(res);
                if(res.data.code==500){
                    wx.showToast({
                      title: res.data.msg,
                      icon:'none'
                    })
                }else{
                    t.setData({
                        showModel2: false,
                        className: t.data.value
                    })
                }
           
            })
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

})