index.js 3.03 KB
Newer Older
张杰's avatar
张杰 committed
1
// pages/home/parents/index.js
2 3

const request = require('../../../api/parrent.js')
4
const app = getApp()
5 6


张杰's avatar
张杰 committed
7 8 9 10 11 12
Page({

  /**
   * 页面的初始数据
   */
  data: {
13 14 15
    page: 0,
    pageSize: 15,
    records: [],
16
    recordTypes: app.globalData.recordTypes,
张杰's avatar
张杰 committed
17 18
    eatStates: app.globalData.eatStates
    
张杰's avatar
张杰 committed
19 20 21 22 23
  },

  /**
   * 生命周期函数--监听页面加载
   */
24 25
  onLoad: function(options) {
    const that = this
张杰's avatar
张杰 committed
26 27 28 29 30 31 32 33
    

    if (app.globalData.login.students.length == 0) {
      wx.showToast({
        title: '无学生信息, 请联系管理员',
        icon: 'none'
      })
      return
张杰's avatar
张杰 committed
34
    }
张杰's avatar
张杰 committed
35 36
    let student = app.globalData.login.students[0]
    var studentId = student.id
张杰's avatar
张杰 committed
37
    this.setData({
张杰's avatar
张杰 committed
38
      student:student
39
    })
张杰's avatar
张杰 committed
40

张杰's avatar
张杰 committed
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
    request.queryStudentRecord(that.data.page, that.data.pageSize, studentId).then(res => {
      console.log(res)
      let resData = res


      var record = resData['records']
      var templist = this.data.records
      for (var i = 0; i < record.length; i++) {
        var item = record[i]

        var dateStr = item.recordDate.substr(0, 10)
        let show_day = new Array('周日', '周一', '周二', '周三', '周四', '周五', '周六');
        let date = new Date(dateStr);
        var num = date.getDay()
        item.recordDate = dateStr + " " + show_day[date.getDay()]

        // 饮食
        var dietRecords = item['dietRecord']

        for (var j = 0; j < dietRecords.length; j++) {
          var diet = dietRecords[j]
          diet.z_recordType = that.data.recordTypes[diet.recordType]
          diet.z_eatState = that.data.eatStates[diet.eatState]
          if (diet.recordType == 'diet_milk') {
            diet.z_eatState = diet.value + "毫升"
          }
          if (diet.recordType == 'diet_water') {
            diet.z_eatState = diet.value + "次"
          }
        }
张杰's avatar
张杰 committed
71

张杰's avatar
张杰 committed
72 73 74 75 76
        // 睡觉
        var sleepRecord = item["sleepRecord"]
        for (var j = 0; j < sleepRecord.length; j++) {
          var r = sleepRecord[j]
          r.z_recordType = that.data.recordTypes[r.recordType]
张杰's avatar
张杰 committed
77

张杰's avatar
张杰 committed
78
        }
张杰's avatar
张杰 committed
79

张杰's avatar
张杰 committed
80 81 82 83 84
        // wc
        var wcRecord = item["wcRecord"]
        for (var j = 0; j < wcRecord.length; j++) {
          var r = wcRecord[j]
          r.z_recordType = that.data.recordTypes[r.recordType]
张杰's avatar
张杰 committed
85

张杰's avatar
张杰 committed
86
        }
张杰's avatar
张杰 committed
87

张杰's avatar
张杰 committed
88 89 90
        console.log(item)
        templist.push(item)
      }
张杰's avatar
张杰 committed
91 92


张杰's avatar
张杰 committed
93 94 95 96
      this.setData({
        records: templist,
        page: resData['paging']['page']
      })
张杰's avatar
张杰 committed
97

张杰's avatar
张杰 committed
98
    })
张杰's avatar
张杰 committed
99

张杰's avatar
张杰 committed
100 101 102 103 104
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
105
  onReady: function() {
张杰's avatar
张杰 committed
106 107 108 109 110 111

  },

  /**
   * 生命周期函数--监听页面显示
   */
112
  onShow: function() {
张杰's avatar
张杰 committed
113 114 115 116 117 118

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
119
  onHide: function() {
张杰's avatar
张杰 committed
120 121 122 123 124 125

  },

  /**
   * 生命周期函数--监听页面卸载
   */
126
  onUnload: function() {
张杰's avatar
张杰 committed
127 128 129 130 131 132

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
133
  onPullDownRefresh: function() {
张杰's avatar
张杰 committed
134 135 136 137 138 139

  },

  /**
   * 页面上拉触底事件的处理函数
   */
140
  onReachBottom: function() {
张杰's avatar
张杰 committed
141 142 143 144 145 146

  },

  /**
   * 用户点击右上角分享
   */
147
  onShareAppMessage: function() {
张杰's avatar
张杰 committed
148 149 150

  }
})