审查视图

pages/parentsDo/parentsDo.js 8.0 KB
lihongjuan authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
// 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() {

  }
})