159 lines
4.6 KiB
TypeScript
159 lines
4.6 KiB
TypeScript
import { formatDisplayOrDash } from '@/utils/datetime-display'
|
|
|
|
export type PaymentFlowStepKey =
|
|
| 'receipt-submit'
|
|
| 'finance-receipt'
|
|
| 'refund-submit'
|
|
| 'finance-refund'
|
|
|
|
export type PaymentFlowStepState = 'pending' | 'done' | 'current'
|
|
|
|
export interface PaymentFlowStepField {
|
|
label: string
|
|
value: string
|
|
multiline?: boolean
|
|
slot?: 'attachments'
|
|
attachmentUrls?: string
|
|
}
|
|
|
|
export interface PaymentFlowStep {
|
|
key: PaymentFlowStepKey
|
|
title: string
|
|
state: PaymentFlowStepState
|
|
time: string
|
|
fields: PaymentFlowStepField[]
|
|
}
|
|
|
|
function dash(v: unknown) {
|
|
return formatDisplayOrDash(v)
|
|
}
|
|
|
|
function formatAmount(v: unknown) {
|
|
if (v == null || v === '') return '—'
|
|
const n = Number(v)
|
|
if (Number.isNaN(n)) return '—'
|
|
return `¥${n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`
|
|
}
|
|
|
|
function hasReceiptSubmit(detail: Record<string, unknown>) {
|
|
const status = String(detail.payStatus || '')
|
|
return ['jfqrz', 'yjf', 'tfqrz', 'ytf'].includes(status)
|
|
}
|
|
|
|
function hasFinanceReceipt(detail: Record<string, unknown>) {
|
|
const status = String(detail.payStatus || '')
|
|
return ['yjf', 'tfqrz', 'ytf'].includes(status) || Boolean(detail.financeConfirmTime)
|
|
}
|
|
|
|
function hasRefundSubmit(detail: Record<string, unknown>) {
|
|
const status = String(detail.payStatus || '')
|
|
return ['tfqrz', 'ytf'].includes(status) || Boolean(detail.refundApplyTime)
|
|
}
|
|
|
|
function hasFinanceRefund(detail: Record<string, unknown>) {
|
|
const status = String(detail.payStatus || '')
|
|
return status === 'ytf' || Boolean(detail.refundFinanceConfirmTime)
|
|
}
|
|
|
|
function resolveStepState(
|
|
key: PaymentFlowStepKey,
|
|
detail: Record<string, unknown>,
|
|
activeStepKey?: PaymentFlowStepKey
|
|
): PaymentFlowStepState {
|
|
if (activeStepKey === key) return 'current'
|
|
|
|
const doneMap: Record<PaymentFlowStepKey, boolean> = {
|
|
'receipt-submit': hasReceiptSubmit(detail),
|
|
'finance-receipt': hasFinanceReceipt(detail),
|
|
'refund-submit': hasRefundSubmit(detail),
|
|
'finance-refund': hasFinanceRefund(detail)
|
|
}
|
|
|
|
if (doneMap[key]) {
|
|
if (activeStepKey === key) return 'current'
|
|
return 'done'
|
|
}
|
|
|
|
return 'pending'
|
|
}
|
|
|
|
function receiptSubmitTime(detail: Record<string, unknown>) {
|
|
const status = String(detail.payStatus || '')
|
|
if (status === 'jfqrz') return dash(detail.updateTime)
|
|
if (hasFinanceReceipt(detail) && detail.transferTime) return dash(detail.transferTime)
|
|
return '—'
|
|
}
|
|
|
|
export function buildPaymentFlowSteps(
|
|
detail: Record<string, unknown> | null | undefined,
|
|
activeStepKey?: PaymentFlowStepKey
|
|
): PaymentFlowStep[] {
|
|
const d = detail || {}
|
|
const steps: PaymentFlowStep[] = [
|
|
{
|
|
key: 'receipt-submit',
|
|
title: '缴费确认信息',
|
|
state: resolveStepState('receipt-submit', d, activeStepKey),
|
|
time: receiptSubmitTime(d),
|
|
fields: [
|
|
{ label: '缴费金额(元)', value: formatAmount(d.paymentAmount ?? d.amount) },
|
|
{ label: '备注', value: dash(d.remark), multiline: true },
|
|
{
|
|
label: '转账凭证',
|
|
value: '',
|
|
slot: 'attachments',
|
|
attachmentUrls: String(d.transferAttachments || '')
|
|
}
|
|
]
|
|
},
|
|
{
|
|
key: 'finance-receipt',
|
|
title: '缴费财务确认信息',
|
|
state: resolveStepState('finance-receipt', d, activeStepKey),
|
|
time: dash(d.financeConfirmTime),
|
|
fields: [
|
|
{ label: '财务备注', value: dash(d.financeRemark), multiline: true },
|
|
{
|
|
label: '财务确认附件',
|
|
value: '',
|
|
slot: 'attachments',
|
|
attachmentUrls: String(d.financeConfirmAttachments || '')
|
|
}
|
|
]
|
|
},
|
|
{
|
|
key: 'refund-submit',
|
|
title: '退费确认信息',
|
|
state: resolveStepState('refund-submit', d, activeStepKey),
|
|
time: dash(d.refundApplyTime),
|
|
fields: [
|
|
{ label: '退费金额(元)', value: formatAmount(d.refundAmount) },
|
|
{ label: '退费备注', value: dash(d.refundRemark), multiline: true },
|
|
{
|
|
label: '退费附件',
|
|
value: '',
|
|
slot: 'attachments',
|
|
attachmentUrls: String(d.refundAttachments || '')
|
|
}
|
|
]
|
|
},
|
|
{
|
|
key: 'finance-refund',
|
|
title: '退费财务确认信息',
|
|
state: resolveStepState('finance-refund', d, activeStepKey),
|
|
time: dash(d.refundFinanceConfirmTime),
|
|
fields: [
|
|
{ label: '财务备注', value: dash(d.refundFinanceRemark), multiline: true },
|
|
{
|
|
label: '财务确认附件',
|
|
value: '',
|
|
slot: 'attachments',
|
|
attachmentUrls: String(d.refundFinanceConfirmAttachments || '')
|
|
}
|
|
]
|
|
}
|
|
]
|
|
|
|
return steps
|
|
}
|