// pages/home/teacher/index.js
const request = require('../../../api/teacher.js')
const utils = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    signIcon: "/src/img/signin.png",
    userIcon: "/src/img/defaut_teacher_icon.png",
    records: [],

  },

  tapCell: function(e) {
    console.log(e)
    let studentId = e.currentTarget.dataset.studentid
    wx.navigateTo({
      url: '/pages/add_record/index?studentIds=' + JSON.stringify([studentId]),
    })

  },

  operateTap: function(event) {
    console.log(event._relatedInfo.anchorTargetText)
    var studentIds = []
    for (var i = 0; i < this.data.records.length; i++) {
      studentIds.push(this.data.records[i].id)
    }
    wx.navigateTo({
      url: '/pages/add_record/index?studentIds=' + JSON.stringify(studentIds),
    })
  },

  signTap: function(e) {
    wx.navigateTo({
      url: '/pages/home/sign/index',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // 设置日期
    let date = new Date()
    let dateStr = utils.formatDate(date)
    this.setData({
      dateStr: dateStr
    })



    request.querySignSummary("4028048267a65d0f0167a69ae1910058", "4028048267a5969b0167a5b22f3807f8").then(res => {
      console.log(res)

      for (var i = 0; i < res.length; i++) {
        var item = res[i]
        item.signDate = item.signDate.substr(0, 10)
      }
      this.setData({
        records: res
      })

    })



  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})