index.js
30.6 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
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
// tabIndex/pages/index/index.js
import mixins from './index_mixins'
import api from '../../api.js'
import NP from 'number-precision'
import {
getMerchantBrand,
getListSelectAccount
} from '~/api/api'
import {
getYQInfo,
get4SStoreList,
getBusinessSchoolScene
} from '~/store/index'
import {
checkDailyReport,
checkStudyTask,
checkOrderLockGate
} from '~/store/ModalToQueueControl'
import { navigateToRequiredDailyReport } from '~/utils/staffDailyReportNavigation.js'
import {
loadAbnormalFlowTipState,
dismissAbnormalFlowTip,
openAbnormalFlowTransactionPopup
} from '../../services/abnormalFlowTipService.js'
import { openOrderPromptWithRestrictState } from '../../services/newOrderAbnormalFlowRestrict.service.js'
import { confirmOrderPrompt } from '../../services/orderPromptConfirm.service.js'
import { ABNORMAL_FLOW_LOCK_BYPASS } from '~/utils/abnormalFlowLock.helpers.js'
import {
buildTabIndexMenusAsync,
createMenuJumpHandler,
getMenuFingerprint,
applyMenuBadges,
onWorkReportPopupSelect
} from '../../menu/index.js'
import { createModalQueueService } from '../../services/modalQueueService.js'
import {
sliceTodoPreview,
buildStaffRemindParams,
buildShutDownTaskParams
} from '../../services/todoService.js'
import { runDailyChecks } from '../../services/dailyCheckService.js'
import { invalidateMenuAndApiCaches as clearSharedMenuApiCaches } from '~/utils/menuApiCache.js'
import {
buildHomeMenuFingerprint,
createMenuRebuildCoordinator
} from '../../services/menuSyncHelpers.js'
import {
computeTableWidth,
mergeTablePage,
capDisplayOrderMoney
} from '../../services/dashboardService.js'
const IMG_URL =
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
const app = getApp()
let time = null
import commonApi from '~/api/api'
Page({
/**
* 页面的初始数据
*/
data: {
IMG_URL,
...mixins.data,
navStyle: 'background-color: rgba(0,0,0,0);box-shadow:none;',
navBarHeight: 0,
delayShow: false,
showRemark: false,
methodUpdateInfo: {
value: ''
},
isStaff: false,
showOrderpop: false,
waitInputCount: 0,
shopSideSelectPopup: false,
flag: true,
dateObj: {
beginDateStr: '',
today: ''
},
showPicker: false,
// showPicker: true
storeRange: [],
changeSelectIndex: 0, // 个人产值过滤筛选
taskInfo: {},
background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
todoList: [],
stodoList: [],
missingRecordTodoList: [],
todos: {
1: '日报填写提醒',
2: '今日尚未开单',
3: '工牌处于离线状态',
4: '客户跟进提醒',
5: '培训提醒',
6: '资料查看提醒',
7: '上班打卡',
8: '下班打卡'
},
selectType: 1,
styleHight: 'auto',
ispopUp: true,
isPad: false,
isWait: false, // 今日待办等:非 canSelectMultiStore 且非技师(loginRole 7)
sceneObj: {},
orderPromptDjQrOnlyMode: false,
showReportPopup: false,
abnormalFlowTips: { show: false, count: 0, tipsText: '' },
reportTemplateList: [],
currentReportItem: null,
maxDate: '',
},
onReportPopupCancel() {
this.setData({
showReportPopup: false
})
},
handleNavigateServiceCenter(e) {
wx.$router.go("tabWorkOrder.serviceNoticeList");
},
onReportPopupSelect(e) {
onWorkReportPopupSelect(this, e.detail)
},
// 查询员工待办事项列表
getStaffRemindList() {
const userInfo = wx.$util.getUserInfo()
commonApi.getStaffRemindList(buildStaffRemindParams(userInfo)).then(result => {
this.setData(sliceTodoPreview(result.data))
})
},
closeRemind(e) {
let userInfo = wx.$util.getUserInfo(),
taskId = e.currentTarget.dataset.id
commonApi.shutDownTaskApi(buildShutDownTaskParams(userInfo, taskId)).then(result => {
if (result.data) {
this.getStaffRemindList()
wx.showToast({
title: '关闭成功',
icon: 'success'
})
}
})
},
async goto(e) {
let url,
id = e.currentTarget.dataset.id
switch (id) {
case 1:
//日报填写提醒
let currentDate = new Date()
// 获取上一天的日期
let previousDate = new Date(currentDate)
previousDate.setDate(currentDate.getDate() - 1)
// toISOString 方法会丢失时区 导致与北京时间差八小时
let hour = previousDate.getHours() + 8
previousDate.setHours(hour)
// 格式化日期为"yyyy-mm-dd"
let formattedDate = previousDate.toISOString().split('T')[0]
navigateToRequiredDailyReport({ reportDate: formattedDate })
break
case 2:
// 校验是否填写昨日日报
let staffCheck = await checkDailyReport()
if (staffCheck) return false
// 校验学习中心开单限制
let staffStudyTask = await checkStudyTask()
if (staffStudyTask) return false
// 校验异常订单
let lockCheck = await checkOrderLockGate({}, 'pages.index')
if (lockCheck) return false
//开单提醒
if (await wx.$globalDataFunction.inspectionOfProhibitionBill()) return
await openOrderPromptWithRestrictState(this, { sceneObj: {} })
// wx.$router.go('tabWorkOrder.createOrder')
break
case 4:
//预约客户提醒
wx.$router.go('tabDate.apprManage')
break
}
},
packupList() {
if (this.data.ispopUp) {
this.setData({
stodoList: this.data.todoList.slice(0, 2),
ispopUp: false
})
} else {
this.setData({
styleHight: 'auto',
ispopUp: true
})
}
},
changeSwiper(e) {
this.setData({
changeSelectIndex: e.detail.current
})
},
tipsEvent() {
this.setData({
showOrderpop: true
})
},
closeSwitchPopup() {
this.setData({
showOrderpop: false
})
},
async navigator(e) {
// 校验是否填写昨日日报
let staffCheck = await checkDailyReport()
if (staffCheck) return false
// 校验学习中心开单限制
let staffStudyTask = await checkStudyTask()
if (staffStudyTask) return false
let { selectOutTradeNoArr } = e.detail
let { paymentMethod } = this.data
const lockCheck = await checkOrderLockGate({
orderCreateType: 'additionRecordOrder',
paymentMethod,
bypassReason: ABNORMAL_FLOW_LOCK_BYPASS.ADDITION_RECORD
}, 'pages.index')
if (lockCheck) return false
this.closeSwitchPopup()
wx.$storage.set('outTradeNo', selectOutTradeNoArr)
if (selectOutTradeNoArr) {
let params = {
selectOutTradeNoArr,
orderCreateType: 'additionRecordOrder',
paymentMethod
}
wx.$router.go('tabWorkOrder.createOrder', params)
}
},
remarkConfirm(e) {
let { methodUpdateInfo } = this.data
let { detail: filmTimes } = e
methodUpdateInfo.filmTimes = filmTimes
api
.updateCouponDayReport(methodUpdateInfo)
.then(result => {
if (result.code == 0) {
methodUpdateInfo.value = ''
this.setData({
methodUpdateInfo
})
this.getMerchantCouponList()
} else {
wx.showToast({
title: '修改失败',
icon: 'error'
})
}
})
.catch(err => {
console.log(err)
})
},
// 切换过滤筛选个人产值
changeStaticData(e) {
let { index } = e.currentTarget.dataset
this.setData({
changeSelectIndex: index
})
},
changeTableData(e) {
let { startDate, maxDate, isYqdSuper } = this.data
let { merchantId, filmTimes, merchantName } = e.currentTarget.dataset.item
// 不是管理员不开启这个权限
if (!isYqdSuper) return
if (startDate != maxDate) {
return wx.showToast({
title: '只能修改当天数据',
icon: 'none'
})
}
let methodUpdateInfo = {
merchantId,
merchantName,
filmTimes: filmTimes,
startDate: maxDate,
endDate: maxDate
}
this.setData({
showRemark: true,
methodUpdateInfo
})
},
navbarReady(e) {
let navBarHeight = e.detail.height
this.setData({
navBarHeight
})
},
back() {
wx.$router.go('pages.sceneIndex')
console.log('🚀')
},
showMenuPopup() {
this.setData({
shopSideSelectPopup: true
})
},
tapPicker() {
this.setData({
moveArrow: !this.data.moveArrow
})
},
// 获取4s店数据
get4SStoreList() {
let userInfo = wx.$util.getUserInfo()
const loginRole = userInfo.subLoginUser?.loginRole
// if (userInfo?.isSuper) return;
const effectiveUser = { ...userInfo, loginRole: loginRole ?? userInfo?.loginRole }
let params = {
merchantId:
wx.$hasPermission?.canSelectMultiStore?.(effectiveUser)
? ''
: userInfo?.merchantId,
staffUUID:
wx.$hasPermission?.canSelectMultiStore?.(effectiveUser)
? ''
: userInfo?.uuid,
scene: 1
}
get4SStoreList(
params,
wx.$hasPermission?.canSelectMultiStore?.(userInfo)
).then(result => {
if (!wx.$hasPermission?.isSuper?.(userInfo)) {
if (!result?.length) {
// 缓存记录登录信息 但关联未4s
userInfo.shopMerchantId = null
userInfo.shopMerchantName = null
userInfo.sceneType = null
// debugger
wx.$util.setUserInfo(userInfo)
return wx.$router.reLaunch('pages.accountItems')
}
}
if (wx.$hasPermission?.canSelectMultiStore?.(effectiveUser)) {
// 超管或区域督导
if (result[0]?.merchantName !== '全部' && result[0]?.merchantId) {
result.unshift({
merchantName: '全部'
})
}
}
this.setData({
storeRange: result || []
})
})
},
// 超管获取园区店数据
getStoreList(e) {
let { value } = e.detail
getYQInfo(this.data.userInfo)
.then(result => {
let { merchantRange } = result
if (value) {
merchantRange = merchantRange.filter(item =>
item.merchantName.includes(value)
)
}
this.setData({
merchantRange
})
})
.catch(err => { })
},
changePicker(e, value) {
let { merchantId } = e
// 修改对应下标显示
app.globalData.yqdInfo.subIndex = value
let obj = {}
if (merchantId) obj.merchantId = merchantId
api.swtichSubLoginInfo(obj).then(res => {
console.log(res)
let { code, data, message } = res
if (code == 0) {
// debugger
let userInfo = wx.$util.getUserInfo()
userInfo.subLoginUser = data.subLoginUser
wx.$util.setUserInfo(userInfo)
this.initData(data, { storeSwitched: true })
} else {
this.showToast(message)
}
})
this.tapPicker()
},
navTabPage(e) {
let { item, type } = e.currentTarget.dataset
if ('activeIndex' in item) {
wx.$util.refreshPageData()
item.url = type ? item.waiturl : item.url
item.activeIndex = type ? item.activeWIndex : item.activeIndex
item.url &&
wx.$router.go(item.url, {
activeIndex: item.activeIndex
})
} else {
item.url && wx.$router.go(item.url)
}
},
jumpDebounce(e) {
const debouncedJump = wx.$util.debounce(
event => this.jump(event),
1000,
true
)
debouncedJump(e) // 调用防抖后的函数
},
jumpThrottle(e) {
// 创建节流函数,1500ms 内只能触发一次
if (!this.throttledJump) {
this.throttledJump = wx.$util.throttle(event => this.jump(event), 1500)
}
this.throttledJump(e) // 调用节流后的函数
},
/** 菜单 icon 点击:委托 tabIndex/menu/jumpHandlers 按 action.type 跳转 */
async jump(e) {
if (!this._menuJump) {
this._menuJump = createMenuJumpHandler(this)
}
return this._menuJump(e)
},
async promptHandleConfirm(e) {
const { sceneObj, orderPromptDjQrOnlyMode } = this.data
await confirmOrderPrompt(
e.detail,
{
onNavigateCreate: paymentMethod => {
const params = { paymentMethod }
if (Object.keys(sceneObj || {})?.length) {
params.scene = sceneObj
}
wx.$router.go('tabWorkOrder.createOrder', params)
},
onOpenRecordingPopup: () => {
this.tipsEvent()
}
},
orderPromptDjQrOnlyMode
)
const paymentMethod =
e.detail.payFlag != 2 ? 1 : e.detail.payType
this.setData({ paymentMethod })
},
promptCancel() {
this.setData({
showPromptDialog: false
})
},
/** 关闭异常流水吸底提醒(当前登录周期) */
onAbnormalFlowTipClose() {
dismissAbnormalFlowTip(this)
},
/** 异常流水吸底「去处理」:打开选流水弹窗 */
onAbnormalFlowTipAction() {
openAbnormalFlowTransactionPopup(this)
},
// 确定是否要显示
showSelectType({ scene = '', item = {} }) {
wx.$modal(
this,
{
show: true,
title: '请选择录单入口',
tabTitleShow: false,
success: async res => {
// 跳转新增订单页面 并带特定参数
let { selectType } = this.data
if (selectType == 1) {
await openOrderPromptWithRestrictState(this, { sceneObj: scene })
} else {
wx.$router.go('tabWorkOrder.defeatOrder', {
scene,
...item
})
}
},
error: () => { }
},
'#modal2'
)
},
selectType(e) {
let { type } = e.currentTarget.dataset
console.log(e, e.currentTarget.dataset, type)
this.setData({
selectType: type
})
},
changeDate(e) {
let { name } = e.currentTarget.dataset
let data = new Date(),
value = name == 'today' ? 0 : 1,
startDate,
endDate
// 选择 今日
if (!value) {
startDate = data.format('yyyy-MM-dd')
endDate = data.format('yyyy-MM-dd')
} else {
// 选择 本月
const year = data.getFullYear()
const month = data.getMonth()
startDate = new Date(year, month, 1).format('yyyy-MM-dd')
endDate = new Date(year, month + 1, 0).format('yyyy-MM-dd')
}
let { tableBtn } = this.data
this.setData({
startDate,
endDate,
['tableBtn[1].text']: '本月'
})
this.setTab(tableBtn, value)
this.restPageNum()
},
// 切换日历
tapCalendar() {
console.log(this.data.whiteArrow)
this.setData({
whiteArrow: !this.data.whiteArrow
})
},
monthSelect(e) {
let { date } = e.detail
let { label, date: selectDate } = date
this.setData({
['dateObj.label']: label + '份',
['dateObj.dataMonth']: selectDate
})
let { merchantRange } = this.data
this.getOutputValue({
merchantRange
})
},
rangeSelect(e) {
let { tableBtn } = this.data
let {
date: { start, end }
} = e.detail
this.setData({
startDate: start,
endDate: end
})
let startStr = start.replace(/-/g, '.')
let endStr = end.replace(/-/g, '.')
let str = `${startStr.substring(2, startStr.length)}-${endStr.substring(
2,
endStr.length
)}`
tableBtn[1].text = str
this.setTab(tableBtn, 1)
this.restPageNum()
},
setTime() {
let _this = this
time = setTimeout(() => {
// 2025-8月版本,隐藏补录入口
// _this.getWaitOrder()
}, 10 * 1000)
},
// 10s轮询一次待补录
getWaitOrder() {
let { isStaff } = this.data
isStaff &&
api
.waitinputorder()
.then(result => {
let { code, data } = result
this.setTime()
if (code == 0) {
this.setData({
waitInputCount: data.waitInputCount
})
}
})
.catch(err => { })
},
setTab(tableBtn, index) {
console.log(index)
tableBtn.map(i => (i.active = false))
tableBtn[index].active = true
this.setData({
tableBtn
})
},
changeTableSort(e) {
let { index } = e.currentTarget.dataset
console.log(index)
let { tableSort, tableObj } = this.data
if (tableSort == index) {
tableObj[index].sort = !tableObj[index].sort
} else {
tableObj[index].sort = true
}
this.setData({
tableSort: index,
tableObj
})
this.sortTable(tableObj)
},
restPageNum() {
this.setData({
pageNum: 1
})
this.getMerchantCouponList()
},
scrollonReachBottom() {
console.log('scrollonReachBottom')
let { pages, pageNum } = this.data
// 判断当前页是否是末页
if (pages == pageNum) return wx.$util.showToast('列表已到底')
this.setData({
pageNum: pageNum + 1
})
this.getMerchantCouponList()
},
sortTable(tableObj) {
let { tableSort, table } = this.data
let { key, sort } = tableObj[tableSort]
const objectArraySort = keyName => {
return (objectN, objectM) => {
const valueN = objectN[keyName]
const valueM = objectM[keyName]
if (valueN > valueM) return sort ? 1 : -1
else if (valueN < valueM) return sort ? -1 : 1
else return 0
}
}
table.sort(objectArraySort(key, sort))
this.setData({
table
})
},
getMerchantCouponList() {
let userInfo = wx.$util.getUserInfo()
if (wx.$hasPermission?.isTechnician?.(userInfo)) return
let {
orderByTypeEnum,
tableSort,
tableObj,
startDate,
endDate,
totalTableSum,
tableWidth,
table,
pageNum
} = this.data
let target = tableObj[tableSort].sort
let orderByType = orderByTypeEnum[target][tableSort]
api
.getMerchantCouponList({
orderByType,
startDate,
endDate,
pageSize: 999999,
pageNum
})
.then(res => {
let { code, message, data } = res
// let table = [];
if (code == 0) {
table = mergeTablePage(
table,
data?.page?.list || [],
pageNum
)
totalTableSum.forEach((element, index) => {
element.total = data[element.name] || 0
})
tableWidth = computeTableWidth(totalTableSum, tableObj)
this.setData({
tableFlag: true,
table,
totalTableSum,
tableWidth,
tableObj,
// 服务端没返回分页信息时不能置 undefined:setData 会告警,且 pages == pageNum 判断会失真
pages: data?.page?.pages || 0
})
} else {
this.showToast(message)
}
})
},
checkShowOrderPop(options) {
let userInfo = wx.$util.getStorageSync('dj_boutique_user_info')
if (userInfo?.subLoginUser?.merchantId == options.merchantId) {
if (options.merchantId) {
this.setData({
showOrderpop: true
})
}
}
},
getOutputValue(yqdInfo) {
let { dateObj, userInfo } = this.data
if (wx.$hasPermission?.isTechnician?.(userInfo)) return
let { subIndex, merchantRange } = yqdInfo
// yqMerchantId 不是全部就必要要带过去
// 1-超管 2-商户管理员 3-区域运营 4-驻店人员
const yqMerchantId = merchantRange[subIndex]?.merchantId || ''
const merchantId = wx.$hasPermission?.isSuper?.(userInfo) ? '' : userInfo?.shopMerchantId
const loginRole = userInfo?.loginRole
this.setData({
loginRole
})
if (!loginRole) return false //没有不用展示就是没有
let params = {
dataMonth: dateObj.dataMonth,
yqMerchantId,
merchantId
}
api
.goodsOrderOutputValueBelong(params)
.then(result => {
let { code, data } = result
if (code == 0) {
// 目标值为 0 时 NP.divide(0, 0) 会得到 NaN,页面上就会显示 "NaN%";这里统一按 0 处理
const calcRate = (value, target) => {
if (!target) return 0
return NP.round(NP.times(NP.divide(value || 0, target), 100), 2)
}
let rateValue = calcRate(data?.totalOutputValue, data?.totalTargetOutputValue)
console.log(rateValue, 'rateValue')
if (data.areaSupervisionList && data.areaSupervisionList.length) {
data.areaSupervisionList.forEach(item => {
let rateValue = calcRate(item?.outputValue, item?.targetOutputValue)
item.rateValue = rateValue
// 百分比
item.rateValuePercent = rateValue + '%'
})
}
if (data.outoutValueList && data.outoutValueList.length) {
data.outoutValueList.forEach(item => {
let rateValue = calcRate(item?.outputValue, item?.targetOutputValue)
item.rateValue = rateValue
item.rateValuePercent = rateValue + '%'
})
}
this.setData({
outputValueObj: {
...data,
rateValue,
rateValuePercent: rateValue ? rateValue + '%' : '0%'
}
})
}
})
.catch(err => { })
},
getUserStat(userInfo) {
api
.userStat({
// merchantId: userInfo?.isSuper ? undefined : userInfo?.shopMerchantId,
merchantId: userInfo?.shopMerchantId || undefined
})
.then(result => {
let { code, data } = result
if (code == 0) {
this.data.changeBtnData.forEach(changeData => {
data[changeData.valueObj].totalOrderMoney =
capDisplayOrderMoney(
data[changeData.valueObj].totalOrderMoney
)
data[changeData.valueFn].totalOrderMoney =
capDisplayOrderMoney(
data[changeData.valueFn].totalOrderMoney
)
})
this.setData({
userStat: data
})
}
})
.catch(err => { })
},
totalListSet() {
let { userInfo } = this.data
if (
userInfo.subLoginUser?.loginRole == 3 ||
userInfo.subLoginUser?.loginRole == 5 ||
wx.$hasPermission?.isSuper?.(userInfo) ||
wx.$hasPermission?.canViewMentorship?.(userInfo)
) {
this.setData({
totalList: [
{
name: '转化订单',
itemName: 'totalUpgrade',
index: 4,
icon: 'icon_17'
},
{
name: '战败订单',
itemName: 'totalNotUpgrade',
index: 5,
icon: 'icon_16'
},
{
name: '客单价',
itemName: 'customerUnitPrice',
unit: '¥',
index: 6,
icon: 'icon_7'
}
]
})
}
},
/** 统计技师施工单量 */
getTechnicianItemsCount() {
let { userInfo } = this.data
api
.countTechnicianItems({
merchantId: userInfo?.shopMerchantId || undefined
})
.then(result => {
console.log(result, '统计技师施工单量')
let { code, data } = result
if (code == 0) {
this.setData({
technicianItemsCount: data
})
}
})
},
initTime() {
let data = new Date()
// 选择 本月
const year = data.getFullYear()
const month = data.getMonth()
const dataMonth = new Date(year, month + 1, 0).format('yyyy-MM')
this.setData({
dateObj: {
dataMonth,
pointUnit: 1, // 1日,2月,默认日
type: 'month',
label: month + 1 + '月份',
today: data.format('yyyy-MM-dd')
}
})
},
async initData(userInfo, options = {}) {
const { storeSwitched = false } = options
userInfo = userInfo ? userInfo : wx.$util.getUserInfo()
const merchantId =
userInfo?.shopMerchantId ||
userInfo?.default4SStoreInfo?.merchantId ||
''
const prevMerchantId = this._abnormalFlowTipMerchantId
if (storeSwitched) {
this.invalidateMenuCache()
}
getYQInfo(userInfo).then(result => {
wx.$util.hideLoading()
this.totalListSet()
const isTech = wx.$hasPermission?.isTechnician?.(userInfo)
if (!isTech) {
this.getMerchantCouponList()
this.initTime()
this.getUserStat(userInfo)
this.getOutputValue(result)
}
if (this.data.isWait) this.getStaffRemindList()
// 是技师请求统计接口
// console.log('是技师请求统计接口')
if (wx.$hasPermission?.canSelectMultiStoreWithTechnician?.(userInfo))
this.getTechnicianItemsCount()
this.setData({
...result
})
})
if (storeSwitched) {
const isWait =
!wx.$hasPermission?.canSelectMultiStore?.(userInfo) &&
!wx.$hasPermission?.isTechnician?.(userInfo)
await this.syncHomeMenus({
force: true,
includeCustomerClue: isWait
})
}
// 产品需求:强制填写(04-17版本)
this.checkDailyRecport()
if (
merchantId &&
prevMerchantId !== undefined &&
String(merchantId) !== String(prevMerchantId)
) {
loadAbnormalFlowTipState(this)
}
if (merchantId) {
this._abnormalFlowTipMerchantId = merchantId
}
},
async checkDailyRecport() {
return runDailyChecks(this, { isStaff: app.globalData.isStaff })
},
addModalToQueue(
title,
content,
confirmText,
showCancel,
priority,
eventCallback
) {
this._modalQueue?.add(
title,
content,
confirmText,
showCancel,
priority,
eventCallback
)
},
showNextModal() {
this._modalQueue?.showNext()
},
/**获取园区配置(客户线索入口由 menu provider 控制) */
async getYqStoreConfig() {
const userInfo = wx.$util.getUserInfo()
if (wx.$hasPermission?.isTechnician?.(userInfo)) return
await this.syncHomeMenus({ includeCustomerClue: true })
},
checkIsPadOrNot() {
let _this = this
wx.getRendererUserAgent({
success(res) {
let isPad = /iPad|Android.*Tablet|Kindle|Silk/i.test(res.userAgent)
_this.setData({
isPad
})
}
})
},
/** 驻店员工 onLoad:拉取导师标记(菜单由 onShow customerOnReady 统一构建) */
getIsMentor() {
return new Promise(resolve => {
let userInfo = wx.$util.getUserInfo()
if (wx.$hasPermission?.canSelectMultiStore?.(userInfo))
return
commonApi
.getStaffMentorFlag({
staffPhone: userInfo?.phone
})
.then(res => {
let { code, data, message } = res
if (code == 0) {
const nextMentor = !!data
if (nextMentor === this.data.mentorFlag) {
return
}
this.setData({ mentorFlag: nextMentor }, () => {
this.invalidateMenuFingerprint()
this.syncHomeMenus({
includeCustomerClue: this.data.isWait
})
})
} else {
wx.$util.showToast(message)
}
})
resolve()
})
},
/**
* 菜单构建完成后,按 id 拉取角标(待审批、招聘管理、客户线索)
* @param {Object} userInfo
* @param {Array} [menu]
*/
_updateMenuBadges(userInfo, menu = this.data.menu) {
applyMenuBadges(this, userInfo, menu)
},
/**
* 重建首页菜单:调用 tabIndex/menu 管道并单次 setData
* @param {Object} [options]
* @param {boolean} [options.includeCustomerClue] - 为 true 时走客户线索 provider(园区员工 onShow)
*/
async rebuildMenus(options = {}) {
const { includeCustomerClue = false } = options
const userInfo = wx.$util.getUserInfo()
if (!userInfo) return
const result = await buildTabIndexMenusAsync({
userInfo,
isStaff: app.globalData.isStaff,
mentorFlag: this.data.mentorFlag,
deps: {
includeCustomerClue,
tabIndexApi: api,
commonApi,
getBusinessSchoolScene
}
})
const setPayload = {
menu: result.menu,
newMenu: result.newMenu,
isNoStaff: result.isNoStaff
}
const { sideEffects = {} } = result
if (sideEffects.taskId !== undefined) {
setPayload.taskId = sideEffects.taskId
}
if (sideEffects.missingRecordTodoList) {
setPayload.missingRecordTodoList = sideEffects.missingRecordTodoList
}
if (sideEffects.showTaskDialog) {
setPayload.showTaskDialog = true
setPayload.taskInfo = sideEffects.taskInfo
if (sideEffects.taskId) {
commonApi.setTaskDialog({ id: sideEffects.taskId })
}
}
this.setData(setPayload, () => {
this._updateMenuBadges(userInfo, result.menu)
})
},
/** 生成当前菜单指纹(rebuild 成功后提交) */
_buildMenuFingerprintKey(userInfo, includeCustomerClue = false) {
return buildHomeMenuFingerprint(getMenuFingerprint, userInfo, {
mentorFlag: this.data.mentorFlag,
isStaff: app.globalData.isStaff,
includeCustomerClue: !!includeCustomerClue
})
},
/**
* 首页菜单唯一编排:in-flight 合并 + rebuild 完成后提交指纹
* @param {{ includeCustomerClue?: boolean, force?: boolean }} [options]
*/
async syncHomeMenus(options = {}) {
const { includeCustomerClue = false, force = false } = options
const userInfo = wx.$util.getUserInfo()
if (!userInfo) return
if (!this._menuSync) {
this._menuSync = createMenuRebuildCoordinator()
}
const fingerprint = this._buildMenuFingerprintKey(
userInfo,
includeCustomerClue
)
return this._menuSync.sync({
force,
fingerprint,
rebuild: () => this.rebuildMenus({ includeCustomerClue })
})
},
/** 仅清除菜单指纹,保留 API 缓存(导师标记等场景) */
invalidateMenuFingerprint() {
this._menuSync?.clearFingerprint()
},
/** 切店等场景:指纹 + 菜单 API / isNeed 共用缓存 */
invalidateMenuCache() {
this.invalidateMenuFingerprint()
clearSharedMenuApiCaches()
},
/**
* 菜单就绪入口(兼容旧调用)
* @param {boolean} [force] - true 时忽略指纹缓存
*/
async customerOnReady(force = false) {
return this.syncHomeMenus({
includeCustomerClue: this.data.isWait,
force
})
},
gotoMissingReception() {
const [item] = this.data.missingRecordTodoList
wx.$router._to(
'/packageEquity/pages/missingReception/missingReception',
{
reportDate: item.reportDate
},
'navigateTo'
)
},
onRoute(options) {
options && this.checkShowOrderPop(options)
wx.__HAS_SHOW_MODAL = false
// options && options.resetStoreList && this.get4SStoreList()
// 跳转工单/预约详情
// listStatus 0 待跟进 1已升级 2战败 3待支付
if (options?.isGoPage) {
// status 1待跟进(有inviteRecordId跳转预约详情无跳转待跟进工单页面 微信支付跳转工单确认页面)3待支付(跳转工单确认页面)constructionFlag(已施工页面)
let pageName =
options?.status == 1 && options?.pageParams?.id
? 'tabDate.detail'
: options.status == 3 ||
(options.status == 1 && options.selectPayType == 1)
? 'tabWorkOrder.confirmOrder'
: options.constructionFlag == 'Y' && options.status != 10
? 'tabWorkOrder.constructionOrderDetail'
: 'tabWorkOrder.orderDetail'
wx.$router.go(
`${pageName}?id=${options?.pageParams?.id}&orderCode=${options?.pageParams?.orderCode}`,
{
...options?.pageParams
}
)
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this._modalQueue = createModalQueueService(this)
this._menuSync = createMenuRebuildCoordinator()
options && this.checkShowOrderPop(options)
let today = new Date()
let startDate = today.format('yyyy-MM-dd')
let endDate = today.format('yyyy-MM-dd')
let userInfo = wx.$util.getUserInfo()
this.setData({
maxDate: new Date().format('yyyy-MM-dd'),
startDate,
endDate,
isStaff: app.globalData.isStaff,
isWait:
!wx.$hasPermission?.canSelectMultiStore?.(userInfo) &&
!wx.$hasPermission?.isTechnician?.(userInfo)
})
this.checkIsPadOrNot()
if (wx.$hasPermission?.isNormalStaff?.(userInfo))
this.get4SStoreList()
if (app.globalData.isStaff) {
this.getIsMentor()
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function (options) {
let userInfo = wx.$util.getUserInfo()
const isWait =
!wx.$hasPermission?.canSelectMultiStore?.(userInfo) &&
!wx.$hasPermission?.isTechnician?.(userInfo)
setTimeout(() => {
this.setData({
delayShow: true
})
}, 1000)
this.setData({
isStaff: app.globalData.isStaff,
isWait
})
// 菜单唯一冷启动入口(含客户线索时一次 rebuild)
this.syncHomeMenus({ includeCustomerClue: isWait })
if (userInfo) {
if (userInfo.merchantAccountList && userInfo.merchantAccountList.length) {
try {
userInfo.merchantAccountList.map(e => {
if (e == 6 || e == 8) throw true
})
} catch (error) {
userInfo.merchantType = error
}
}
}
// 如果是员工 开启订单补录轮询
// 2025-8月版本,隐藏补录入口
// this.getWaitOrder()
if (userInfo) {
this.initData(userInfo)
this.setData({
userInfo
})
loadAbnormalFlowTipState(this)
} else {
getApp().login(true)
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
time && clearTimeout(time)
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
time && clearTimeout(time)
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () { },
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () { },
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () { }
})