index.js 3.94 KB
Newer Older
张杰's avatar
张杰 committed
1
// pages/home/teacher/index.js
张杰's avatar
张杰 committed
2 3
const request = require('../../../api/teacher.js')
const utils = require('../../../utils/util.js')
张杰's avatar
张杰 committed
4
const app = getApp()
张杰's avatar
张杰 committed
5 6 7 8 9 10
Page({

  /**
   * 页面的初始数据
   */
  data: {
11
    signIcon: "/src/img/signin.png",
张杰's avatar
张杰 committed
12
    userIcon: "",
13
    records: [],
张杰's avatar
张杰 committed
14
    userName:'',
张杰's avatar
张杰 committed
15
    subTitle:'共0人'
张杰's avatar
张杰 committed
16 17 18

  },

19 20 21 22 23 24 25 26 27
  previewPic: function(e) {
    var current = this.data.records[e.target.dataset.index].arrPic[e.target.dataset.picIndex]
    wx.previewImage({
      current: current,
      urls: this.data.records[e.target.dataset.index].arrPic
    })

  },

28 29
  tapCell: function(e) {
    console.log(e)
张杰's avatar
张杰 committed
30 31
    let index = e.currentTarget.dataset.index
    let student = this.data.records[index]
32
    wx.navigateTo({
张杰's avatar
张杰 committed
33
      url: '/pages/add_record/index?studentIds=' + JSON.stringify([student.id]) + '&pictureIds=' + JSON.stringify(student.arrIds) + '&remark=' + (student.remark ? student.remark : '') + '&picRemark=' + (student.pictureRemark ? student.pictureRemark : ''),
34 35 36 37 38
    })

  },

  operateTap: function(event) {
张杰's avatar
张杰 committed
39
    console.log(event._relatedInfo.anchorTargetText)
张杰's avatar
张杰 committed
40 41 42 43
    var studentIds = []
    for (var i = 0; i < this.data.records.length; i++) {
      studentIds.push(this.data.records[i].id)
    }
张杰's avatar
张杰 committed
44
    wx.navigateTo({
张杰's avatar
张杰 committed
45
      url: '/pages/add_record/index?studentIds=' + JSON.stringify(studentIds),
张杰's avatar
张杰 committed
46 47 48
    })
  },

49
  signTap: function(e) {
张杰's avatar
张杰 committed
50 51 52 53 54 55 56 57
    if (app.globalData.login.classes.length == 0) {
      wx.showToast({
        title: '无班级信息, 请联系管理员',
        icon: 'none'
      })
      return
    }
    var signSummary = app.globalData.login.classes[0].id
张杰's avatar
张杰 committed
58
    wx.navigateTo({
张杰's avatar
张杰 committed
59
      url: '/pages/home/sign/index?classId=' + signSummary,
张杰's avatar
张杰 committed
60 61 62
    })
  },

张杰's avatar
张杰 committed
63 64 65
  /**
   * 生命周期函数--监听页面加载
   */
66
  onLoad: function(options) {
张杰's avatar
张杰 committed
67 68
    this.setData({
      userName: app.globalData.login.user.userName,
张杰's avatar
张杰 committed
69
      userIcon: app.globalData.login.wxaUser.avatarUrl
张杰's avatar
张杰 committed
70
    })
张杰's avatar
张杰 committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84

  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
张杰's avatar
张杰 committed
85 86 87 88 89 90 91
    // 设置日期
    let date = new Date()
    let dateStr = utils.formatDate(date)
    this.setData({
      dateStr: dateStr
    })

张杰's avatar
张杰 committed
92 93 94 95 96 97 98 99
    if (app.globalData.login.classes.length == 0) {
      wx.showToast({
        title: '无班级信息, 请联系管理员',
        icon: 'none'
      })
      return
    }
    var signSummary = app.globalData.login.classes[0].id
张杰's avatar
张杰 committed
100 101 102 103
    var studentCount = app.globalData.login.classes[0].studentCount
    this.setData({
      subTitle: '共' + studentCount + '人'
    })
104

张杰's avatar
张杰 committed
105 106
    // request.querySignSummary("4028048267a65d0f0167a69ae1910058", "4028048267a5969b0167a5b22f3807f8").then(res => {
    request.querySignSummary(app.globalData.login.user.id, signSummary).then(res => {
张杰's avatar
张杰 committed
107 108 109 110
      console.log(res)

      for (var i = 0; i < res.length; i++) {
        var item = res[i]
111
        item.signDate = item.signDate.substr(0, 10)
张杰's avatar
张杰 committed
112 113
        let paymentType = app.globalData.studentPaymentTypes[item.studentPaymentType]
        item.signStudentName = item.signStudentName + ' (' + paymentType + ')'
张杰's avatar
张杰 committed
114 115 116 117 118 119 120 121 122 123 124 125
        var arrPic = []
        let arrIds = []
        if (item.picture != null && item.picture != '') {
          arrIds = item.picture.split(",")
          for (var j = 0; j < arrIds.length; j++) {
            let id = arrIds[j]
            arrPic.push(utils.handleImgShow(id))
          }
        }
        console.log(arrPic)
        item.arrIds = arrIds
        item.arrPic = arrPic
张杰's avatar
张杰 committed
126 127 128 129 130 131 132
      }
      this.setData({
        records: res
      })

    })

张杰's avatar
张杰 committed
133 134 135 136 137
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
138
  onHide: function() {
张杰's avatar
张杰 committed
139 140 141 142 143 144

  },

  /**
   * 生命周期函数--监听页面卸载
   */
145
  onUnload: function() {
张杰's avatar
张杰 committed
146 147 148 149 150 151

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
152
  onPullDownRefresh: function() {
张杰's avatar
张杰 committed
153 154 155 156 157 158

  },

  /**
   * 页面上拉触底事件的处理函数
   */
159
  onReachBottom: function() {
张杰's avatar
张杰 committed
160 161 162 163 164 165

  },

  /**
   * 用户点击右上角分享
   */
166
  onShareAppMessage: function() {
张杰's avatar
张杰 committed
167 168 169

  }
})