index.js 5.01 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')
张杰's avatar
张杰 committed
4
const app = getApp()
SmileFei's avatar
SmileFei committed
5

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

  /**
   * 页面的初始数据
   */
  data: {
SmileFei's avatar
SmileFei committed
12
    signSummaryId: "",
SmileFei's avatar
SmileFei committed
13
    recordDetail: {},
SmileFei's avatar
SmileFei committed
14
    showAuditBtn: true,
张杰's avatar
张杰 committed
15 16
    /* 所有的小分类字典 */
    recordTypes: app.globalData.recordTypes,
SmileFei's avatar
SmileFei committed
17 18 19 20
    eatStates: {
      "less": "少",
      "normal": "正常",
      "more": "多"
张杰's avatar
张杰 committed
21 22 23 24 25 26 27
    },
    //学生备注
    remark: '',
    //图片备注
    picRemark: '',
    studentName: '',
    kindergarten: '',
张杰's avatar
张杰 committed
28
    sex: '',
张杰's avatar
张杰 committed
29 30
    pictureIds: [],
    studentPicture: '/src/img/defaut_teacher_icon.png'
SmileFei's avatar
SmileFei committed
31 32 33 34 35
  },

  //加载详情
  getRecordDetailForSignId: function() {
    request.getRecordDetailForSignId(this.data.signSummaryId).then(res => {
SmileFei's avatar
SmileFei committed
36
      console.log(res)
SmileFei's avatar
SmileFei committed
37 38 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
      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
65 66 67 68 69
        if (res.state == "finish") {
          this.setData({
            showAuditBtn: false
          })
        }
SmileFei's avatar
SmileFei committed
70
        this.setData({
SmileFei's avatar
SmileFei committed
71
          recordDetail: res
SmileFei's avatar
SmileFei committed
72 73 74 75 76 77 78 79 80 81 82
        })
      }

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

SmileFei's avatar
SmileFei committed
84
  auditSignSummary: function(signSummaryId) {
SmileFei's avatar
SmileFei committed
85
    console.log(signSummaryId)
张杰's avatar
张杰 committed
86 87 88 89 90 91 92 93 94
    let record = this.data.recordDetail
    if (record.dietRecord.length == 0 && record.sleepRecord.length == 0 && record.wcRecord.length == 0) {
      wx.showToast({
        title: '没有记录,无法审批',
        icon: 'none',
      })
      return
    }

SmileFei's avatar
SmileFei committed
95
    request.auditSignSummary(signSummaryId).then(res => {
SmileFei's avatar
SmileFei committed
96 97 98
      this.setData({
        showAuditBtn: false
      })
SmileFei's avatar
SmileFei committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
      wx.showToast({
        title: '审核成功!',
        icon: 'none',
        duration: 2000
      })
    }).catch(err => {
      wx.showToast({
        title: err.message,
        icon: 'none',
        duration: 2000
      })
    })

  },

张杰's avatar
张杰 committed
114 115

  previewPic: function (e) {
张杰's avatar
张杰 committed
116 117 118
    let index = e.target.dataset.picindex
    console.log(e)
    var current = this.data.arrPic[index]
张杰's avatar
张杰 committed
119 120 121 122 123 124 125
    wx.previewImage({
      current: current,
      urls: this.data.arrPic
    })

  },

张杰's avatar
张杰 committed
126 127 128 129
  tapCell: function (e) {
    console.log(e)
    let student = this.data.recordDetail
    wx.navigateTo({
张杰's avatar
张杰 committed
130
      url: '/pages/add_record/index?studentIds=' + JSON.stringify([this.data.signSummaryId]) + '&pictureIds=' + JSON.stringify(this.data.pictureIds) + '&remark=' + (this.data.remark ? this.data.remark : '') + '&picRemark=' + (this.data.picRemark ? this.data.picRemark : ''),
张杰's avatar
张杰 committed
131 132 133
    })
  },

SmileFei's avatar
SmileFei committed
134 135
  operateTap: function(e) {
    this.auditSignSummary(this.data.signSummaryId)
张杰's avatar
张杰 committed
136 137 138 139 140
  },

  /**
   * 生命周期函数--监听页面加载
   */
SmileFei's avatar
SmileFei committed
141 142
  onLoad: function(options) {
    this.data.signSummaryId = options.signSummaryId;
张杰's avatar
张杰 committed
143 144
    let remark = options.remark
    let picRemark = options.picRemark
张杰's avatar
张杰 committed
145 146 147 148 149 150
    let studentPicture = options.studentPicture
    if (studentPicture != 'null') {
      this.setData({
        studentPicture: utils.handleImgShow(studentPicture)
      })
    }
张杰's avatar
张杰 committed
151 152 153 154 155 156 157
    this.setData({
      remark: remark,
      picRemark: picRemark, 
      studentName: options.studentName,
      sex: options.sex
    })

张杰's avatar
张杰 committed
158 159 160 161 162 163 164 165 166 167 168 169
    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
170
    this.getRecordDetailForSignId()
张杰's avatar
张杰 committed
171 172 173 174 175
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
SmileFei's avatar
SmileFei committed
176
  onReady: function() {
张杰's avatar
张杰 committed
177 178 179 180 181 182

  },

  /**
   * 生命周期函数--监听页面显示
   */
SmileFei's avatar
SmileFei committed
183
  onShow: function() {
张杰's avatar
张杰 committed
184 185 186 187 188 189

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
SmileFei's avatar
SmileFei committed
190
  onHide: function() {
张杰's avatar
张杰 committed
191 192 193 194 195 196

  },

  /**
   * 生命周期函数--监听页面卸载
   */
SmileFei's avatar
SmileFei committed
197
  onUnload: function() {
张杰's avatar
张杰 committed
198 199 200 201 202 203

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
SmileFei's avatar
SmileFei committed
204
  onPullDownRefresh: function() {
张杰's avatar
张杰 committed
205 206 207 208 209 210

  },

  /**
   * 页面上拉触底事件的处理函数
   */
SmileFei's avatar
SmileFei committed
211
  onReachBottom: function() {
张杰's avatar
张杰 committed
212 213 214 215 216 217

  },

  /**
   * 用户点击右上角分享
   */
SmileFei's avatar
SmileFei committed
218
  onShareAppMessage: function() {
张杰's avatar
张杰 committed
219 220 221

  }
})