parentsList.js 7.8 KB
// pages/list/list.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        banner: [],
        currentSwiper: 0,
        index: 0,
        index2: 0,
        id: 0,
        parid: 1,
        i: 0,
        class_id: "",
        student_id: "",
        one: "",
        two: "",
        there: "",
        listtow: "",
        list: "",
        onShareImgs: '',
        test: false
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var inent = wx.getStorageSync('ident');
        options.parid = 1;
        this.onShareImg();
        this.bannerFun();
        this.setData({
            class_id: options.class_id,
            student_id: options.student_id,
            parid: options.parid,
            test: wx.getStorageSync('testCount')
        })
        
      if (inent == "1" ) {
            wx.redirectTo({
                url: '/pages/list/list?classId=' + options.class_id + '&style=' + 1,
            })
      } else if (inent === "0" || inent == "2") {

            this.classFun();
            setTimeout(()=>{
         
              if(options.class_id&&options.class_id!='undefined'){
                
                this.myFun();
              }
                
            },1000)
        } else {
            wx.showModal({
                title: '提示',
                content: '请前往授权',
                success(res) {
                    if (res.confirm) {
                        wx.redirectTo({
                            url: '/pages/home/home?class_id=' + options.class_id + '&id=' + options.id + '&where' + options.where,
                        })
                    } else if (res.cancel) {

                    }
                }
            })
        }
    },
    navgate(e){
        wx.navigateTo({
          url: '/pages/newsDetail/newsDetail?src='+e.currentTarget.dataset.src,
        })
    },
    quitTest(){
        app.quitTest()
    },
    //数据
    myFun() {
                
        let t = this;
        let url;
        if (t.data.class_id == "" || t.data.class_id == undefined) {

        } else {
            url = '/api/StudentWoke/isjoin?class_id=' + t.data.class_id;
        }
        app.gets(url).then(res => {
            if (res.data.code == 10000) {
                wx.showModal({
                    title: '提示',
                    content: '请加入班级',
                    showCancel: false,
                    success(res) {
                        if (res.confirm) {
                            wx.redirectTo({
                                url: '/pages/joinClass/joinClass?class_id=' + t.data.class_id + '&id=' + t.data.id + '&where=' + t.data.where,
                            })
                        }
                    }
                });
            } else if (res.data.code == 5000) {
                wx.showModal({
                    title: '提示',
                    content: '请前往授权',
                    success(res) {
                        if (res.confirm) {
                            wx.redirectTo({
                                url: '/pages/home/home?class_id=' + t.data.class_id + '&id=' + t.data.id + '&where' + t.data.where,
                            })
                        } else if (res.cancel) {

                        }
                    }
                })
            }
            wx.hideLoading()

        })
    },
    // 转发图片
    onShareImg() {
        let t = this;
        let url = '/api/shareimg/createimg';
        let params = {
            style: 5,
            class_id: t.data.class_id,
            style1: t.data.parid
        };
        app.post(url, params).then((res) => {
            console.log(123131)
            t.setData({
                onShareImgs: res.data.msg
            })
        })

    },
    onShareAppMessage: function() {
        let t = this;
        return {
            title: '我的班级',
            path: '/pages/parentsList/parentsList?class_id=' + t.data.class_id + '&parid=' + t.data.parid + '&student_id=' + t.data.student_id,
            imageUrl: t.data.onShareImgs,
            success: function(res) {
                console.log('成功', res)
            }
        }
    },
    // 学生班级
    classFun() {
        let t = this;
        let url = '/api/studentwoke/allclass';
        let array = [];
        app.post(url).then(res => {
            console.log(res);
            if (res.data.code == '5000') {
                wx.showToast({
                    title: '您还未授权',
                    icon: 'none'
                })
                setTimeout(() => {
                    wx.redirectTo({
                        url: '/pages/home/home',
                    })
                }, 1000)
                wx.hideLoading();
            } else {
                res.data.msg.forEach(function(item, ind) {
                    array.push(item.name)
                })
                t.setData({
                    detail: res.data.msg,
                    array: array,
                    class_id: res.data.msg[t.data.index2].class_id,
                    student_id: res.data.msg[t.data.index2].student_id
                });
                t.listFun();
                wx.hideLoading();
            }

        })
    },
    // banner
    bannerFun() {
        let t = this;
        let url = '/api/banner/index';
        app.post(url,{
            type: wx.getStorageSync('ident')==1?1:2
          }).then(res => {
            t.setData({
                banner: res.data.msg
            })
        })
    },
    //数据
    listFun() {
        let t = this;
        let url = '/api/studentwoke/paihang';
        let params = {
            class_id: t.data.class_id,
            style: t.data.parid,
            student_id: t.data.student_id
        };
        app.post(url, params).then(res => {
            t.setData({
                list: res.data.msg,
                one: res.data.msg.bef[0],
                two: res.data.msg.bef[1],
                there: res.data.msg.bef[2],
                listtow: res.data.msg.list
            })
            t.onShareImg();
            wx.hideLoading();
        })
    },
    // 轮播底部原点
    swiperChange: function(e) {
        this.setData({
            currentSwiper: e.detail.current
        })
    },

    gay2(e) {
        wx.showLoading({
            title: '加载中',
        });
        this.setData({
            parid: e.currentTarget.dataset.parid,
            one: '',
            two: '',
            there: '',
            list: ''
        });
        this.listFun();
    },
    // 家长端选择班级
    bindPickerChange2(e) {
        wx.showLoading({
            title: '加载中',
        });
        this.setData({
            index2: e.detail.value,
            one: '',
            two: '',
            there: '',
            list: ''
        });
        this.classFun();
    },
    gonav1() {
        wx.redirectTo({
            url: '/pages/parentsDo/parentsDo?class_id=' + this.data.class_id,
        })
    },
    gonav2() {
        
    },
    gonav3() {
        wx.redirectTo({
            url: '/pages/parentsMy/parentsMy?class_id=' + this.data.class_id,
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

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

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

    },

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

    },

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

    },

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

    },

    /**
     * 用户点击右上角分享
     */

})