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

    /**
     * 页面的初始数据
     */
    data: {
        date: '输入查询日期',
        page:1,
        pageSize: 10,
        Worklist:[],
        baselist:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData({
            type: options.type||'student'
        })
    },
    // 数据接口
    dataFun() {
        let t = this;
        let url = '/api/teacher/get_homework';
        let params = {
            starttime: t.data.date,
            page: this.data.page,
            pageNum: t.data.pageSize

        };
       
        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;

                  })
                  console.log()
                  t.setData({
                    Worklist: 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,
        })
    },
    // 搜索接口
    searchFun() {
        let t = this;
        let url = t.data.type == 'student'?'/api/StudentWoke/search':'/api/teacher/get_homework';
        let list = [];
        let params = t.data.type == 'student'?({
            createtime: t.data.date
        }):({
            starttime: t.data.date,
            page: t.data.page,
            pageNum: t.data.pageSize
        })
        
        app.post(url, params).then(res => {
            if (res.data.msg == "") {
                wx.showToast({
                    title: '暂无作业记录',
                    icon: 'none'
                })
            } else {
              res.data.msg.gq.forEach((ele, ind) => {
                    if (ele != '') {
                        ele.forEach((ele2, ind2) => {
                            list.push(ele2);
                        })
                    }
                })
              res.data.msg.successs.forEach((ele, ind) => {
                if (ele != '') {
                  ele.forEach((ele2, ind2) => {
                    list.push(ele2);
                  })
                }
              })
                t.setData({
                    list: list
                })
            }
        })
    },
    // 前往作业详情
    goDetail(e) {
        let t = this;
        let id = e.currentTarget.dataset.id;
        let classId = e.currentTarget.dataset.classid;
        wx.navigateTo({
            url: '/pages/parentsDetail/parentsDetail?id=' + id + '&classId=' + classId,
        })
    },
    // 输入picker
    bindDateChange(e) {
        console.log(e);
        this.setData({
            date: e.detail.value
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

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

    },

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

    },

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

    },

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

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        if(this.data.type == 'teach'){
            if(this.data.nodata){
                wx.showToast({
                  title: '没有更多了',
                  icon: "none"
                })
            }else{
                this.setData({
                    page: this.data.page + 1
                })
                this.dataFun()
            }
        }
    },

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

    }
})