staffDailyReportNavigation.js
2.01 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
import {
fetchDailyReportNewVersionMenuVisible,
resolveShopMerchantId
} from './dailyReportNewVersionGate.js'
import {
buildStoreDailyReportNavigateUrl,
canShowStaffDailyNew
} from './dynamicFormMenus.js'
export function resolveLegacyStaffDailyRoute(userInfo = {}) {
if (userInfo.sceneType === 0) {
return {
type: 'router',
route: 'tabWorkOrder.staffDaily',
params: { scene: 0 }
}
}
return {
type: 'router',
route: 'tabWorkOrder.upgradeStaffDaily',
params: {}
}
}
export function buildStoreDailyReportUrlWithDate(reportDate) {
const base = buildStoreDailyReportNavigateUrl()
if (!reportDate) {
return base
}
const sep = base.includes('?') ? '&' : '?'
return `${base}${sep}reportDate=${encodeURIComponent(reportDate)}`
}
/**
* 是否跳转新版驻店日报(白名单 + 角色门禁)
* @param {Object} [userInfo]
* @returns {Promise<boolean>}
*/
export async function shouldUseNewStaffDailyReport(userInfo = {}) {
if (!canShowStaffDailyNew(userInfo)) {
return false
}
if (wx?.$hasPermission?.canSelectMultiStore?.(userInfo)) {
return false
}
const merchantId = resolveShopMerchantId(userInfo)
if (!merchantId) {
return false
}
return fetchDailyReportNewVersionMenuVisible(merchantId)
}
/**
* 按白名单跳转新/老驻店日报
* @param {Object} [options]
* @param {Object} [options.userInfo]
* @param {string} [options.reportDate] yyyy-MM-dd
*/
export async function navigateToRequiredDailyReport(options = {}) {
const info = options.userInfo || wx.$util?.getUserInfo?.() || {}
if (await shouldUseNewStaffDailyReport(info)) {
const url = buildStoreDailyReportUrlWithDate(options.reportDate)
wx.navigateTo({ url })
return { type: 'navigate', url }
}
const legacy = resolveLegacyStaffDailyRoute(info)
const params = { ...(legacy.params || {}) }
if (options.reportDate) {
params.reportDate = options.reportDate
}
wx.$router.go(legacy.route, params)
return { type: 'router', route: legacy.route, params }
}
export const navigateToStaffDailyReport = navigateToRequiredDailyReport