parentsDo.js 8.0 KB
// pages/parentsDo/parentsDo.js
const app = getApp();
let theTimer;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner: [],
    currentSwiper: 0,
    ycomplete: [],
    dcomplete: [],
    class_id: "",
    getMessage: false,
    currentData:2,
    test: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var inent = wx.getStorageSync('ident');
    let tokens = wx.getStorageSync('token');
    let t = this;
    this.setData({
      class_id: options.class_id,
      id: options.id,
      where: options.where,
      test:wx.getStorageSync('testCount')
    })
    this.bannerFun();
    if (tokens) {
      if (inent === "0"||inent=='2') {
        wx.showLoading({
          title: '加载中',
        });
        // this.listFun();
        if(options.class_id&&options.class_id !='undefined'){
          this.myFun()
        }
      } else if (inent === "1" && options.where == 4) {
        wx.showModal({
          title: '提示',
          content: '您的身份是教师\r\n点击查看作业提交情况',
          showCancel: false,
          success(res) {
            if (res.confirm) {
              wx.redirectTo({
                url: '/pages/index/index?class_id=' + options.class_id + '&homeworkId=' + options.id + '&state=' + 9,
              })
            }
          }
        })
      } else if (inent === "1" && options.where == 5) {
        wx.showModal({
          title: '提示',
          content: '您的身份不可查看',
          showCancel: false,
          success(res) {
            if (res.confirm) {
              wx.redirectTo({
                url: '/pages/index/index'
              })
            }
          }
        })
      } else {
        wx.showModal({
          title: '提示',
          content: '请前往授权',
          success(res) {
            if (res.confirm) {
              wx.redirectTo({
                url: '/pages/new_calss/new_calss?class_id=' + options.class_id + '&id=' + options.id + '&where' + options.where,
              })
            }
          }
        })
      }
    }else{
      wx.redirectTo({
        url: '/pages/new_calss/new_calss?class_id=' + t.data.class_id + '&id=' + t.data.id + '&where' + t.data.where,
      })
    }
  },

  navgate(e){ 
    wx.navigateTo({
      url: '/pages/newsDetail/newsDetail?src='+e.currentTarget.dataset.src,
    })
  },
  quitTest(){
    app.quitTest()
  },
  // tab切换
  gay(e) {
    let t = this;
    this.setData({
      currentData: e.currentTarget.dataset.current
    })
  },
  

  myFun() {
    let t = this;
    let url;
    console.log(t.data.class_id=='undefined')
    if (t.data.class_id == "" || t.data.class_id == 'undefined') {
      url = '/api/StudentWoke/isjoin';
    } else {
      url = '/api/StudentWoke/isjoin?class_id=' + t.data.class_id;
    }

    app.gets(url).then(res => {
      console.log("课程权限管理:")
      console.log(res)
      if (res.data.code == 10000) {

        if (t.data.class_id === 'undefined') {
          if (t.data.ycomplete.length == 0 && t.data.dcomplete.length == 0){
            wx.showToast({
              title: '请加入班级后操作',
              icon:'none'
            })
          }
        }else{
          wx.showModal({
            title: '提示',
            content: '请加入班级',
            showCancel: false,
            success(res) {
              if (res.confirm) {
                wx.navigateTo({
                  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) {

            }
          }
        })
      }

    })
  },
  // 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/work';
    let ycomplete = [];
    let dcomplete = [];
    let gelong = [];
    this.setData({
      dcomplete:[]
    })
    app.post(url,{}).then(res => {
      wx.hideLoading();
      dcomplete = res.data.msg.dzye;
      if (dcomplete.length>0){
        function time() {
          dcomplete.forEach((ele, ind) => {
            let a = new Date().getTime();
            a = Math.floor(a / 1000);
            let startTime = 0;
            let endTime = 0;
            if (a < ele.endtime) {
              startTime = a;
              endTime = ele.endtime;
            } else {
              ele.endtime = 0;
            }
            let timeDiff = endTime - startTime;
            var hour = Math.floor(timeDiff / 3600);
            timeDiff = timeDiff % 3600;
            let minute = Math.floor(timeDiff / 60);
            timeDiff = timeDiff % 60;
            let second = timeDiff;
            if (hour <= 9) hour = '0' + hour;
            if (minute <= 9) minute = '0' + minute;
            if (second <= 9) second = '0' + second;
            let zoTime = hour + ':' + minute + ':' + second;
            ele['endtime1'] = zoTime;
          })
          t.setData({
            dcomplete: dcomplete
          });
        }
        time();
        theTimer = setInterval(time, 1000);
      }else{
        clearInterval(theTimer);
        theTimer = '';
        t.setData({
          dcomplete: []
        });
        console.log(t.data.dcomplete)
      }

      // var Reverse = res.data.msg.czye.reverse();
      t.setData({
        ycomplete: res.data.msg.czye
      });
      // t.myFun();
      wx.hideLoading();
    })
  },
  // 轮播底部原点
  swiperChange: function(e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  },
  // 前往详情页面
  goDetail(e) {
    let t = this;
    console.log(e);
    let id = e.currentTarget.dataset.id;
    let class_id = e.currentTarget.dataset.classid;

    wx.navigateTo({
      url: '/pages/submit/submit?id=' + id + '&class_id=' + class_id,
    })
  },
  goDetail2(e) {
    let t = this;
    let id = e.currentTarget.dataset.id;
    let class_id = e.currentTarget.dataset.classid;
    wx.navigateTo({
      url: '/pages/parentsDetail/parentsDetail?id=' + id + '&classId=' + class_id,
    })
  },
  // 前往历史页面
  goRecord() {
    wx.navigateTo({
      url: '/pages/workRecord/workRecord',
    })
  },
  gonav1() {

  },
  gonav2() {
    wx.redirectTo({
      url: '/pages/parentsList/parentsList?class_id=' + this.data.class_id,
    })
  },
  gonav3() {
    wx.redirectTo({
      url: '/pages/parentsMy/parentsMy?class_id=' + this.data.class_id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var inent = wx.getStorageSync('ident');
    let tokens = wx.getStorageSync('token');
    console.log('获取作业')
    if (tokens) {
      console.log()
      if (inent == "0" || inent == '2') {
        wx.showLoading({
          title: '加载中',
        });
        console.log('进入作业')
        this.listFun();
      }
    };
    wx.hi
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    clearInterval(theTimer);
    this.setData({
      dcomplete:[]
    })
  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})