divisionTestStepProgress.js
4.29 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
/** subProgress 进行中:34 步骤1 / 35 已付款 / 36 已分账 / 31 失败(不驱动展示步骤) */
export const DIVISION_TEST_SUB_PROGRESS_IN_PROGRESS = [34, 35, 36, 31]
export function isDivisionTestInProgress(subProgress) {
const sp = Number(subProgress)
return DIVISION_TEST_SUB_PROGRESS_IN_PROGRESS.includes(sp)
}
export function isDivisionTestPassed(subProgress) {
const sp = Number(subProgress)
return sp > 0 && !isDivisionTestInProgress(sp)
}
function hasOutTradeNo(payload = {}) {
const v = payload.outTradeNo
return v != null && v !== ''
}
function isOrderPaidFromPayload(payload, sp) {
if (payload.orderPaid === true) return true
if (payload.paymentSuccess === true) return true
if (payload.payStatus === 1 || payload.payStatus === '1' || payload.payStatus === 'Y') {
return true
}
if (sp === 31 && hasOutTradeNo(payload)) return true
return sp >= 35
}
/**
* 仅从 subProgress / 支付状态解析业务态,不映射展示步骤
* @param {number|string} subProgress
* @param {{ orderPaid?: boolean, payStatus?: *, paymentSuccess?: boolean, outTradeNo?: string }} [payload]
*/
export function mapSubProgressToUi(subProgress, payload = {}) {
const sp = Number(subProgress)
const step1Paid = isOrderPaidFromPayload(payload, sp)
return {
step1Paid,
subProgress: sp,
isFailed: sp === 31
}
}
/** 步骤条完成态:[0]=步骤1已付款 [1]=步骤2已到达 [2]=步骤3失败标记(仅 max>=3 时) */
export function buildStepCompletedFlags(step1Paid, maxReachedStep, isFailed = false) {
const max = Number(maxReachedStep) || 1
return [
!!step1Paid,
max >= 2,
!!isFailed && max >= 3
]
}
/**
* @param {number} targetStep
* @param {{ maxReachedStep: number, step1Paid?: boolean }} uiState
*/
export function canNavigateToStep(targetStep, uiState) {
const step = Number(targetStep)
const max = Number(uiState.maxReachedStep) || 1
if (step < 1 || step > 3) return false
return step <= max
}
/**
* 回看已完成步骤时为只读
* @param {number} viewStep
* @param {{ maxReachedStep: number }} uiState
*/
export function isStepReadOnly(viewStep, uiState) {
const v = Number(viewStep)
const max = Number(uiState.maxReachedStep) || 1
return v < max
}
/**
* subProgress 决定可达的最大步骤
* @param {number|string} subProgress
* @param {number|string} [progress] 服务端主步骤 1/2/3
* @returns {number} 1 | 2 | 3
*/
export function resolveMaxReachedStepFromSubProgress(subProgress, progress) {
const sp = Number(subProgress) || 0
const mp = Number(progress) || 0
if (sp === 36) return 3
if (sp >= 35) return 2
if (sp === 31 && mp >= 1 && mp <= 3) return mp
return 1
}
/**
* 打开弹窗时决定初始展示步骤:优先 progress(1/2/3),无 progress 时回退 subProgress
* @param {number|string} subProgress
* @param {number|string} [progress] 服务端主步骤 1/2/3
* @returns {{ viewStep: number, maxReachedStep: number }}
*/
export function resolveInitialWizardSteps(subProgress, progress) {
const sp = Number(subProgress) || 0
const mp = Number(progress) || 0
let maxReachedStep = resolveMaxReachedStepFromSubProgress(sp, mp)
if (mp >= 1 && mp <= 3) {
maxReachedStep = Math.max(maxReachedStep, mp)
return { viewStep: mp, maxReachedStep }
}
if (sp === 36) {
return { viewStep: 3, maxReachedStep: 3 }
}
if (sp === 31 && maxReachedStep > 1) {
return { viewStep: maxReachedStep, maxReachedStep }
}
return { viewStep: 1, maxReachedStep }
}
export function isDivisionTestFailed(subProgress) {
return Number(subProgress) === 31
}
/**
* subProgress=31/36 等需按服务端 progress 恢复展示步骤
*/
export function shouldSyncWizardStepsFromProgress(subProgress) {
const sp = Number(subProgress)
return sp === 31 || sp === 36
}
/**
* 步骤1是否展示「关联测试订单」(而非二维码)
* @param {{ step1Paid?: boolean, subProgress?: number|string, outTradeNo?: string, maxReachedStep?: number, viewStep?: number }} params
*/
export function shouldShowStep1OrderLinked({
step1Paid = false,
subProgress = 0,
outTradeNo = '',
maxReachedStep = 1,
viewStep = 1
} = {}) {
if (step1Paid) return true
if (Number(subProgress) === 31 && outTradeNo) return true
if (Number(maxReachedStep) > 1 && Number(viewStep) === 1) return true
return false
}