const tools = require('../../utils/tools.js');
const app = require('../../utils/util.js');
Page({
  data: {
    dataArr: [],
    showNull: false
  },
  goClass(e) {
    let id = e.currentTarget.dataset.item.id
    let name = e.currentTarget.dataset.item.clasName
    let clasEnd = e.currentTarget.dataset.item.clasEnd
    if (e.currentTarget.dataset.item.isActive == 0) {
      wx.showModal({
        showCancel: false,
        content: "还未到开班时间哦"
      })
    }
    if (e.currentTarget.dataset.item.isActive == 1) {
      wx.switchTab({
        url: '../myClass/myClass'
      })
    }
    if (e.currentTarget.dataset.item.isActive == 2) {
      wx.navigateTo({
        url: '../historyClass/historyClass?id=' + id + '&&name=' + name + '&&clasEnd=' + clasEnd
      })
    }
  },
  getArr(sessionKey) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/student/selWholeClas',
      method: "post",
      data: {
        sessionKey: sessionKey
      },
      success: (res) => {
        if (res.data.code == 0 && res.data.data.length != 0) {
          this.setData({
            dataArr: res.data.data
          })
        } else {
          this.setData({
            showNull: true
          })
        }
      }
    })
  },
  async onLoad() {
    const sessionKey = await tools.checkSessionAndLogin();
    this.getArr(sessionKey);
  }
})