2026-05-20 21:00:47 +08:00
|
|
|
import { mapExpenseClaimToRequest } from '../composables/useRequests.js'
|
2026-05-21 09:28:33 +08:00
|
|
|
import {
|
2026-05-27 17:31:27 +08:00
|
|
|
canApproveBudgetExpenseApplications,
|
2026-05-21 09:28:33 +08:00
|
|
|
canApproveLeaderExpenseClaims,
|
2026-05-27 14:35:17 +08:00
|
|
|
isCurrentDirectManagerForRequest,
|
|
|
|
|
isCurrentRequestApplicant,
|
2026-05-21 09:28:33 +08:00
|
|
|
isFinanceUser
|
|
|
|
|
} from './accessControl.js'
|
2026-05-20 21:00:47 +08:00
|
|
|
|
|
|
|
|
export function canProcessApprovalRequest(request, currentUser) {
|
|
|
|
|
const node = String(request?.workflowNode || '').trim()
|
|
|
|
|
|
2026-05-27 14:35:17 +08:00
|
|
|
if (isCurrentRequestApplicant(request, currentUser)) {
|
2026-05-20 21:00:47 +08:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-21 09:28:33 +08:00
|
|
|
if (isFinanceUser(currentUser) && node.includes('财务')) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-27 17:31:27 +08:00
|
|
|
if (node.includes('预算')) {
|
|
|
|
|
return canApproveBudgetExpenseApplications(currentUser, request)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-21 09:28:33 +08:00
|
|
|
const isLeaderApprovalNode = (
|
2026-05-20 21:00:47 +08:00
|
|
|
node.includes('直属领导')
|
|
|
|
|
|| node.includes('领导审批')
|
|
|
|
|
|| node.includes('部门负责人')
|
|
|
|
|
|| node.includes('负责人审批')
|
|
|
|
|
)
|
2026-05-21 09:28:33 +08:00
|
|
|
|
2026-05-27 14:35:17 +08:00
|
|
|
return (
|
|
|
|
|
canApproveLeaderExpenseClaims(currentUser)
|
|
|
|
|
&& isLeaderApprovalNode
|
|
|
|
|
&& isCurrentDirectManagerForRequest(request, currentUser)
|
|
|
|
|
)
|
2026-05-20 21:00:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function listPendingApprovalRequests(claimsPayload, currentUser) {
|
|
|
|
|
if (!Array.isArray(claimsPayload)) {
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return claimsPayload
|
|
|
|
|
.map((item) => mapExpenseClaimToRequest(item))
|
|
|
|
|
.filter((item) => item.approvalKey === 'in_progress')
|
|
|
|
|
.filter((item) => canProcessApprovalRequest(item, currentUser))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function resolvePendingClaimIds(claimsPayload, currentUser) {
|
|
|
|
|
return listPendingApprovalRequests(claimsPayload, currentUser)
|
|
|
|
|
.map((item) => String(item.claimId || '').trim())
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
}
|