import request from './request' // 报表统计API export interface DashboardStats { unpaidReceivable: number pendingExpense: number todayIncome: number todayExpense: number pendingApprovalCount: number overdueReceivableCount: number } export interface TrendItem { date: string income: number expense: number } export interface DistributionItem { name: string count: number value: number | string } // 项目收支分析DTO export interface ProjectFinance { projectId: number projectCode: string projectName: string customerName: string status: string receivableAmount: number receivedAmount: number unreceivedAmount: number receiveRate: number expenseAmount: number profit: number profitRate: number } // 获取仪表盘统计数据 export function getDashboardStats() { return request.get('/report/dashboard/stats') } // 获取收支趋势 export function getTrend(period: 'week' | 'month' | 'quarter' = 'week') { return request.get('/report/trend', { params: { period } }) } // 获取项目状态分布 export function getProjectStatusDistribution() { return request.get('/report/project/status-distribution') } // 获取支出类型分布 export function getExpenseTypeDistribution() { return request.get('/report/expense/type-distribution') } // 获取项目收支分析 export function getProjectFinance(params?: { status?: string; customerId?: number }) { return request.get('/report/project/finance', { params }) } // 导出项目收支分析Excel export function exportProjectFinance(params?: { status?: string; customerId?: number }) { const baseUrl = import.meta.env.VITE_API_URL || '' const token = localStorage.getItem('token') const tenantId = localStorage.getItem('tenantId') || '1' // 构建查询参数 const queryParams = new URLSearchParams() if (params?.status) queryParams.append('status', params.status) if (params?.customerId) queryParams.append('customerId', String(params.customerId)) const queryString = queryParams.toString() const url = `${baseUrl}/report/project/finance/export${queryString ? '?' + queryString : ''}` // 使用fetch下载 return fetch(url, { headers: { Authorization: `Bearer ${token}`, 'X-Tenant-Id': tenantId } }).then(response => { if (!response.ok) throw new Error('导出失败') // 获取文件名 const contentDisposition = response.headers.get('Content-Disposition') let filename = '项目收支分析报表.xlsx' if (contentDisposition) { const match = contentDisposition.match(/filename\*=utf-8''(.+)/i) if (match && match[1]) { filename = decodeURIComponent(match[1]) } } return response.blob().then(blob => ({ blob, filename })) }) }