homework.js 6.7 KB
// pages/homework/homework.js\
let utils = require('../../utils/util.js');
const app = getApp();
let theTimer;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentSwiper: 0,
        currentData: 2,
        page: 1,
        hw_width: '',
        test: false
      },
      quitTest(){
        app.quitTest()
      },
        // 前往历史页面
      goRecord() {
        wx.navigateTo({
          url: '/pages/workRecord/workRecord?type=teach',
        })
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        wx.stopPullDownRefresh();
        wx.showLoading({
            title: '加载中',
        });
        this.setData({
          test:wx.getStorageSync('testCount')
        })
        
        this.bannerFun();
    },
    navgate(e){
      wx.navigateTo({
        url: '/pages/newsDetail/newsDetail?src='+e.currentTarget.dataset.src,
      })
  },
    // 轮播图接口
    bannerFun() {
        let t = this;
        let url = "/api/banner/index";
        app.post(url,{
          type:1
        }).then(res => {
            console.log(res.data);
            t.setData({
                banner: res.data.msg
            });
            wx.hideLoading();
        })
    },
    gonav1() {
        wx.redirectTo({
            url: '/pages/index/index?fenId='+ "",
        })
    },
    gonav2() {
        
    },
    gonav3() {
        wx.redirectTo({
            url: '/pages/my/my',
        })
    },
    // 数据接口
    dataFun() {
        let t = this;
        let url = '/api/teacher/classlist';
        let params = {
            status: t.data.currentData,
            page: this.data.page
        };
        wx.showLoading({
          title: '加载中',
        });
        app.post(url, params).then(res => {
            console.log(res);
            if (res.data.code == 5000) {
                wx.redirectTo({
                    url: '/pages/my/my',
                })
            } else {
              t.setData({
                nodata: res.data.msg.length<4?true:false,
                baselist: t.data.baselist.concat(res.data.msg)
              })
              console.log(t.data.baselist)
              if(res.data.msg.length>0){
                let data = t.data.baselist;
                clearInterval(theTimer);

                function time() {
                  data.forEach(function (ele, index) {
                    var a = new Date().getTime()
                    a = Math.floor(a / 1000);
                    var startTime = 0,
                      endTime = 0;
                    if (a < ele.endtime) {
                      startTime = a
                      endTime = ele.endtime
                    } else {
                      ele.endtime = 0;
                    }
                    var timeDiff = ele.endtime - startTime;
                    var hour = Math.floor(timeDiff / 3600);
                    timeDiff = timeDiff % 3600;
                    var minute = Math.floor(timeDiff / 60);
                    timeDiff = timeDiff % 60;
                    var 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;
                    let width = ((ele.wanc.wannum / ele.wanc.totalnum) * 272) + 'rpx';
                    ele['jd'] = width;
                    ele['endtime1'] = zoTime;

                  })
                  t.setData({
                    list: data,
                  });
                }
                time();
                theTimer = setInterval(time, 1000);
                wx.hideLoading();
              }else{

                wx.showToast({
                  title: '没有更多了',
                  icon:'none'
                })
              }

            }

        })
    },
    // 前往商品详情
    goDetail(e) {
        let t = this;
        let id = e.currentTarget.dataset.zid;
        let classid = e.currentTarget.dataset.classid;
        wx.removeStorageSync('tempWork');
        wx.navigateTo({
            url: '/pages/detail/detail?zid=' + id + '&classid=' + classid,
        })
    },

    // 轮播底部原点
    swiperChange: function(e) {
        this.setData({
            currentSwiper: e.detail.current
        })
    },

    // tab切换
    gay(e) {
        wx.showLoading({
            title: '加载中',
        });
        clearInterval(theTimer);
        this.setData({
            list: [],
          baselist:[],
            page:1
        })
        let t = this;
        this.setData({
            currentData: e.currentTarget.dataset.current
        })
        t.dataFun();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        wx.showLoading({
            title: '加载中',
        })
        this.setData({
            page:1,
            list:[],
            baselist:[]
        });
        clearInterval(theTimer);
        this.dataFun();
    },

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

    },

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

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
    },
    
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
      if(this.data.nodata){
        wx.showToast({
          title: '没有更多了',
          icon:'none'
        })
      }else{
        this.setData({
          page: this.data.page+1
        })
        this.dataFun()
      }
        // wx.showLoading({
        //     title: '加载中',
        // })
        // let t = this;
        // let url = '/api/teacher/classlist';
        // let params = {
        //     status: t.data.currentData,
        //     page: t.data.page
        // };
        // app.post(url, params).then(res => {
        //     console.log(res);
        //     if (res.data.msg != "") {
        //       console.log(res.data.msg)
        //         t.setData({
        //             list: t.data.list.concat(res.data.msg),
        //             page: t.data.page + 1
        //         })
        //         console.log(t.data.list)
        //         wx.hideLoading();
        //     } else if (res.data.msg == "") {
        //         wx.showToast({
        //             title: '已经没有数据了',
        //             icon: 'none'
        //         })
        //     }
        // })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})