85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
import { AgentRechargeStatus, type AgentRecharge } from '@/types/api'
|
|
import { hasVoucherKeys } from '@/utils/business'
|
|
|
|
export interface AgentRechargeAction {
|
|
label: string
|
|
handler: () => void
|
|
type: 'primary' | 'danger'
|
|
}
|
|
|
|
interface BuildAgentRechargeActionsOptions {
|
|
hasAuth: (permission: string) => boolean
|
|
onViewPaymentVoucher: (row: AgentRecharge) => void
|
|
onConfirmPayment: (row: AgentRecharge) => void
|
|
onReject: (row: AgentRecharge) => void
|
|
onTriggerApproval: (row: AgentRecharge) => void
|
|
}
|
|
|
|
export const buildAgentRechargeActions = (
|
|
row: AgentRecharge,
|
|
options: BuildAgentRechargeActionsOptions
|
|
): AgentRechargeAction[] => {
|
|
const actions: AgentRechargeAction[] = []
|
|
const hasApprovalRecord =
|
|
row.approval_provider === 'wecom' ||
|
|
row.approval_source === 'wecom' ||
|
|
row.approval_source === 'legacy' ||
|
|
(row.approval_instance_id !== undefined && row.approval_instance_id !== null)
|
|
const approvalStatusEmpty = row.approval_status === undefined || row.approval_status === null
|
|
const canTriggerApproval =
|
|
approvalStatusEmpty &&
|
|
![
|
|
AgentRechargeStatus.COMPLETED,
|
|
AgentRechargeStatus.REJECTED,
|
|
AgentRechargeStatus.CLOSED
|
|
].includes(row.status)
|
|
|
|
if (
|
|
row.payment_method === 'offline' &&
|
|
hasVoucherKeys(row.payment_voucher_key) &&
|
|
options.hasAuth('agent_recharge:view_payment_voucher')
|
|
) {
|
|
actions.push({
|
|
label: '支付凭证',
|
|
handler: () => options.onViewPaymentVoucher(row),
|
|
type: 'primary'
|
|
})
|
|
}
|
|
|
|
if (
|
|
!hasApprovalRecord &&
|
|
row.status === AgentRechargeStatus.PENDING &&
|
|
row.payment_method === 'offline' &&
|
|
options.hasAuth('agent_recharge:confirm_payment')
|
|
) {
|
|
actions.push({
|
|
label: '确认支付',
|
|
handler: () => options.onConfirmPayment(row),
|
|
type: 'primary'
|
|
})
|
|
}
|
|
|
|
if (canTriggerApproval && options.hasAuth('agent_recharge:trigger_approval')) {
|
|
actions.push({
|
|
label: '补发审批',
|
|
handler: () => options.onTriggerApproval(row),
|
|
type: 'primary'
|
|
})
|
|
}
|
|
|
|
if (
|
|
!hasApprovalRecord &&
|
|
row.status === AgentRechargeStatus.PENDING &&
|
|
row.payment_method === 'offline' &&
|
|
options.hasAuth('agent_recharge:reject')
|
|
) {
|
|
actions.push({
|
|
label: '拒绝',
|
|
handler: () => options.onReject(row),
|
|
type: 'danger'
|
|
})
|
|
}
|
|
|
|
return actions
|
|
}
|