Reuse /advances APIs with bx envelope and Fresh Mint list/form styling. Co-authored-by: Cursor <cursoragent@cursor.com>
88 lines
2.3 KiB
JavaScript
88 lines
2.3 KiB
JavaScript
/** 对齐 bx-mobile/src/utils/format.ts(Batch2 所需子集) */
|
||
|
||
export function statusLabel(status) {
|
||
if (status == null || status === '') return '-'
|
||
const map = {
|
||
1: '启用',
|
||
0: '禁用',
|
||
draft: '待提交',
|
||
pending: '审批中',
|
||
approved: '已通过',
|
||
rejected: '已驳回',
|
||
withdrawn: '已撤回',
|
||
issued: '已发放',
|
||
paid: '已支付',
|
||
offset: '已冲抵',
|
||
partial: '部分冲抵',
|
||
processed: '已处理'
|
||
}
|
||
return map[status] ?? String(status)
|
||
}
|
||
|
||
export function statusTone(status) {
|
||
if (status == null) return 'info'
|
||
const map = {
|
||
1: 'done',
|
||
0: 'error',
|
||
draft: 'info',
|
||
pending: 'warn',
|
||
approved: 'done',
|
||
rejected: 'error',
|
||
withdrawn: 'warn',
|
||
issued: 'done',
|
||
paid: 'done',
|
||
offset: 'done',
|
||
partial: 'warn',
|
||
processed: 'done'
|
||
}
|
||
return map[status] ?? 'info'
|
||
}
|
||
|
||
export function workflowListStatusTagClass(status) {
|
||
const raw = status == null || status === '' ? 'draft' : String(status)
|
||
return `s-${raw}`
|
||
}
|
||
|
||
export function ticketHeaderStatusToneClass(status) {
|
||
const tone = statusTone(status)
|
||
const map = {
|
||
info: 'advance-ticket-status--info',
|
||
warn: 'advance-ticket-status--warn',
|
||
done: 'advance-ticket-status--done',
|
||
error: 'advance-ticket-status--err',
|
||
processing: 'advance-ticket-status--processing'
|
||
}
|
||
return map[tone] || 'advance-ticket-status--info'
|
||
}
|
||
|
||
export function formatAmount(amount) {
|
||
const n = typeof amount === 'string' ? parseFloat(amount) : amount
|
||
if (Number.isNaN(n)) return '0.00'
|
||
return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||
}
|
||
|
||
export function formatDate(dateStr) {
|
||
if (!dateStr) return '-'
|
||
return String(dateStr).substring(0, 10)
|
||
}
|
||
|
||
export function formatDateTime(dateStr) {
|
||
if (!dateStr) return '-'
|
||
return String(dateStr).substring(0, 16).replace('T', ' ')
|
||
}
|
||
|
||
export function pickApplyTime(row) {
|
||
if (!row || typeof row !== 'object') return undefined
|
||
const v = row.applyTime ?? row.createTime ?? row.apply_time ?? row.create_time
|
||
if (v == null || v === '') return undefined
|
||
return String(v)
|
||
}
|
||
|
||
export function formatApplyDateTime(row) {
|
||
return formatDateTime(pickApplyTime(row))
|
||
}
|
||
|
||
export function formatApplyDate(row) {
|
||
return formatDate(pickApplyTime(row))
|
||
}
|