supervisorDaily.js
27 KB
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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
// tabWorkOrder/pages/supervisorDaily/supervisorDaily.js
var util = require("~/utils/timeFormat/time-utils.js");
import { resData } from "./resData"
import { tempRuleFnObj } from "./ruleFnObj"
import fn from '~/components/GLCustForm/ruleFn'
import api from "../../api";
import apiDefault from "~/api/api";
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/regional-assistant/'
var allRuleObj = {}
import {
setConfigInfo
} from '~/store/index'
const app = getApp()
Page({
/**
* 页面的初始数据
* selectWeek 0代表的本周 1代表下一周 -1代表上一周
* timeBean 传递给组件的数据,数据的格式在一开始的工具类中明确
*/
data: {
IMG_URL,
imgShow: false,
isDisable: false,
hasDailyValue: false,
isUpload: false,
isTodayEdit: false,
// userInfo: {},
// 轻改区域日报模版code
qgReportCode: null,
title: '',
// 模版表单提交数据
tmlpFormData: {},
timeBean: {},
selectWeek: 0,
tabActive: '',
tabList: [],
dataAttrName: 'tmlpFormData',
/** 模版表单数据对象
* { 模版key: [ 模版下面的表单项数据对象 ] }
*/
tmlpObj: null,
// 往日可编辑的模版
tmlpEditList: [],
tmlpCode: '',
/** 模版表单数据对象验证规则对象
* { 模版key: [ 模版下面的表单项数据对象 ] }
*/
// 后端返回的模版初始数据
// tmlpInitData: resData.types
tmlpInitData: null,
// tmlpItemObj 模版数据单个的对象
tmlpItemObj: {},
isLoading: false,
// 适配不同“带教配置”模版字段,organizeTraining/organizeTraining_1/organizeTraining_2
trainTmlpSuffix: '',
imgObj: {
trainingPhotos: [],
trainingPhotos_1: [],
trainingPhotos_2: []
},
mutiOption: {
attendingStaff: {},
attendingStaff_1: {},
attendingStaff_2: {},
},
isChangeTab: false,
isConfirm: false,
tabChange: true,
staffCheckList: [],
staffCheckList_1: [],
staffCheckList_2: [],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if(options.refresh) {
this.setData({
qgReportCode: options?.templateCode || null,
title: options?.templateCode ? '轻改区域日报' : '延保区域日报'
})
this.initData(options)
}
wx.$router.getData((route) => {
this.setData({
qgReportCode: route?.params?.templateCode || null,
title: route?.params?.templateCode ? '轻改区域日报' : '延保区域日报'
})
this.initData(options)
})
},
async initData(options) {
// 获取配置服务数据
let baseConfigData = await setConfigInfo(app.globalData)
this.setData({
tmlpEditList: baseConfigData?.dailyTmlpEditList?.map(item => item.code)
})
// 初始化日期
this.setData({
reportDate: options.reportDate,
timeBean: util.getWeekDayList(this.data.selectWeek),
isChangeTab: true
});
this.resetTempData()
this.getRecordDetail()
this.setData({
flag: true,
});
},
dealOrganizeTraining() {
let { trainTmlpSuffix } = this.data
const params = {
target: {
id: 'organizeTraining' + trainTmlpSuffix
},
detail: {
attr: 'isTrainingOrganized' + trainTmlpSuffix
}
}
this.radioEvent(params)
},
radioEvent(e) {
let pAttr = e.target.id
let {
attr
} = e.detail
let { tmlpFormData, tmlpObj, trainTmlpSuffix, tmlpCode } = this.data
tmlpObj['organizeTraining' + trainTmlpSuffix]?.forEach(item => {
if (!item.name.includes('isTrainingOrganized')) {
item.isHide = tmlpFormData[attr] == '否' ? true : false
}
})
if (allRuleObj[pAttr] && pAttr == ('organizeTraining' + trainTmlpSuffix)) {
let keyList = Object.keys(allRuleObj[pAttr])
keyList.forEach(item => {
if (item != ('isTrainingOrganized' + trainTmlpSuffix) && allRuleObj[pAttr][item]) {
allRuleObj[pAttr][item][0].required = tmlpFormData[attr] == '否' ? false : true
}
})
}
const pAttrList = Object.keys(allRuleObj)
console.log(tmlpCode, 'pAttrList---')
if (['qinggai-temp-001', 'uuid-temp-001'].includes(tmlpCode)) {
pAttrList.forEach(pAttrItem => {
tmlpObj[pAttrItem].forEach(item => {
if (!item.name.includes('dayOffStatus')) {
item.required = tmlpFormData['dayOffStatus'] == '是' ? false : true
}
})
let keyList = Object.keys(allRuleObj[pAttrItem])
keyList.forEach(item => {
if (item != 'dayOffStatus' && allRuleObj[pAttrItem][item]) {
allRuleObj[pAttrItem][item][0].required = tmlpFormData['dayOffStatus'] == '是' ? false : true
}
})
})
}
console.log(tmlpObj, attr)
this.setData({
tmlpObj
})
},
jump() {
wx.$router.back();
},
navbarReady(e) {
let navBarHeight = e.detail.height;
this.setData({
navBarHeight,
});
},
onClickShow(e) {
const { name } = e.target.dataset
this.setData({ imgShow: true, imgName: name })
},
onClickHide() {
this.setData({ imgShow: false })
},
resetTempData() {
allRuleObj = {}
this.setData({
tmlpInitData: null,
tmlpFormData: {},
tmlpObj: null,
selectedStr: '',
selectTxt: ''
})
},
/** 查询用户指定日期的日报详情 */
getRecordDetail() {
let { timeBean, qgReportCode } = this.data
let params = {
date: timeBean.weekDayList[timeBean.selectDay].date
}
if(qgReportCode) {
params.templateCode = qgReportCode
}
wx.$util.showLoading()
api.getRecordDetail(params).then(res => {
if (res.data == null) {
this.resetTempData();
this.setData({
isChangeTab: false,
});
return true;
}
this.setData({
tmlpCode: res.data.templateCode,
tmlpInitData: res.data.types,
});
this.getDynamicForm();
this.setReportDate();
}).finally(() => {
wx.hideLoading()
})
},
/** 查询用户指定日期范围内填写日报的日期 */
getDateRecord() {
let { timeBean, isDisable, tmlpEditList, tmlpCode, qgReportCode } = this.data
console.log(tmlpEditList, 'tmlpEditList')
console.log(tmlpCode, 'tmlpCode')
// console.log(timeBean.weekDayList, 'timeBean.weekDayList--')
let params = {
sDate: timeBean.reportStartDate,
eDate: timeBean.reportEndDate
}
if(qgReportCode) {
params.templateCode = qgReportCode
}
this.setData({
hasDailyValue: false,
isTodayEdit: ['qinggai-temp-001', 'uuid-temp-001'].includes(tmlpCode)
})
wx.$util.showLoading()
api.getDateRecord(params).then(res => {
console.log(res, 'res-----')
let list = res.data || []
list.forEach(item => {
let currDate = new Date(item).format('yyyy-MM-dd')
let idx = timeBean.weekDayList.findIndex(k => k.date == currDate)
if (idx != -1) {
timeBean.weekDayList[idx].hasDailyValue = true
}
})
if (timeBean.weekDayList[timeBean.selectDay].date == new Date().format('yyyy-MM-dd')) {
//改----------------
this.setData({
isDisable: timeBean.weekDayList[timeBean.selectDay].hasDailyValue || false,
hasDailyValue: timeBean.weekDayList[timeBean.selectDay].hasDailyValue || false
})
} else if (tmlpEditList.includes(tmlpCode)) {
// 往期编辑
this.setData({
isDisable: timeBean.weekDayList[timeBean.selectDay].hasDailyValue || false
})
}
this.setData({
timeBean
})
}).finally(() => {
wx.hideLoading()
})
},
handleInput(e) {
let value = e.detail
let {
attr
} = e.target.dataset
let { trainTmlpSuffix } = this.data
this.setData({
['tmlpFormData.' + attr + trainTmlpSuffix]: value
})
},
// 图片上传
upLoad(event) {
let _this = this
const { file } = event.detail
const { attr, idx } = event.currentTarget.dataset
let { imgObj, trainTmlpSuffix } = this.data
let tempFiles = file?.url
let imgType = tempFiles.split('.')[1]
let type = imgType == 'unknown' ? 'jpg' : imgType
wx.getFileSystemManager().readFile({
filePath: tempFiles, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success(_res) {
wx.$util.showLoading('上传中...')
apiDefault
.uploadImg({
file: `${type}@${_res.data}`
})
.then(img => {
wx.$util.hideLoading()
let { code, data, message } = img
if (code == 0) {
// imgObj[attr].push({ url: data })
imgObj[attr + trainTmlpSuffix][0] = { url: data }
_this.setData({
['tmlpFormData.' + attr + trainTmlpSuffix]: data,
imgObj
})
} else {
wx.$util.showToast(message)
}
})
}
})
},
// 图片删除
handleDeleteImg(e) {
const { attr } = e.currentTarget.dataset
let { imgObj, trainTmlpSuffix } = this.data
const { index } = e.detail
imgObj[attr + trainTmlpSuffix].splice(index, 1)
this.setData({
imgObj
})
},
// 与会驻店选择
handleStaffPicker(e) {
let { pname, name } = e.currentTarget.dataset;
let { isDisable, trainTmlpSuffix } = this.data
pname = pname + trainTmlpSuffix
name = name + trainTmlpSuffix
if (isDisable) {
return true
}
let { tmlpObj, mutiOption } = this.data
const idx = tmlpObj?.[pname].findIndex(k => k.name == name)
mutiOption[name] = {
optionList: tmlpObj[pname][idx].optionList
}
this.setData({
mutiOption,
selectItemTitle: '与会驻店人员',
selectPName: pname,
selectItemName: name,
showSelectItemPopup: true,
});
},
// 与会驻店人员选择确定
changeStaff(e) {
let { selectItemName, tmlpFormData, trainTmlpSuffix } = this.data;
if (selectItemName) {
tmlpFormData[selectItemName] = "";
tmlpFormData[selectItemName + "Txt"] = "";
}
// 与会驻店人员的ids
tmlpFormData['staffIds' + trainTmlpSuffix] = "";
var list = [];
var ids = []
// console.log(trainTmlpSuffix, 'trainTmlpSuffix---')
// console.log( this.data['staffCheckList' + trainTmlpSuffix], 'trainTmlpSuffix---')
this.data['staffCheckList' + trainTmlpSuffix].forEach((item) => {
list.push(item.staffName);
ids.push(item.id)
});
if (selectItemName) {
tmlpFormData[selectItemName] = list.join(",");
tmlpFormData[selectItemName + 'Txt'] = list.join(',')
}
tmlpFormData['staffIds' + trainTmlpSuffix] = ids.join(",")
let selectedStr = list.slice(0, 2).join(';')
let selectTxt = (list.length > 2 ? ';等' + list.length + '人' : '')
this.setData(
{
showSelectItemPopup: false,
tmlpFormData,
selectedStr,
selectTxt
}
);
},
staffSearch(e) {
let { staffName } = e.detail
console.log(staffName, 'staffname')
this.getStaffList(staffName)
},
click(e) {
let { idx, item } = e.detail
let { mutiOption, selectPName,
selectItemName, trainTmlpSuffix } = this.data
let staffCheckList = this.data['staffCheckList' + trainTmlpSuffix]
const checkIdx = staffCheckList.findIndex(k => k.id == item.id)
checkIdx == -1 ? staffCheckList.push(item) : staffCheckList.splice(checkIdx, 1)
this.setData({
[`mutiOption.${selectItemName}.optionList[${idx}].active`]: !this.data.mutiOption[selectItemName].optionList[idx].active,
[`staffCheckList${trainTmlpSuffix}`]: staffCheckList
})
this.setData({
showSelectItemPopup: true,
mutiOption
// formData,
});
},
getDynamicForm() {
this.dealTab()
},
tabChange(e) {
let {
key
} = e.currentTarget.dataset
let trainTmlpSuffix = this.fitTraninTmlp(key)
this.setData({
tabActive: key,
tabChange: false,
trainTmlpSuffix: trainTmlpSuffix,
selectItemName: 'attendingStaff' + trainTmlpSuffix
}, () => {
this.setData({
tabChange: true
})
this.changeStaff()
this.dealOrganizeTraining()
})
},
dealTab() {
let { tmlpInitData } = this.data
let tabList = []
tmlpInitData?.forEach(item => {
tabList.push({
name: item.name,
key: item.key
})
})
this.setData({
tabList,
tabActive: tmlpInitData.length ? tmlpInitData[0].key : '',
trainTmlpSuffix: this.fitTraninTmlp(tmlpInitData.length ? tmlpInitData[0].key : '')
})
this.dealDynamicForm()
},
/**
* 适配“带教培训”模版
*/
fitTraninTmlp(tabName, matchStr = 'organizeTraining') {
let afterMatch = ''
let index = tabName.indexOf(matchStr);
if (index !== -1) {
// 获取匹配字符串后面的所有字符
afterMatch = tabName.substring(index + matchStr.length);
}
return afterMatch
},
/**
* 处理动态表单
*/
dealDynamicForm() {
// imgObj.trainingPhotos, selectedStr
this.setData({
tmlpObj: null
})
wx.$util.showLoading()
let { tmlpInitData, tabList, imgObj, selectedStr, selectTxt, timeBean } = this.data
// console.log(tabList, 'tabList--')
// tmlpObj
var obj = {}
var tempTmlpItemObj = {}
let tmlpFormData = {}
imgObj.trainingPhotos = []
imgObj.trainingPhotos_1 = []
imgObj.trainingPhotos_2 = []
selectedStr = ''
selectTxt = ''
// var ruleObj = {}
tabList.forEach(val => {
let list = []
allRuleObj[val.key] = {}
// 模版的表单项
tempTmlpItemObj[val.key] = {}
let trainSuffix = ''
// 带教培训后缀适配
if (val.key.includes('organizeTraining')) {
trainSuffix = this.fitTraninTmlp(val.key)
}
let formList = tmlpInitData.find(k => k.key == val.key)?.items || []
formList.forEach((k, kIdx) => {
// console.log(k.frontRule, 'k.frontRule--')
var frontConfig = JSON.parse(k.frontRule)
// console.log(frontConfig, 'frontConfig--')
if (k.key.includes('attendingStaff')) {
this.data['staffCheckList' + trainSuffix] = k.value ? k.value.split(',').map(item => { return { staffName: item } }) : []
}
if (k.key.includes('trainingPhotos') && k.value) {
imgObj['trainingPhotos' + trainSuffix] = [{ url: k.value }]
}
if (frontConfig.type == 'select') {
frontConfig.labelName = k.key + 'Txt'
}
if (frontConfig.type == 'slot') {
frontConfig.slotName = trainSuffix ? k.key.split(trainSuffix)[0] : k.key
}
tempTmlpItemObj[val.key][k.key] = {
placeholder: k.placeholder,
maxlength: frontConfig.maxlength || '140'
}
list.push({
label: k.name,
name: k.key,
placeholder: k.placeholder,
suffix: k.suffix,
type: frontConfig.type,
labelWidth: frontConfig.labelWidth,
maxlength: frontConfig.maxlength || '140',
isAgreeTrim: frontConfig.isAgreeTrim || false,
isLabelNoLine: frontConfig.isLabelNoLine,
inputAlign: frontConfig.inputAlign || 'right',
optionList: frontConfig.optionList || [],
optionId: frontConfig.optionId || [],
optionLabel: frontConfig.optionLabel || [],
noCellHeight: frontConfig.noCellHeight || false,
fieldType: frontConfig.fieldType || 'text',
rows: frontConfig.rows || '1',
slotName: frontConfig.slotName || k.key,
// select的选项合集
labelName: frontConfig.labelName,
inputLimit: frontConfig.inputLimit || {},
isOnlyPc: frontConfig.isOnlyPc || false
})
if (!frontConfig.isOnlyPc) {
tmlpFormData[k.key] = k.value
}
if (frontConfig.type == 'select') {
tmlpFormData[frontConfig.labelName] = k.value
}
if (frontConfig.rule) {
allRuleObj[val.key][k.key] = JSON.parse(JSON.stringify(frontConfig.rule))
for (let i = 0; i < allRuleObj[val.key][k.key].length; i++) {
let temp = allRuleObj[val.key][k.key]
if (temp[i]?.required) {
list[kIdx].required = true
}
if (temp[i]?.validator) {
if (tempRuleFnObj[val.key] && tempRuleFnObj[val.key][k.key] && tempRuleFnObj[val.key][k.key][temp[i]?.validator]) {
allRuleObj[val.key][k.key][i].validator = tempRuleFnObj[val.key][k.key][temp[i].validator]
// console.log(allRuleObj[val.key][k.key][i].validator, 'itemRuleObj[k.key][i].validator')
}
// temp[i]?.validator = temp[i]?.validator.replace(/\"/g, '')
}
}
}
})
list = list.filter(m => !m.isOnlyPc)
// console.log(allRuleObj[val.key], 'itemRuleObj---')
obj[val.key] = JSON.parse(JSON.stringify(list))
// ruleObj[val.key] = itemRuleObj
})
console.log(allRuleObj, 'allRuleObj')
// 是否组织培训默认值
if (timeBean.weekDayList[timeBean.selectDay].date == new Date().format('yyyy-MM-dd')) {
if (obj?.organizeTraining && !tmlpFormData.isTrainingOrganized) {
tmlpFormData.isTrainingOrganized = '是'
}
}
wx.hideLoading()
this.setData({
tmlpObj: obj,
tmlpFormData,
tmlpItemObj: tempTmlpItemObj,
imgObj,
selectedStr,
selectTxt,
isChangeTab: false,
staffCheckList: this.data.staffCheckList,
staffCheckList_1: this.data.staffCheckList_1,
staffCheckList_2: this.data.staffCheckList_2
}, () => {
this.getStaffList()
// const staffIdx = obj?.organizeTraining?.findIndex(k => k.name == 'attendingStaff') || -1
// if (staffIdx != -1) {
// this.getStaffList()
// }
let keys = Object.keys(obj)
keys.forEach(item => {
let trainSuffix = this.fitTraninTmlp(item)
let staffIdx = obj?.['organizeTraining' + trainSuffix]?.findIndex(k => k.name.includes('attendingStaff')) || -1
if (staffIdx != -1) {
this.getStaffList('', trainSuffix)
}
})
this.changeStaff()
this.dealOrganizeTraining()
})
},
getStaffList(staffName, suffix) {
const { qgReportCode } = this.data
if(qgReportCode == 'qinggai-temp-001') {
return true
}
var trainSuffix = suffix || this.data.trainTmlpSuffix
let that = this
let params = {
staffName: staffName,
pageNum: 1,
pageSize: 99999
}
api.getStaffList(params).then(res => {
// console.log(res, 'res-staff----')
let { tmlpObj, mutiOption } = that.data
const staffIdx = tmlpObj?.['organizeTraining' + trainSuffix]?.findIndex(k => k.name.includes('attendingStaff')) || -1
if (staffIdx != -1) {
if (this.data['staffCheckList' + trainSuffix].length) {
this.data['staffCheckList' + trainSuffix].forEach(item => {
let findIdx = res.data.list.findIndex(i => i.id == item.id)
if (findIdx != -1) {
res.data.list[findIdx].active = true
}
})
}
tmlpObj['organizeTraining' + trainSuffix][staffIdx].optionId = 'id'
tmlpObj['organizeTraining' + trainSuffix][staffIdx].optionLabel = 'staffName'
tmlpObj['organizeTraining' + trainSuffix][staffIdx].optionList = res.data.list
mutiOption['attendingStaff' + trainSuffix] = {
optionList: tmlpObj['organizeTraining' + trainSuffix][staffIdx].optionList
}
this.setData({
mutiOption,
tmlpObj
})
}
}).finally(() => {
const staffPopup = this.selectComponent("#staffPopup");
wx.$util.hideLoading()
staffPopup.setData({
isLoad: false
})
})
},
getPageData() {
let thisPage = wx.$router.getPageInstance()
return thisPage?.data[this.data.dataAttrName]
},
dealParams() {
let { tmlpObj } = this.data
let list = Object.keys(tmlpObj)
let params = JSON.parse(JSON.stringify(this.getPageData()))
const changeValueAttrList = ['select']
list.forEach(item => {
tmlpObj[item].forEach(k => {
if (changeValueAttrList.includes(k.type)) {
params[k.name] = params[k.labelName]
delete params[k.labelName]
}
})
})
let trainList = [{
tmlpName: 'organizeTraining',
isTrain: 'isTrainingOrganized'
}, {
tmlpName: 'organizeTraining_1',
isTrain: 'isTrainingOrganized_1'
}, {
tmlpName: 'organizeTraining_2',
isTrain: 'isTrainingOrganized_2'
}]
let staffIds = []
trainList.forEach(k => {
let trainSuffix = this.fitTraninTmlp(k.tmlpName)
// 没有组织培训,需删掉的属性
let noOrganAttrList = tmlpObj[k.tmlpName]?.map(item => {
return item.name != k.isTrain ? item.name : ''
})
if (params[k.isTrain] == '否') {
noOrganAttrList.forEach(item => {
delete params[item]
})
delete params['staffIds' + trainSuffix]
delete params['attendingStaff' + trainSuffix + 'Txt']
} else {
staffIds = staffIds.concat(params['staffIds' + trainSuffix]?.split(',') || [])
}
})
params.staffIds = staffIds.join(',')
if (params.attendingStaff) {
params.attendingStaff = params.attendingStaffTxt
delete params.attendingStaffTxt
}
return JSON.stringify(params)
},
secondConfirm(params) {
let that = this
wx.showModal({
title: "确认提示",
content: "日报提交后将触发群消息推送,是否确认提交?",
// showCancel: false,
cancelText: '取消', // '取消
cancelColor: "#292D33",
confirmText: "确定",
confirmColor: "#2C66F7",
complete(res) {
if (res.confirm) {
api.saveTempReport(params).then(res => {
if (res.code == '0' || res.code == '-3') {
that.getRecordDetail()
}
wx.$util.showToast(res.code == '0' ? '提交成功' : res.message)
}).finally(() => {
that.setData({
isConfirm: false
})
})
} else {
that.setData({
isConfirm: false
})
}
}
});
},
validLink(formData, attr) {
if (!formData[attr]) {
return false
}
//https://meeting.tencent.com/crm/;无录屏
if (/https:\/\/meeting.tencent.com\/crm\//.test(formData[attr]) || formData[attr].includes('无录屏')) {
return false
} else {
wx.showModal({
title: '温馨提示',
content: '请参考示例,填写正确的录屏链接,如没有录屏链接则填写“无录屏”。',
confirmText: '好的',
confirmColor: '#2C66F7',
showCancel: false,
success(res) {
}
})
return true
}
},
changeVal(attr, val) {
this.setData({
[attr]: val
})
},
handleEdit() {
this.changeVal('isDisable', false)
},
handleCancel() {
const { qgReportCode } = this.data
this.changeVal('isDisable', true)
this.onLoad({ refresh: true, templateCode: qgReportCode })
},
handleConfirm() {
let { isConfirm, qgReportCode } = this.data
if (isConfirm) {
return true
}
this.setData({
isConfirm: true
})
let formData = this.getPageData()
const attrList = Object.keys(allRuleObj)
console.log(attrList, 'attrList----')
for (let i = 0; i < attrList.length; i++) {
let formRule = allRuleObj[attrList[i]]
console.log(formRule, 'formRule----')
let validObj = fn.checkRequired(formData, formRule)
if (validObj) {
this.setData({
isConfirm: false
})
wx.$util.showToast(validObj.message)
return
}
}
let linkList = ['tencentMeetingRecordingLink', 'tencentMeetingRecordingLink_1', 'tencentMeetingRecordingLink_2']
for (let i = 0; i < linkList.length; i++) {
if (this.validLink(formData, linkList[i])) {
this.setData({
isConfirm: false
})
return
}
}
let params = {
formJson: this.dealParams()
}
if(qgReportCode) {
params.templateCode = qgReportCode
}
console.log(JSON.parse(params.formJson), 'params-----')
// 删----要给新字段加校验++++
// this.setData({
// isConfirm: false
// })
// wx.$util.showToast('提交成功')
this.secondConfirm(params)
},
/**
* 点击了上一周,选择周数字减一,然后直接调用工具类中一个方法获取到数据
*/
lastWeek: function (e) {
let { isChangeTab } = this.data
if (isChangeTab) {
return true
}
var selectWeek = --this.data.selectWeek;
var timeBean = this.data.timeBean;
timeBean = util.getWeekDayList(selectWeek);
if (selectWeek != 0) {
timeBean.selectDay = 0;
}
this.setData({
timeBean,
selectWeek,
isChangeTab: true
});
this.resetTempData()
// this.setReportDate();
this.getRecordDetail();
// this.getStaffReport();
// this.getStaffDailyReportDetailWeeklyList();
},
/**
* 点击了下一周,选择周数字加一,然后直接调用工具类中一个方法获取到数据
*/
nextWeek: function (e) {
let { isChangeTab } = this.data
if (isChangeTab) {
return true
}
var selectWeek = ++this.data.selectWeek;
var timeBean = this.data.timeBean;
// console.log(timeBean.weekDayList[6].date, 'timeBean.weekDayList[6].date');
// timeBean = util.getWeekDayList(selectWeek, timeBean.weekDayList[6].date)
console.log(selectWeek);
timeBean = util.getWeekDayList(selectWeek);
// console.log(timeBean, "nextWeek");
if (selectWeek != 0) {
timeBean.selectDay = 0;
}
this.setData({
timeBean,
selectWeek,
isChangeTab: true
});
this.resetTempData()
// this.setReportDate();
this.getRecordDetail();
// this.getStaffReport();
// this.getStaffDailyReportDetailWeeklyList();
},
/**
* 选中了某一日,改变selectDay为选中日
*/
dayClick: function (e) {
let { isChangeTab } = this.data
if (isChangeTab) {
return true
}
this.setData({
["timeBean.selectDay"]: e.detail,
isChangeTab: true,
});
this.resetTempData()
// this.setReportDate();
this.getRecordDetail();
// this.getStaffReport();
},
// 设置报告日期
setReportDate() {
let { timeBean, tmlpFormData, templateCode } = this.data;
console.log(timeBean, "nextWeek");
let date = timeBean.weekDayList[timeBean.selectDay].date;
var time = new Date(date);
var y = time.getFullYear();
var m = time.getMonth() + 1;
console.log(timeBean.weekDayList[timeBean.selectDay].date, 'timeBean.weekDayList[timeBean.selectDay].date')
console.log(new Date().format('yyyy-MM-dd'))
this.setData({
["timeBean.yearMonth"]: y + "-" + m,
["tmlpFormData.reportDate"]: date,
isEditReport: false,
isDisable: timeBean.weekDayList[timeBean.selectDay].date != new Date().format('yyyy-MM-dd')
});
this.getDateRecord()
},
})