index.js
19.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
// packageEquity/pages/index/index.js — 权益首页 Component(菜单见 menu/,非菜单见 services/)
import { checkDailyReport } from '~/store/ModalToQueueControl'
import { navigateToRequiredDailyReport } from '~/utils/staffDailyReportNavigation.js'
import {
getReceptionRecordList,
getRecordDetailList,
checkMerchantDirect,
checkMissingReception
} from '../../receptionRecordsApi'
import aiApi from '../../aiApi'
import { getBusinessSchoolScene } from '~/store/index'
import { getQuotationStatistics, outputValueStatistics } from '../../api'
import commonApi from '~/api/api'
import carLifeApi from '../../carEquityApi'
import reportPageTrackMixin from '~/mixins/reportPageTrackMixin'
import {
EQUITY_ITEM_DATA_LIST,
EQUITY_STATIC_DATA_LIST,
SWIPER_INDEX_TO_ACTIVE
} from '../../config/dashboardConfig.js'
import {
buildOutputValueDateRange,
normalizeOutputValueStats,
normalizeQuotationStatistics
} from '../../services/dashboardService.js'
import {
sliceTodoPreview,
buildEquityStaffRemindParams,
buildEquityShutDownTaskParams,
resolveTodoGotoAction
} from '../../services/todoService.js'
import {
buildReceptionQueryParams,
normalizeReceptionDateSections,
mergeReceptionDetails,
computeReceptionHasMore,
buildReceptionFingerprint
} from '../../services/receptionListService.js'
import {
buildHomeRefreshFingerprint,
withHomeRefreshDedup
} from '../../services/homeRefreshService.js'
import { openOrderPromptWithRestrictState } from '../../../tabIndex/services/newOrderAbnormalFlowRestrict.service.js'
import {
buildEquityMenusAsync,
createEquityMenuJumpHandler,
applyEquityMenuBadges,
onWorkReportPopupSelect,
handleOrderPromptConfirm,
handleOrderPromptCancel,
getMenuFingerprint,
invalidateMenuAndApiCaches as clearSharedMenuApiCaches
} from '../../menu/index.js'
import {
buildEquityMenuFingerprint,
createMenuRebuildCoordinator
} from '../../services/menuSyncHelpers.js'
const app = getApp()
let lastPath = null
const IMG_URL =
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
Component({
behaviors: [reportPageTrackMixin],
properties: {
navBarHeight: { type: Number, value: 0 },
mode: {
type: Number,
observer(newVal, oldVal) {
if (newVal === oldVal) return
if (!this._initialMenuBuilt && newVal != null) {
this._buildInitialMenusOnce()
return
}
if (oldVal != null && newVal !== oldVal) {
this.syncEquityMenus({ force: true, mode: newVal })
}
}
},
waitInputCount: { type: Number },
showScreen: { type: Boolean },
/** Tab0 可见性:false→true 时刷新看板/待办(与 equityPage onShow 路径互补) */
show: {
type: Number,
observer(n) {
const userInfo = wx.$util.getUserInfo() || {}
if (n && wx.$hasPermission?.isNotMentor?.(userInfo)) {
this.onPageShow()
if (this._homeReady) {
this.refreshEquityHome({ skipMenu: true })
}
} else if (wx.$hasPermission?.isNotMentor?.(userInfo)) {
this.onPageHide()
}
}
},
serviceCenterUnreadNum: { type: Number, value: 0 }
},
data: {
nothing: false,
listData: [],
IMG_URL,
statisticsObj: {},
dataActive: 'today',
staticDataList: EQUITY_STATIC_DATA_LIST,
itemDataList: EQUITY_ITEM_DATA_LIST,
menuList: [],
loginRoleLabel: {
1: '超管',
2: '商户管理员',
3: '区域运营',
4: '驻店负责人',
5: '广联销售',
6: '飞行督导',
7: '技师',
8: '技师督导'
},
loginRole: '',
userInfo: {},
staticData: {},
taskInfo: {},
current: 0,
todoList: [],
missingRecordTodoList: [],
stodoList: [],
todos: {
1: '日报填写提醒',
2: '今日尚未开单',
3: '工牌处于离线状态',
4: '客户跟进提醒',
5: '培训提醒',
6: '资料查看提醒',
7: '上班打卡',
8: '下班打卡'
},
ispopUp: true,
isPad: false,
pageNum: 1,
searchForm: {},
showEmployeeName: false,
isShowDefeatBtn: true,
loaded: false,
track_event_code: 'staff_reception_list',
violationStatus: 1,
recordTabList: [
{ text: '疑似违规', value: 1 },
{ text: '未违规', value: 0 },
{ text: '已违规', value: 2 }
],
showReportPopup: false,
reportTemplateList: [],
currentReportItem: null,
mentorFlag: false
},
lifetimes: {
attached() {
this._menuSync = createMenuRebuildCoordinator()
const userInfo = wx.$util.getUserInfo()
this.setData({
loginRole: userInfo.subLoginUser?.loginRole,
userInfo
})
this.onLoad()
}
},
methods: {
handleNavigateServiceCenter() {
wx.$router.go('tabWorkOrder.serviceNoticeList')
},
onReportPopupCancel() {
this.setData({ showReportPopup: false })
},
onReportPopupSelect(e) {
onWorkReportPopupSelect(this, e.detail)
},
onScroll() {
const { navBarHeight } = this.data
const query = wx.createSelectorQuery().in(this)
query.select('.receive-list-host').boundingClientRect()
query.exec(res => {
if (res[0]?.top - 6 <= navBarHeight) {
this.setData({ isScrollTop: true, isSticky: true })
} else {
this.setData({ isScrollTop: false })
}
})
},
onSwiperChange(e) {
const current = e.detail.current
const name = SWIPER_INDEX_TO_ACTIVE[current] || 'today'
this.setData({ current, dataActive: name })
this.refreshDashboard(name)
},
checkIsPadOrNot() {
wx.getRendererUserAgent({
success: res => {
const isPad = /iPad|Android.*Tablet|Kindle|Silk/i.test(res.userAgent)
this.setData({ isPad })
}
})
},
/** @deprecated 兼容 equityPage selectComponent */
async menuListRest() {
this.invalidateMenuCache()
return this.syncEquityMenus({ force: true })
},
invalidateMenuFingerprint() {
this._menuSync?.clearFingerprint()
},
/** 切店:指纹 + 菜单 API / isNeed 共用缓存 */
invalidateMenuCache() {
this.invalidateMenuFingerprint()
clearSharedMenuApiCaches()
},
_buildMenuFingerprintKey(userInfo, mode) {
return buildEquityMenuFingerprint(getMenuFingerprint, userInfo, {
mentorFlag: this.data.mentorFlag,
isStaff: app.globalData.isStaff,
mode: mode !== undefined ? mode : this.data.mode
})
},
/**
* 权益首页菜单唯一编排:in-flight 合并 + rebuild 完成后提交指纹
* @param {{ force?: boolean, mode?: number }} [options]
*/
async syncEquityMenus(options = {}) {
const { force = false, mode: modeOpt } = options
const userInfo = wx.$util.getUserInfo()
if (!userInfo) return
if (!this._menuSync) {
this._menuSync = createMenuRebuildCoordinator()
}
const mode = modeOpt !== undefined ? modeOpt : this.data.mode
const fingerprint = this._buildMenuFingerprintKey(userInfo, mode)
return this._menuSync.sync({
force,
fingerprint,
rebuild: () => this.rebuildEquityMenus({ force: true, mode })
})
},
async _buildInitialMenusOnce() {
if (this._initialMenuBuilt) return
if (this.data.mode == null) return
this._initialMenuBuilt = true
await this.syncEquityMenus({ force: true, mode: this.data.mode })
},
async ensureMentorFlag() {
const userInfo = wx.$util.getUserInfo() || {}
if (wx.$hasPermission?.canSelectMultiStore?.(userInfo)) {
return
}
const prevMentor = this.data.mentorFlag
try {
const res = await commonApi.getStaffMentorFlag({
staffPhone: userInfo?.phone
})
if (res.code == 0) {
const nextMentor = !!res.data
if (nextMentor === prevMentor) {
return
}
await new Promise(resolve => {
this.setData({ mentorFlag: nextMentor }, resolve)
})
if (this._initialMenuBuilt) {
this.invalidateMenuFingerprint()
await this.syncEquityMenus({ force: true })
}
}
} catch {
// ignore
}
},
async rebuildEquityMenus(options = {}) {
const userInfo = wx.$util.getUserInfo()
if (!userInfo) return
const mode =
options.mode !== undefined ? options.mode : this.data.mode
const result = await buildEquityMenusAsync({
userInfo,
isStaff: app.globalData.isStaff,
mentorFlag: this.data.mentorFlag,
mode,
merchantBrand: this.data.merchantBrand || [],
deps: {
getBusinessSchoolScene,
commonApi,
aiApi,
carLifeApi,
receptionRecordsApi: {
checkMerchantDirect,
checkMissingReception
}
}
})
const setPayload = { menuList: result.menuList }
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 })
}
if (sideEffects.storeRangeList) {
setPayload.storeRangeList = sideEffects.storeRangeList
setPayload.listData = []
setPayload.nothing = false
}
if (sideEffects.showReceive !== undefined) {
setPayload.showReceive = sideEffects.showReceive
}
this.setData(setPayload, () => {
applyEquityMenuBadges(this, userInfo, result.menuList)
if (sideEffects.showReceive && sideEffects.storeRangeList) {
this.maybeRefreshReceptionList()
}
})
},
/**
* 切 4S 店后同步门店上下文、品牌列表并重建菜单(由 equityPage.initData 调用)。
* @param {Object} [options]
* @param {number} [options.mode] - 父页 getMerchant4SMode 结果,避免 properties.mode 延迟
*/
async onStoreSwitched(options = {}) {
const userInfo = wx.$util.getUserInfo() || {}
const storeInfo = userInfo.default4SStoreInfo || {}
await new Promise(resolve => {
this.setData({ userInfo, storeInfo }, resolve)
})
if (!wx.$hasPermission?.canViewViolation?.(userInfo)) {
await this.getMerchantCarBrandList()
}
this.invalidateMenuCache()
const mode =
options.mode !== undefined ? options.mode : this.data.mode
await this.syncEquityMenus({ force: true, mode })
if (this._homeReady) {
await this.refreshEquityHome({
force: true,
forceReception: true
})
}
},
/**
* Tab0 统一刷新:看板 + 待办 + 可选菜单/接待列表。
* 经 homeRefreshService 做 in-flight 去重;每次切回 Tab0 都会执行(无 TTL 跳过)。
* @param {Object} [options]
* @param {boolean} [options.skipMenu=false] - true 时不重建菜单(Tab 切回常用)
* @param {boolean} [options.forceReception=false] - 强制刷新接待列表
* @param {boolean} [options.force=false] - 保留扩展
* @returns {Promise<void>}
*/
async refreshEquityHome(options = {}) {
const { skipMenu = false, forceReception = false, force = false } = options
const userInfo = wx.$util.getUserInfo() || {}
const fingerprint = buildHomeRefreshFingerprint({
dataActive: this.data.dataActive,
shopMerchantId: userInfo?.default4SStoreInfo?.merchantId,
isWait: this.data.isWait
})
return withHomeRefreshDedup(fingerprint, { force }, async () => {
const tasks = [
this.refreshDashboard(this.data.dataActive),
this.refreshQuotationTotal()
]
if (this.data.isWait) tasks.push(this.fetchStaffRemindList())
await Promise.all(tasks)
if (!skipMenu) await this.syncEquityMenus()
if (this.data.showReceive) {
this.maybeRefreshReceptionList(forceReception)
}
})
},
refreshDashboard(dataActive) {
const userInfo = wx.$util.getUserInfo()
const active = dataActive || this.data.dataActive
return outputValueStatistics({
...buildOutputValueDateRange(active),
shopMerchantId: userInfo?.default4SStoreInfo?.merchantId
}).then(res => {
if (res.code == 0) {
this.setData({ staticData: normalizeOutputValueStats(res.data) })
} else {
wx.$util.showToast(res.message)
}
})
},
refreshQuotationTotal() {
const { storeInfo } = this.data
return getQuotationStatistics({
merchantId: storeInfo?.merchantId
}).then(res => {
if (res.code == '0') {
this.setData({
statisticsObj: normalizeQuotationStatistics(res.data)
})
} else {
wx.$util.showToast(res.message || '接口异常')
}
})
},
fetchStaffRemindList() {
const userInfo = wx.$util.getUserInfo()
return commonApi
.getStaffRemindList(buildEquityStaffRemindParams(userInfo))
.then(result => {
const preview = sliceTodoPreview(result.data || [])
this.setData({
todoList: preview.todoList,
stodoList: preview.stodoList
})
})
},
onTodoClose(e) {
const taskId = e.detail.id
const userInfo = wx.$util.getUserInfo()
commonApi
.shutDownTaskApi(buildEquityShutDownTaskParams(userInfo, taskId))
.then(result => {
if (result.data) {
this.fetchStaffRemindList()
wx.showToast({ title: '关闭成功', icon: 'success' })
}
})
},
async onTodoGoto(e) {
const action = resolveTodoGotoAction(e.detail.id, {
mode: this.data.mode,
merchantBrand: this.data.merchantBrand
})
if (action.type === 'navigate') {
if (Number(e.detail.id) === 1) {
navigateToRequiredDailyReport({ reportDate: action.params?.reportDate })
return
}
wx.$router.go(action.route, action.params)
} else if (action.type === 'showPromptDialog') {
await openOrderPromptWithRestrictState(this)
}
},
onTodoPackup() {
if (this.data.ispopUp) {
this.setData({
stodoList: this.data.todoList.slice(0, 2),
ispopUp: false
})
} else {
this.setData({ ispopUp: true })
}
},
getReceptionParams() {
return buildReceptionQueryParams({
searchForm: this.data.searchForm,
isFilterDefeat: this.data.isFilterDefeat,
isFilterUpgrade: this.data.isFilterUpgrade,
storeRangeList: this.data.storeRangeList,
violationStatus: this.data.violationStatus,
userInfo: wx.$util.getUserInfo() || {},
hasPermission: wx.$hasPermission || {}
})
},
maybeRefreshReceptionList(force = false) {
const userInfo = wx.$util.getUserInfo() || {}
const fp = buildReceptionFingerprint({
userInfo,
violationStatus: this.data.violationStatus,
searchForm: this.data.searchForm
})
if (force || fp !== this._receptionFingerprint) {
this._receptionFingerprint = fp
this.getReceptionList()
}
},
goReceptionDetail(e) {
const { item } = e.detail
wx.$router.go('receptionDetail', { ...item, hideScore: 1 })
wx.$track.setTrackData(0, 'reception_detail', { batchId: item.batchId }, '', 0)
},
getReceptionList() {
const params = this.getReceptionParams()
this.setData({ loaded: false }, () => {
wx.showLoading({ title: '加载中' })
getReceptionRecordList({
merchantNo: params.merchantNo,
startDateTime: params.startDateTime,
endDateTime: params.endDateTime,
staffUuids: params.staffUuids
})
.then(res => {
if (res.code == 0) {
this.setData(
{
listData: normalizeReceptionDateSections(res.data),
pageNum: 1,
nothing: false
},
() => this.getReceptionRecordDetailInfo()
)
} else {
wx.$util.showToast(res.message)
wx.hideLoading()
}
})
.catch(() => wx.hideLoading())
})
},
getReceptionRecordDetailInfo() {
const { pageNum, listData, nothing } = this.data
if (nothing) return
const params = { pageNum, ...this.getReceptionParams() }
wx.showLoading({ title: '加载中' })
this.track_businessParam = params
getRecordDetailList(params)
.then(res => {
if (res.code == 0) {
const merged = mergeReceptionDetails(listData, res.data?.list || [])
this.setData({
loaded: true,
listData: merged,
pageNum: pageNum + 1,
nothing: computeReceptionHasMore(
merged,
pageNum,
res.data?.pages,
res.data?.total
)
})
} else {
wx.$util.showToast(res.message)
}
wx.$receptionLoaded = true
wx.hideLoading()
})
.catch(() => wx.hideLoading())
},
onBottomRefresh() {
this.getReceptionRecordDetailInfo()
},
async onLoad() {
const isStaff = app.globalData.isStaff
const userInfo = wx.$util.getUserInfo() || {}
if (wx.$hasPermission?.isNotMentor?.(userInfo)) this.onPageShow()
if (wx.$hasPermission?.canSelectMultiStore?.(userInfo)) {
this.setData({ showEmployeeName: true, isShowDefeatBtn: false })
}
const isWait = !wx.$hasPermission?.canSelectMultiStore?.(userInfo)
this.setData({
storeInfo: userInfo?.default4SStoreInfo || {},
userInfo,
isStaff,
isWait
})
this.checkIsPadOrNot()
if (!wx.$hasPermission?.canViewViolation?.(userInfo)) {
this.getMerchantCarBrandList()
}
await this.ensureMentorFlag()
await this.refreshEquityHome({ skipMenu: true })
this._homeReady = true
},
navGo: wx.$util.throttle(async function (e) {
const { item } = e.currentTarget.dataset
if (item.path === lastPath) return
setTimeout(() => {
lastPath = null
}, 2000)
lastPath = item.path
if (!this._equityMenuJump) {
this._equityMenuJump = createEquityMenuJumpHandler(this)
}
return this._equityMenuJump(e)
}, 2000),
async promptHandleConfirm(e) {
await handleOrderPromptConfirm(this, e.detail)
},
promptCancel() {
handleOrderPromptCancel(this)
},
async checkDaily() {
const staffCheck = await checkDailyReport(true)
if (staffCheck) return false
},
getSelectByMerchantId() {
return new Promise(resolve => {
const { default4SStoreInfo: { merchantId } } = wx.$util.getUserInfo()
carLifeApi.getSelectByMerchantId({ merchantNo: merchantId }).then(res => {
resolve(res.data)
})
})
},
async getMerchantCarBrandList() {
const userInfo = wx.$util.getUserInfo() || this.data.userInfo || {}
const shopMerchantId = userInfo.shopMerchantId
if (!shopMerchantId) return
const { code, data } = await carLifeApi.getMerchantCarBrandList([shopMerchantId])
if (code == 0 && data) {
this.setData({
merchantBrand: data?.data[0]?.carBrandList || []
})
}
},
back() {
const thisPage = wx.$router.getPageInstance()
thisPage.setData({ showScreen: false, show_reception_confirm: false })
},
showScreenPop() {
const { isFilterDefeat, isFilterUpgrade } = this.data
const thisPage = wx.$router.getPageInstance()
thisPage.setData({
showScreen: true,
showReceptionRendering: true,
show_reception_confirm: true,
isFilterDefeat,
isFilterUpgrade
})
},
searchScreen(e) {
const searchForm = e.detail
const orderResult = searchForm?.orderResult || []
this.setData(
{
isFilterUpgrade: orderResult?.includes(1),
isFilterDefeat: orderResult?.includes(2),
searchForm,
listData: [],
nothing: false
},
() => {
this.getReceptionList()
wx.$track.setTrackData(0, 'staff_reception_search', this.getReceptionParams())
}
)
this.back()
this.refreshDashboard(this.data.dataActive)
},
goPage() {
const { violationStatus } = this.data
wx.navigateTo({
url: `/packageEquity/pages/receptionRecords/receptionRecords?hideScore=1&tabValue=${violationStatus}`
})
wx.$track.setTrackData(0, 'see_more')
},
onHide() {
const userInfo = wx.$util.getUserInfo() || {}
if (wx.$hasPermission?.isNotMentor?.(userInfo)) this.onPageHide()
},
onUnload() {
const userInfo = wx.$util.getUserInfo() || {}
if (wx.$hasPermission?.isNotMentor?.(userInfo)) this.onPageHide()
},
recordTabClick(e) {
const { value } = e.detail
if (value == this.data.violationStatus) return
this.setData({ listData: [], nothing: false, violationStatus: value })
this.getReceptionList()
wx.$track.setTrackData(0, 'staff_reception_search', this.getReceptionParams())
},
gotoMissingReception() {
const [item] = this.data.missingRecordTodoList
wx.$router._to(
'/packageEquity/pages/missingReception/missingReception',
{ reportDate: item.reportDate },
'navigateTo'
)
}
}
})