83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
export type MpContractMode = 'manage' | 'approve'
|
|
export type MpContractManageView = 'all' | 'approving' | 'approved'
|
|
export type MpContractApproveView = 'submitted' | 'approved'
|
|
export type MpContractView = MpContractManageView | MpContractApproveView
|
|
|
|
export const MP_CONTRACT_MANAGE_TABS: Array<{ value: MpContractManageView; label: string }> = [
|
|
{ value: 'all', label: '全部' },
|
|
{ value: 'approving', label: '待审批' },
|
|
{ value: 'approved', label: '已审批' }
|
|
]
|
|
|
|
export const MP_CONTRACT_APPROVE_TABS: Array<{ value: MpContractApproveView; label: string }> = [
|
|
{ value: 'submitted', label: '待审批' },
|
|
{ value: 'approved', label: '已审批' }
|
|
]
|
|
|
|
export function formatContractMoney(amount?: number | null): string {
|
|
if (amount === undefined || amount === null || Number.isNaN(Number(amount))) return '—'
|
|
return `¥${Number(amount).toLocaleString('zh-CN', {
|
|
minimumFractionDigits: 2,
|
|
maximumFractionDigits: 2
|
|
})}`
|
|
}
|
|
|
|
export function buildContractListQuery(input: {
|
|
mode: MpContractMode
|
|
view: MpContractView
|
|
pageNum: number
|
|
pageSize: number
|
|
keyword: string
|
|
currentUserId: string
|
|
}): Record<string, unknown> {
|
|
const params: Record<string, unknown> = {
|
|
pageNum: input.pageNum,
|
|
pageSize: input.pageSize
|
|
}
|
|
const kw = String(input.keyword || '').trim()
|
|
if (kw) params.keyword = kw
|
|
|
|
if (input.mode === 'manage') {
|
|
if (input.view === 'all') params.excludeStatus = 'invalid'
|
|
else if (input.view === 'approving') params.status = 'approving'
|
|
else params.status = 'approved'
|
|
return params
|
|
}
|
|
|
|
if (input.view === 'submitted') {
|
|
params.pendingApprovalUserId = input.currentUserId
|
|
} else {
|
|
params.approvedByUserId = input.currentUserId
|
|
}
|
|
return params
|
|
}
|
|
|
|
export function buildContractCard(row: {
|
|
id: string | number
|
|
contractNo?: string
|
|
/** 桌面/API 字段 */
|
|
contractName?: string
|
|
/** 兼容旧测试/别名 */
|
|
contractTitle?: string
|
|
customerName?: string
|
|
amount?: number
|
|
freight?: number
|
|
barrelDeposit?: number
|
|
status?: string
|
|
signDate?: string
|
|
canApprove?: boolean
|
|
}) {
|
|
const total =
|
|
(Number(row.amount) || 0) + (Number(row.freight) || 0) + (Number(row.barrelDeposit) || 0)
|
|
return {
|
|
id: String(row.id),
|
|
contractNo: row.contractNo || '—',
|
|
contractTitle: row.contractName || row.contractTitle || '—',
|
|
customerName: row.customerName || '—',
|
|
amountText: formatContractMoney(total),
|
|
status: row.status || '',
|
|
signDate: row.signDate || '—',
|
|
canApprove: !!row.canApprove
|
|
}
|
|
}
|