index.js 3.89 KB
Newer Older
张杰's avatar
张杰 committed
1
// pages/review_student/index.js
SmileFei's avatar
SmileFei committed
2
const request = require('../../api/teacher.js')
张杰's avatar
张杰 committed
3
const utils = require('../../utils/util.js')
SmileFei's avatar
SmileFei committed
4

张杰's avatar
张杰 committed
5 6 7 8 9 10
Page({

  /**
   * 页面的初始数据
   */
  data: {
SmileFei's avatar
SmileFei committed
11
    signSummaryId: "",
SmileFei's avatar
SmileFei committed
12
    recordDetail: {},
SmileFei's avatar
SmileFei committed
13
    showAuditBtn: true,
SmileFei's avatar
SmileFei committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    recordTypes: {
      "diet_morning": '早餐',
      "diet_afternoon": "午餐",
      "diet_milk": "牛奶",
      "diet_evening": "晚餐",
      "diet_morning_more": "上午加餐",
      "diet_afternoon_more": "下午加餐",
      "diet_water": "喝水",
      "diet_milk": "饮用牛奶",
      "sleep_time": "睡觉时间",
      "wc_pee": "小便",
      "wc_poo": "便",
      "wc_diaper": "换尿布"
    },
    eatStates: {
      "less": "少",
      "normal": "正常",
      "more": "多"
    }
  },

  //加载详情
  getRecordDetailForSignId: function() {
    request.getRecordDetailForSignId(this.data.signSummaryId).then(res => {
SmileFei's avatar
SmileFei committed
38
      console.log(res)
SmileFei's avatar
SmileFei committed
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
      if (res) {
        var dateStr = res.recordDate.substr(0, 10)
        let show_day = new Array('周日', '周一', '周二', '周三', '周四', '周五', '周六');
        let date = new Date(dateStr);
        var num = date.getDay()
        res.recordDate = dateStr + " " + show_day[date.getDay()]

        // 饮食
        var dietRecords = res['dietRecord']
        for (var j = 0; j < dietRecords.length; j++) {
          var diet = dietRecords[j]
          diet.z_recordType = this.data.recordTypes[diet.recordType]
          diet.z_eatState = this.data.eatStates[diet.eatState]
        }

        // 睡觉
        var sleepRecord = res.sleepRecord
        for (var j = 0; j < sleepRecord.length; j++) {
          var r = sleepRecord[j]
          r.z_recordType = this.data.recordTypes[r.recordType]
        }

        // wc
        var wcRecord = res.wcRecord
        for (var j = 0; j < wcRecord.length; j++) {
          var r = wcRecord[j]
          r.z_recordType = this.data.recordTypes[r.recordType]
        }
SmileFei's avatar
SmileFei committed
67 68 69 70 71
        if (res.state == "finish") {
          this.setData({
            showAuditBtn: false
          })
        }
SmileFei's avatar
SmileFei committed
72
        this.setData({
SmileFei's avatar
SmileFei committed
73
          recordDetail: res
SmileFei's avatar
SmileFei committed
74 75 76 77 78 79 80 81 82 83 84
        })
      }

    }).catch(err => {
      wx.showToast({
        title: err.message,
        icon: 'none',
        duration: 2000
      })
    })
  },
张杰's avatar
张杰 committed
85

SmileFei's avatar
SmileFei committed
86
  auditSignSummary: function(signSummaryId) {
SmileFei's avatar
SmileFei committed
87 88
    console.log(signSummaryId)
    request.auditSignSummary(signSummaryId).then(res => {
SmileFei's avatar
SmileFei committed
89 90 91
      this.setData({
        showAuditBtn: false
      })
SmileFei's avatar
SmileFei committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
      wx.showToast({
        title: '审核成功!',
        icon: 'none',
        duration: 2000
      })
    }).catch(err => {
      wx.showToast({
        title: err.message,
        icon: 'none',
        duration: 2000
      })
    })

  },

SmileFei's avatar
SmileFei committed
107 108
  operateTap: function(e) {
    this.auditSignSummary(this.data.signSummaryId)
张杰's avatar
张杰 committed
109 110 111 112 113
  },

  /**
   * 生命周期函数--监听页面加载
   */
SmileFei's avatar
SmileFei committed
114 115
  onLoad: function(options) {
    this.data.signSummaryId = options.signSummaryId;
张杰's avatar
张杰 committed
116 117 118 119 120 121 122 123 124 125 126 127
    if (options.pictureIds != null) {
      this.data.pictureIds = JSON.parse(options.pictureIds)
      var arrPic = []
      for (var i = 0; i < this.data.pictureIds.length; i++) {
        let id = this.data.pictureIds[i]
        arrPic.push(utils.handleImgShow(id))
      }
      this.setData({
        arrPic: arrPic
      })
    }

SmileFei's avatar
SmileFei committed
128
    this.getRecordDetailForSignId()
张杰's avatar
张杰 committed
129 130 131 132 133
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
SmileFei's avatar
SmileFei committed
134
  onReady: function() {
张杰's avatar
张杰 committed
135 136 137 138 139 140

  },

  /**
   * 生命周期函数--监听页面显示
   */
SmileFei's avatar
SmileFei committed
141
  onShow: function() {
张杰's avatar
张杰 committed
142 143 144 145 146 147

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
SmileFei's avatar
SmileFei committed
148
  onHide: function() {
张杰's avatar
张杰 committed
149 150 151 152 153 154

  },

  /**
   * 生命周期函数--监听页面卸载
   */
SmileFei's avatar
SmileFei committed
155
  onUnload: function() {
张杰's avatar
张杰 committed
156 157 158 159 160 161

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
SmileFei's avatar
SmileFei committed
162
  onPullDownRefresh: function() {
张杰's avatar
张杰 committed
163 164 165 166 167 168

  },

  /**
   * 页面上拉触底事件的处理函数
   */
SmileFei's avatar
SmileFei committed
169
  onReachBottom: function() {
张杰's avatar
张杰 committed
170 171 172 173 174 175

  },

  /**
   * 用户点击右上角分享
   */
SmileFei's avatar
SmileFei committed
176
  onShareAppMessage: function() {
张杰's avatar
张杰 committed
177 178 179

  }
})