1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
// pages/add_record/index.js
const req = require('../../api/teacher.js')
const utils = require('../../utils/util.js')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
radioValues: [{
'value': '饮食',
'code': 'diet',
'selected': true
},
{
'value': '睡眠',
'code': 'sleep',
'selected': false
},
{
'value': '大小便',
'code': 'wc',
'selected': false
},
],
clazz: [],
studentIds: [],
controlIndex: 0,
categoryCode: ['diet_morning', 'diet_morning_more', 'diet_afternoon', 'diet_afternoon_more', 'diet_evening'],//, 'diet_water', 'diet_milk'
// 饮食子分类
categorys: [],
wcCategoryCode: ['wc_pee', 'wc_poo','wc_diaper'],
// 大小便子分类
wcCategorys:[],
typeIndex: 0,
inputModel: [
],
selectPic: [],
/* 所有的小分类字典 */
recordTypes: app.globalData.recordTypes,
/* 吃饭类型的选项字典 */
eatStates: app.globalData.eatStates,
eatCellTags: {},
//获取到的数据
eatRecord: [],
sleepRecord: [],
wcRecord: [],
// 如果是多个学生, 则不显示添加图片区域和备注
hidePhoto: false,
pictureIds: [],
pictureUrl: [],
//学生备注
remark:'',
//图片备注
picRemark: '',
isHideBtn: false,
},
//添加图片
addPicture: function(e) {
var that = this;
// 选择图片
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function(res) {
//选中的图片路径
let temPath = res.tempFilePaths[0]
that.data.selectPic.push(temPath)
that.setData({
selectPic: that.data.selectPic
});
wx.uploadFile({
url: utils.uploadPath(),
filePath: temPath,
name: 'file',
header: {
'access-token': utils.getAccessToken()
},
success(res) {
const resData = JSON.parse(res.data)
// 获取服务端图片id
that.data.pictureIds.push(resData.obj)
that.data.pictureUrl.push(utils.handleImgShow(resData.obj))
if (resData.obj) {
that.setData({
pictureIds: that.data.pictureIds,
pictureUrl: that.data.pictureUrl
})
} else {
throw new Error({
msg: '图片上传失败'
})
}
},
fail(err) {
wx.showToast({
title: err.msg,
icon: 'none'
})
}
})
}
})
},
previewPic: function(e) {
var current = this.data.pictureUrl[e.target.dataset.index]
wx.previewImage({
current: current,
urls: this.data.pictureUrl
})
},
remarkInput: function (e) {
console.log(e)
let inputValue = e.detail.value
this.setData({
remark: inputValue
})
},
picRemarkInput: function (e) {
console.log(e)
let inputValue = e.detail.value
this.setData({
picRemark: inputValue
})
},
headerBtnTap: function (e) {
var arrRecord = []
let eatState = null
if (this.data.controlIndex == 0) {
arrRecord = this.data.eatRecord
} else if (this.data.controlIndex == 1) {
arrRecord = this.data.sleepRecord
} else if (this.data.controlIndex == 2) {
arrRecord = this.data.wcRecord;
}
var arrRecordList = []
var item = arrRecord[0].recordItems[0]
if (item == null) {
wx.showToast({
title: '该记录已经删除',
icon: 'none'
})
return
}
req.deleteRecord(item.id).then(res=>{
console.log(res)
wx.showToast({
title: '删除成功~',
duration: 1500
})
setTimeout(() => {
wx.navigateBack({
})
}, 1500)
}).catch(function (err) {
wx.showToast({
title: err.message ? err.message : '网络错误',
icon: 'none',
duration: 2000
});
});
},
//删除图片
deleteImg: function(e) {
var that = this
that.data.selectPic.splice(e.currentTarget.dataset.index, 1)
that.data.pictureIds.splice(e.currentTarget.dataset.index, 1)
that.data.pictureUrl.splice(e.currentTarget.dataset.index, 1)
that.setData({
selectPic: that.data.selectPic,
pictureIds: that.data.pictureIds,
pictureUrl: that.data.pictureUrl
})
},
//选择小分类
tapType: function(e) {
let index = null
if (e.target.dataset.index != this.data.typeIndex) {
index = e.target.dataset.index
}
this.setData({
typeIndex: index,
})
this.getRecord()
},
indexChanged: function(e) {
// 点中的是组中第个元素
var index = e.target.dataset.index;
// 读取原始的数组
var radioValues = this.data.radioValues;
for (var i = 0; i < radioValues.length; i++) {
// 全部改为非选中
radioValues[i].selected = false;
// 当前那个改为选中
radioValues[index].selected = true;
}
// console.log(radioValues)
// 写回数据
this.setData({
radioValues: radioValues,
controlIndex: index
});
// clazz状态
this.clazzStatus();
this.getRecord()
},
// 初始化分类数据
configCategory: function() {
// 饮食分类
var categorys = this.data.categorys
for (var i = 0; i < this.data.categoryCode.length; i++) {
let category = this.data.recordTypes[this.data.categoryCode[i]]
categorys.push(category)
}
var wcCategorys = this.data.wcCategorys
for (var i = 0; i < this.data.wcCategoryCode.length; i++) {
let category = this.data.recordTypes[this.data.wcCategoryCode[i]]
wcCategorys.push(category)
}
this.setData({
categorys: categorys,
wcCategorys: wcCategorys
})
},
// 调用接口获取数据
getRecord: function() {
let studentIds = this.data.studentIds
console.log(studentIds)
let category = this.data.radioValues[this.data.controlIndex].code
let type = ''
if (this.data.controlIndex == 0) {
type = this.data.categoryCode[this.data.typeIndex]
} else if (this.data.controlIndex == 2){
type = this.data.wcCategoryCode[this.data.typeIndex]
}
req.queryRecordList(category, type, studentIds).then(res => {
console.log(res)
var eatCellTags = this.data.eatCellTags
var optionTag = ['diet_morning', 'diet_afternoon', 'diet_evening', 'diet_morning_more', 'diet_afternoon_more']
for (var i = 0; i < res.length; i++) {
var item = res[i]
if (item.recordItems.length == 0) {
//没有记录时, 自动生成一条
var r = {}
r.recordType = type
r.recordCategory = category
item.recordItems.push(r)
}
for (var k = 0; k < item.recordItems.length; k++) {
var r = item.recordItems[k]
if (r.recordCategory == 'sleep') {
r.cellType = 'input'
r.cellUnit = '分钟'
break
}
if (r.recordType == 'diet_milk') {
r.cellType = 'input'
r.cellUnit = '毫升'
break
}
if (r.recordType == 'diet_water' || this.data.wcCategoryCode.indexOf(r.recordType) != -1) {
r.cellType = 'input'
r.cellUnit = '次'
break
}
for (var j = 0, len = optionTag.length; j < len; j++) {
var tag = optionTag[j]
if (r.recordType == tag) {
r.cellType = 'select'
r.cellOptions = ['少', '正常', '多']
let eatStatus = Object.keys(this.data.eatStates)
r.optionIndex = eatStatus.indexOf(r.eatState)
break
}
}
}
// 如果小分类没有被选中,去除数据
if (this.data.typeIndex == null) {
item.recordItems = []
}
}
if (this.data.controlIndex == 0) {
this.setData({
eatRecord: res
})
} else if (this.data.controlIndex == 1) {
this.setData({
sleepRecord: res
})
} else if (this.data.controlIndex == 2) {
// for (var i = 0; i < res.length; i++) {
// var item = res[i]
// var pee = '0'
// var poo = '0'
// var diaper = '0'
// item.cellType = 'select'
// item.cellOptions = ['小便', '大便', '尿不湿']
// for (var j = 0; j < item.recordItems.length; j++) {
// var r = item.recordItems[j]
// if (r.recordType == 'wc_pee') {
// pee = r.value
// } else if (r.recordType == 'wc_poo') {
// poo = r.value
// } else if (r.recordType == 'wc_diaper') {
// diaper = r.value
// }
// console.log('pee ' + pee + ' poo ' + poo + ' diaper ' + diaper)
// }
// let wcString = '小便 ' + pee + '次 大便 ' + poo + '次 尿不湿 ' + diaper + '次'
// item.wcString = wcString
// }
this.setData({
wcRecord: res
})
}
if (this.data.studentIds.length == 1) {
let std = res[0]
this.setData({
isHideBtn: std.state == 'finish'
})
}
})
},
// 点击cell上面的选项的点击事件
quantityCellTap: function(e) {
console.log(e.currentTarget.dataset)
let optionIndex = e.currentTarget.dataset.optionindex
let cellIndex = e.currentTarget.dataset.cellindex
let records = this.getCurrentRecord()
var item = records[cellIndex].recordItems[0]
let selectIndex = e.currentTarget.dataset.optionindex
// if (this.data.controlIndex == 2) {
// if (records[cellIndex].optionIndex == selectIndex) {
// records[cellIndex].optionIndex = null
// }else{
// records[cellIndex].optionIndex = selectIndex
// }
// } else {
if (item.optionIndex == selectIndex) {
item.optionIndex = null
}else{
item.optionIndex = selectIndex
}
// }
if (this.data.controlIndex == 0) {
this.setData({
eatRecord: records
})
} else if (this.data.controlIndex == 1) {
this.setData({
sleepRecord: records
})
} else if (this.data.controlIndex == 2) {
this.setData({
wcRecord: records
})
}
},
// cell上面的输入事件
bindKeyInput: function(e) {
let value = e.detail.value
let cellIndex = e.currentTarget.dataset.cellindex
console.log(e)
let records = this.getCurrentRecord()
var item = records[cellIndex].recordItems[0]
item.value = value
if (this.data.controlIndex == 0) {
this.setData({
eatRecord: records
})
} else if (this.data.controlIndex == 1) {
this.setData({
sleepRecord: records
})
} else if (this.data.controlIndex == 2) {
this.setData({
wcRecord: records
})
}
},
// 返回当前点击的大类的数据
getCurrentRecord: function() {
var arrRecord = []
if (this.data.controlIndex == 0) {
arrRecord = this.data.eatRecord
} else if (this.data.controlIndex == 1) {
arrRecord = this.data.sleepRecord
} else if (this.data.controlIndex == 2) {
arrRecord = this.data.wcRecord;
}
return arrRecord
},
// 点击底部的保存按钮
operateTap: function(event) {
console.log(event._relatedInfo.anchorTargetText)
var arrRecord = []
let eatState = null
if (this.data.controlIndex == 0) {
arrRecord = this.data.eatRecord
} else if (this.data.controlIndex == 1) {
arrRecord = this.data.sleepRecord
} else if (this.data.controlIndex == 2) {
arrRecord = this.data.wcRecord;
}
var arrRecordList = []
for (var i = 0; i < arrRecord.length; i++) {
var item = arrRecord[i]
for (var j = 0; j < item.recordItems.length; j++) {
var recordItem = item.recordItems[j]
var value = recordItem.value;
let addRecord = {
"id": recordItem.id,
"createName": recordItem.createName,
"createBy": recordItem.createBy,
"createDate": recordItem.createDate,
"updateName": recordItem.updateName,
"updateBy": recordItem.updateBy,
"updateDate": recordItem.updateDate,
"sysOrgCode": recordItem.sysOrgCode,
"sysCompanyCode": recordItem.sysCompanyCode,
"recordCategory": recordItem.recordCategory,
"recordType": recordItem.recordType,
"eatState": Object.keys(this.data.eatStates)[recordItem.optionIndex],
"value": value,
"signSummaryId": item.signSummaryId
}
// 如果是饮食分类没有选中选项的时候,不保存明细
if (this.data.controlIndex == 0 && (recordItem.optionIndex == null || recordItem.optionIndex == -1)) {
continue
}
arrRecordList.push(addRecord)
}
}
let signSummaryId = null
let remark = null
let picRemark = null
if (this.data.studentIds.length == 1) {
signSummaryId = arrRecord[0].signSummaryId
remark = this.data.remark
picRemark = this.data.picRemark
}
req.setRecord(signSummaryId,arrRecordList,this.data.pictureIds, remark, picRemark).then(res => {
wx.showToast({
title: '保存成功~',
duration: 1500
})
setTimeout(() => {
wx.navigateBack({
})
}, 1500)
})
},
onLoad: function(options) {
this.data.studentIds = JSON.parse(options.studentIds)
let remark = options.remark
let picRemark = options.picRemark
if (options.pictureIds != null) {
this.data.pictureIds = JSON.parse(options.pictureIds)
}
for (var i = 0; i < this.data.pictureIds.length; i++) {
this.data.pictureUrl.push(utils.handleImgShow(this.data.pictureIds[i]))
}
this.setData({
pictureUrl: this.data.pictureUrl,
remark: remark != null ? remark : '',
picRemark: picRemark != null? picRemark : ''
})
console.log(this.data.pictureIds)
if (this.data.studentIds.length > 1) {
this.setData({
hidePhoto: true
})
}
// onLoad 比 onReady 更早调用,后者为选中时屏幕闪动一下
this.clazzStatus();
//分类数据
this.configCategory()
//获取选中的分类的记录
this.getRecord()
},
clazzStatus: function() {
/* 此方法分别被加载时调用,点击某段时调用 */
// class样式表如"selected last","selected"
var clazz = [];
// 参照数据源
var radioValues = this.data.radioValues;
for (var i = 0; i < radioValues.length; i++) {
// 默认为空串,即普通按钮
var cls = '';
// 高亮,追回selected
if (radioValues[i].selected) {
cls += 'selected ';
}
// 最后个元素, 追加last
if (i == radioValues.length - 1) {
cls += 'last ';
}
//去掉尾部空格
cls = cls.replace(/(\s*$)/g, '');
clazz[i] = cls;
}
// console.log(clazz)
// 写回数据
this.setData({
clazz: clazz
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})