abnormalFlow.js
11.5 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
/** 异常流水审批状态(Swagger AbnormalFlowApprovalStatus 1~5) */
import { Util } from "@/common/util"
function formatDate(val) {
return val ? Util.dateFormate(val, "YYYY-MM-DD HH:mm:ss") : "-"
}
function formatDelayDeadline(val) {
if (!val) {
return "-";
}
const str = String(val).trim();
const dateMatch = str.match(/^(\d{4}-\d{2}-\d{2})/);
if (dateMatch) {
return dateMatch[1];
}
return Util.dateFormate(val, "YYYY-MM-DD");
}
export const APPROVAL_STATUS = {
WAIT_REGIONAL: 1,
REGIONAL_REJECTED: 2,
WAIT_BACKEND: 3,
BACKEND_REJECTED: 4,
APPROVED: 5
}
export const APPROVAL_STATUS_LIST = [
{
value: APPROVAL_STATUS.WAIT_REGIONAL,
label: "待区域经理审批",
tagType: "warning",
spotClass: "yellowSpot"
},
{
value: APPROVAL_STATUS.REGIONAL_REJECTED,
label: "区域经理审批驳回",
tagType: "danger",
spotClass: "redSpot"
},
{
value: APPROVAL_STATUS.WAIT_BACKEND,
label: "待后台审批",
tagType: "warning",
spotClass: "yellowSpot"
},
{
value: APPROVAL_STATUS.BACKEND_REJECTED,
label: "后台审批驳回",
tagType: "danger",
spotClass: "redSpot"
},
{
value: APPROVAL_STATUS.APPROVED,
label: "后台审批通过",
tagType: "success",
spotClass: "greenSpot"
}
]
/** 审批日志状态(同数值在不同 approvalSource 下含义不同) */
export const APPROVAL_LOG_STATUS_LIST = [
{
value: APPROVAL_STATUS.REGIONAL_REJECTED,
approvalSource: 0,
label: "区域经理审批驳回",
tagType: "danger",
spotClass: "redSpot",
},
{
value: APPROVAL_STATUS.WAIT_BACKEND,
approvalSource: 0,
label: "区域经理审批通过",
tagType: "success",
spotClass: "greenSpot",
},
{
value: APPROVAL_STATUS.BACKEND_REJECTED,
approvalSource: 1,
label: "后台审批驳回",
tagType: "danger",
spotClass: "redSpot",
},
{
value: APPROVAL_STATUS.APPROVED,
approvalSource: 1,
label: "后台审批通过",
tagType: "success",
spotClass: "greenSpot",
},
]
/** 异常类型(Swagger AbnormalFlowType) */
export const ABNORMAL_TYPE_LIST = [
{ value: 1, label: "已付款未录单" },
{ value: 2, label: "多流水对应一单" },
{ value: 3, label: "一流水对应多单" },
{ value: 4, label: "对公收款" },
{ value: 5, label: "混合支付" },
{ value: 6, label: "金额不一致" },
{ value: 7, label: "其他异常" }
]
const PAY_TYPE_MAP = {
1: "线上微信支付",
2: "线下收款",
3: "POS机收款",
4: "支付宝支付",
5: "嘀加收款",
6: "对公转账",
7: "其他收款"
}
const DISTRIBUTION_STATUS_MAP = {
0: "未分账",
1: "已分账",
2: "分账中",
3: "分账成功",
4: "分账失败"
}
const REFUND_STATUS_MAP = {
0: "未退款",
1: "部分退款"
}
function normalizeStatus(status) {
if (status === null || status === undefined || status === "") {
return null
}
const num = Number(status)
return Number.isNaN(num) ? status : num
}
export function getApprovalStatusMeta(status) {
const normalized = normalizeStatus(status)
const item = APPROVAL_STATUS_LIST.find(
(s) => s.value === normalized || s.label === status
)
return item || { label: "-", tagType: "info", spotClass: "ashSpot" }
}
export function getApprovalLogStatusMeta(status, approvalSource = 0) {
const normalized = normalizeStatus(status)
const source = String(approvalSource)
const item = APPROVAL_LOG_STATUS_LIST.find(
(s) => s.value === normalized && String(s.approvalSource) === source
)
return item || getApprovalStatusMeta(status)
}
function buildRoundStatusFields(statusLabel, statusMeta) {
return {
statusLabel,
statusMeta,
}
}
function buildRoundDisplayFromLog(log, approvalSource) {
if (!log) {
return null
}
const meta = getApprovalLogStatusMeta(
log.approvalStatus,
log.approvalSource ?? approvalSource
)
return {
...buildRoundStatusFields(meta.label, meta),
approver: log.operatorName || "-",
time: formatDate(log.createdDate),
remark: log.remark || "-",
}
}
export function getAbnormalTypeLabel(type) {
const item = ABNORMAL_TYPE_LIST.find(
(t) => t.value === Number(type) || t.label === type
)
return item ? item.label : type || "-"
}
/**
* 抽屉模式:仅待后台审批时可提交
*/
export function getDrawerMode(detail) {
if (!detail) return "view"
const status = normalizeStatus(detail.approvalStatus)
return status === APPROVAL_STATUS.WAIT_BACKEND ? "approve" : "view"
}
export function shouldShowSecondRoundSection(approvalStatus) {
const status = normalizeStatus(approvalStatus)
return (
status === APPROVAL_STATUS.WAIT_BACKEND
|| status === APPROVAL_STATUS.BACKEND_REJECTED
|| status === APPROVAL_STATUS.APPROVED
)
}
function getLatestLog(logs, approvalSource) {
const filtered = (logs || []).filter(
(log) => String(log.approvalSource) === String(approvalSource)
)
if (!filtered.length) {
return null
}
return filtered[filtered.length - 1]
}
function getFirstRoundDisplay(approvalStatus, regionalLog) {
const status = normalizeStatus(approvalStatus)
const pendingMeta = getApprovalStatusMeta(APPROVAL_STATUS.WAIT_REGIONAL)
const rejectedMeta = getApprovalStatusMeta(APPROVAL_STATUS.REGIONAL_REJECTED)
if (status === APPROVAL_STATUS.WAIT_REGIONAL) {
return {
firstRoundStatusLabel: pendingMeta.label,
firstRoundStatusMeta: pendingMeta,
firstRoundApprover: "-",
firstRoundTime: "-",
firstRoundRemark: "-",
}
}
if (status === APPROVAL_STATUS.REGIONAL_REJECTED) {
const logDisplay = buildRoundDisplayFromLog(regionalLog, 0)
return {
firstRoundStatusLabel: logDisplay?.statusLabel || rejectedMeta.label,
firstRoundStatusMeta: logDisplay?.statusMeta || rejectedMeta,
firstRoundApprover: logDisplay?.approver || "-",
firstRoundTime: logDisplay?.time || "-",
firstRoundRemark: logDisplay?.remark || "-",
}
}
if (
status === APPROVAL_STATUS.WAIT_BACKEND
|| status === APPROVAL_STATUS.BACKEND_REJECTED
|| status === APPROVAL_STATUS.APPROVED
) {
const logDisplay = buildRoundDisplayFromLog(regionalLog, 0)
if (logDisplay) {
return {
firstRoundStatusLabel: logDisplay.statusLabel,
firstRoundStatusMeta: logDisplay.statusMeta,
firstRoundApprover: logDisplay.approver,
firstRoundTime: logDisplay.time,
firstRoundRemark: logDisplay.remark,
}
}
return {
firstRoundStatusLabel: "-",
firstRoundStatusMeta: { label: "-", tagType: "info", spotClass: "ashSpot" },
firstRoundApprover: "-",
firstRoundTime: "-",
firstRoundRemark: "-",
}
}
const logDisplay = buildRoundDisplayFromLog(regionalLog, 0)
if (logDisplay) {
return {
firstRoundStatusLabel: logDisplay.statusLabel,
firstRoundStatusMeta: logDisplay.statusMeta,
firstRoundApprover: logDisplay.approver,
firstRoundTime: logDisplay.time,
firstRoundRemark: logDisplay.remark,
}
}
return {
firstRoundStatusLabel: pendingMeta.label,
firstRoundStatusMeta: pendingMeta,
firstRoundApprover: "-",
firstRoundTime: "-",
firstRoundRemark: "-",
}
}
function getSecondRoundDisplay(approvalStatus, hqLog) {
const status = normalizeStatus(approvalStatus)
const pendingMeta = getApprovalStatusMeta(APPROVAL_STATUS.WAIT_BACKEND)
if (status === APPROVAL_STATUS.WAIT_BACKEND) {
return {
secondRoundStatusLabel: pendingMeta.label,
secondRoundStatusMeta: pendingMeta,
secondRoundApprover: "-",
secondRoundTime: "-",
secondRoundRemark: "-",
}
}
const logDisplay = buildRoundDisplayFromLog(hqLog, 1)
if (logDisplay) {
return {
secondRoundStatusLabel: logDisplay.statusLabel,
secondRoundStatusMeta: logDisplay.statusMeta,
secondRoundApprover: logDisplay.approver,
secondRoundTime: logDisplay.time,
secondRoundRemark: logDisplay.remark,
}
}
const declarationMeta = getApprovalStatusMeta(status)
return {
secondRoundStatusLabel: declarationMeta.label,
secondRoundStatusMeta: declarationMeta,
secondRoundApprover: "-",
secondRoundTime: "-",
secondRoundRemark: "-",
}
}
/**
* PC 报备详情接口 data → 抽屉 detailInfo
*/
export function mapPcDeclarationDetail(apiData, rowData = {}) {
const { tradeInfo = {}, declarationInfo = {}, approvalLogs = [] } = apiData || {}
const approvalStatus = normalizeStatus(
rowData.declarationApprovalStatus
?? apiData?.declarationApprovalStatus
?? declarationInfo.approvalStatus
)
const regionalLog = getLatestLog(approvalLogs, 0)
const hqLog = getLatestLog(approvalLogs, 1)
const firstRound = getFirstRoundDisplay(approvalStatus, regionalLog)
const secondRound = getSecondRoundDisplay(approvalStatus, hqLog)
return {
tradeNo: tradeInfo.tradeNo || rowData.tradeNo || "-",
totalPrice: tradeInfo.totalPrice ?? rowData.totalPrice,
notRefundedTotalPrice:
tradeInfo.notRefundedTotalPrice ?? rowData.notRefundedTotalPrice,
posTrmNo: tradeInfo.posTrmNo || rowData.posTrmNo || "-",
payDate: formatDate(tradeInfo.payDate || rowData.payDate),
yqMerchantName:
tradeInfo.yqMerchantName || rowData.yqMerchantName || rowData.merchantName || "-",
payChannel: tradeInfo.payChannel || rowData.payChannel || "-",
payTypeLabel:
PAY_TYPE_MAP[tradeInfo.payType ?? rowData.payType]
|| tradeInfo.payType
|| rowData.payType
|| "-",
distributionStatusLabel:
DISTRIBUTION_STATUS_MAP[tradeInfo.distributionStatus ?? rowData.distributionStatus]
|| tradeInfo.distributionStatus
|| rowData.distributionStatus
|| "-",
trafficMerchantName:
tradeInfo.merchantName || rowData.merchantName || "-",
refundStatusLabel:
REFUND_STATUS_MAP[tradeInfo.refundStatus ?? rowData.refundStatus]
|| tradeInfo.refundStatus
|| rowData.refundStatus
|| "-",
reporterName: declarationInfo.createdBy || "-",
reportTime: formatDate(declarationInfo.createdDate),
abnormalType: declarationInfo.abnormalType,
abnormalTypeLabel: getAbnormalTypeLabel(declarationInfo.abnormalType),
reportRemark: declarationInfo.remark || "-",
voucherList: declarationInfo.voucherImageUrls || [],
approvalStatus,
declarationId: rowData.declarationId,
...firstRound,
...secondRound,
extensionDeadline: formatDelayDeadline(declarationInfo.delayDeadline),
}
}
/**
* 审批表单 → PC 总部审批接口入参
*/
export function mapApproveFormToApi(form, declarationId) {
const params = {
id: declarationId,
approvalStatus: form.auditResult === 1
? APPROVAL_STATUS.APPROVED
: APPROVAL_STATUS.BACKEND_REJECTED,
remark: form.auditRemark
}
if (form.auditResult === 1 && form.extensionDeadline) {
const deadline = String(form.extensionDeadline).trim()
params.delayDeadline = /^\d{4}-\d{2}-\d{2}$/.test(deadline)
? `${deadline} 00:00:00`
: deadline
}
return params
}
export function getDefaultExtensionDate(days = 3) {
const date = new Date()
date.setDate(date.getDate() + days)
const y = date.getFullYear()
const m = String(date.getMonth() + 1).padStart(2, "0")
const d = String(date.getDate()).padStart(2, "0")
return `${y}-${m}-${d}`
}