Files
hzdyjs/web/src/views/cw/dashboard/index.vue
T
2025-07-30 23:24:43 +08:00

701 lines
19 KiB
Vue

<template>
<div class="p-2 page-container">
<!-- 快捷功能按钮 -->
<el-row :gutter="10" class="mb-[10px]">
<el-col :span="6">
<el-card shadow="hover" class="quick-action-card">
<div class="quick-action" @click="handleAdd">
<el-icon class="quick-icon"><Plus /></el-icon>
<span>新增申报</span>
</div>
</el-card>
</el-col>
<el-col :span="6">
<el-card shadow="hover" class="quick-action-card">
<div class="quick-action" @click="showMyApplications">
<el-icon class="quick-icon"><User /></el-icon>
<span>我的申报</span>
</div>
</el-card>
</el-col>
<el-col :span="6">
<el-card shadow="hover" class="quick-action-card">
<div class="quick-action" @click="showPendingApplications">
<el-icon class="quick-icon"><Clock /></el-icon>
<span>待审批</span>
</div>
</el-card>
</el-col>
<el-col :span="6">
<el-card shadow="hover" class="quick-action-card">
<div class="quick-action" @click="showStatistics">
<el-icon class="quick-icon"><DataAnalysis /></el-icon>
<span>统计分析</span>
</div>
</el-card>
</el-col>
</el-row>
<!-- 统计卡片区域 -->
<div class="mb-[10px]">
<el-row :gutter="16">
<el-col :span="3">
<el-card shadow="hover" class="stat-card stat-card-primary">
<div class="stat-content">
<div class="stat-icon">
<el-icon><Files /></el-icon>
</div>
<div class="stat-info">
<div class="stat-value">{{ statistics.totalCount }}</div>
<div class="stat-label">申报总数</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="3">
<el-card shadow="hover" class="stat-card stat-card-warning">
<div class="stat-content">
<div class="stat-icon">
<el-icon><Clock /></el-icon>
</div>
<div class="stat-info">
<div class="stat-value">{{ statistics.approvingCount }}</div>
<div class="stat-label">审批中</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="3">
<el-card shadow="hover" class="stat-card stat-card-success">
<div class="stat-content">
<div class="stat-icon">
<el-icon><CircleCheck /></el-icon>
</div>
<div class="stat-info">
<div class="stat-value">{{ statistics.approvedCount }}</div>
<div class="stat-label">已通过</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="3">
<el-card shadow="hover" class="stat-card stat-card-danger">
<div class="stat-content">
<div class="stat-icon">
<el-icon><CircleClose /></el-icon>
</div>
<div class="stat-info">
<div class="stat-value">{{ statistics.rejectedCount }}</div>
<div class="stat-label">已拒绝</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="3">
<el-card shadow="hover" class="stat-card stat-card-info">
<div class="stat-content">
<div class="stat-icon">
<el-icon><Money /></el-icon>
</div>
<div class="stat-info">
<div class="stat-value">{{ formatAmount(statistics.totalAmount) }}</div>
<div class="stat-label">总金额(万元)</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="3">
<el-card shadow="hover" class="stat-card stat-card-info">
<div class="stat-content">
<div class="stat-icon">
<el-icon><Timer /></el-icon>
</div>
<div class="stat-info">
<div class="stat-value">{{ statistics.avgProcessDays || 0 }}</div>
<div class="stat-label">平均周期(天)</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="3">
<el-card shadow="hover" class="stat-card stat-card-success">
<div class="stat-content">
<div class="stat-icon">
<el-icon><TrendCharts /></el-icon>
</div>
<div class="stat-info">
<div class="stat-value">{{ statistics.monthlyNew || 0 }}</div>
<div class="stat-label">本月新增</div>
</div>
</div>
</el-card>
</el-col>
<el-col :span="3">
<el-card shadow="hover" class="stat-card stat-card-warning">
<div class="stat-content">
<div class="stat-icon">
<el-icon><Finished /></el-icon>
</div>
<div class="stat-info">
<div class="stat-value">{{ statistics.monthlyApproved || 0 }}</div>
<div class="stat-label">本月通过</div>
</div>
</div>
</el-card>
</el-col>
</el-row>
</div>
<!-- 图表区域 -->
<el-row :gutter="16" class="mb-[10px]">
<!-- 月度趋势图表 -->
<el-col :xl="16" :lg="16" :md="24" :sm="24" :xs="24">
<el-card shadow="never" class="chart-card">
<template #header>
<div class="card-header">
<span>月度申报趋势</span>
<el-select v-model="selectedYear" @change="handleYearChange" style="width: 120px;">
<el-option
v-for="year in yearOptions"
:key="year"
:label="year + '年'"
:value="year"
/>
</el-select>
</div>
</template>
<div ref="trendChart" style="height: 350px;"></div>
</el-card>
</el-col>
<!-- 状态分布图表 -->
<el-col :xl="8" :lg="8" :md="24" :sm="24" :xs="24">
<el-card shadow="never" class="chart-card">
<template #header>
<span>状态分布</span>
</template>
<div ref="statusChart" style="height: 350px;"></div>
</el-card>
</el-col>
</el-row>
<!-- 部门统计表格 -->
<el-card shadow="never" class="table-card">
<template #header>
<div class="card-header">
<span>部门统计详情</span>
<el-button type="primary" icon="Download" @click="handleExportDeptStatistics">导出部门统计</el-button>
</div>
</template>
<el-table
:data="statistics.deptStatistics"
border
style="width: 100%"
v-loading="statisticsLoading"
>
<el-table-column prop="deptName" label="部门名称" align="center" min-width="120" show-overflow-tooltip />
<el-table-column prop="totalCount" label="申报数量" align="center" width="100" />
<el-table-column prop="approvingCount" label="审批中" align="center" width="100">
<template #default="scope">
<el-tag type="warning" size="small">{{ scope.row.approvingCount || 0 }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="approvedCount" label="已通过" align="center" width="100">
<template #default="scope">
<el-tag type="success" size="small">{{ scope.row.approvedCount || 0 }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="rejectedCount" label="已拒绝" align="center" width="100">
<template #default="scope">
<el-tag type="danger" size="small">{{ scope.row.rejectedCount || 0 }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="totalAmount" label="总金额(万元)" align="center" width="120">
<template #default="scope">
<span class="amount-text">{{ formatAmount(scope.row.totalAmount) }}</span>
</template>
</el-table-column>
<el-table-column prop="approvedAmount" label="已批金额(万元)" align="center" width="130">
<template #default="scope">
<span class="amount-text success">{{ formatAmount(scope.row.approvedAmount) }}</span>
</template>
</el-table-column>
<el-table-column label="审批率" align="center" width="100">
<template #default="scope">
<el-progress
:percentage="calculateApprovalRate(scope.row)"
:status="getProgressStatus(scope.row)"
:show-text="false"
/>
<span class="rate-text">{{ calculateApprovalRate(scope.row) }}%</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="120" fixed="right">
<template #default="scope">
<el-tooltip content="查看部门详情" placement="top">
<el-button link type="primary" icon="View" @click="viewDepartmentDetail(scope.row)"></el-button>
</el-tooltip>
<el-tooltip content="导出部门数据" placement="top">
<el-button link type="info" icon="Download" @click="exportDepartmentData(scope.row)"></el-button>
</el-tooltip>
</template>
</el-table-column>
</el-table>
</el-card>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, nextTick } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
Plus, User, Clock, DataAnalysis, Files, CircleCheck, CircleClose,
Money, Timer, TrendCharts, Finished
} from '@element-plus/icons-vue'
import * as echarts from 'echarts'
import { getApplicationStatistics, getStatisticsByDept, getStatisticsByMonth } from '@/api/cw/projectApplication'
import { parseTime } from '@/utils/ruoyi'
const router = useRouter()
// 响应式数据
const statistics = reactive({
totalCount: 0,
approvingCount: 0,
approvedCount: 0,
rejectedCount: 0,
totalAmount: 0,
avgProcessDays: 0,
monthlyNew: 0,
monthlyApproved: 0,
deptStatistics: [] as any[]
})
const selectedYear = ref(new Date().getFullYear())
const yearOptions = ref<number[]>([])
const statisticsLoading = ref(false)
// 图表引用
const trendChart = ref()
const statusChart = ref()
let trendChartInstance: echarts.ECharts | null = null
let statusChartInstance: echarts.ECharts | null = null
// 生成年份选项
const generateYearOptions = () => {
const currentYear = new Date().getFullYear()
for (let i = currentYear - 4; i <= currentYear + 1; i++) {
yearOptions.value.push(i)
}
}
// 快捷操作
const handleAdd = () => {
router.push('/cw/application')
}
const showMyApplications = () => {
router.push({ path: '/cw/application', query: { tab: 'my' } })
}
const showPendingApplications = () => {
router.push({ path: '/cw/application', query: { tab: 'pending' } })
}
const showStatistics = () => {
router.push('/cw/application/summary')
}
// 格式化金额
const formatAmount = (amount: number | undefined): string => {
if (!amount) return '0.00'
return amount.toFixed(2)
}
// 计算审批率
const calculateApprovalRate = (row: any): number => {
if (!row.totalCount || row.totalCount === 0) return 0
return Math.round((row.approvedCount / row.totalCount) * 100)
}
// 获取进度条状态
const getProgressStatus = (row: any): string => {
const rate = calculateApprovalRate(row)
if (rate >= 80) return 'success'
if (rate >= 60) return 'warning'
return 'exception'
}
// 查看部门详情
const viewDepartmentDetail = (row: any) => {
router.push({
path: '/cw/application',
query: { deptId: row.deptId, deptName: row.deptName }
})
}
// 导出部门数据
const exportDepartmentData = (row: any) => {
ElMessage.success(`导出部门【${row.deptName}】数据功能开发中...`)
}
// 导出部门统计
const handleExportDeptStatistics = () => {
ElMessage.success('导出部门统计功能开发中...')
}
// 获取统计数据
const loadStatistics = async () => {
try {
statisticsLoading.value = true
const [statsRes, deptRes] = await Promise.all([
getApplicationStatistics(selectedYear.value),
getStatisticsByDept()
])
if (statsRes.code === 200) {
Object.assign(statistics, statsRes.data)
}
if (deptRes.code === 200) {
statistics.deptStatistics = deptRes.data || []
}
} catch (error) {
console.error('获取统计数据失败:', error)
ElMessage.error('获取统计数据失败')
} finally {
statisticsLoading.value = false
}
}
// 年份变化处理
const handleYearChange = () => {
loadStatistics()
loadTrendChart()
}
// 加载趋势图表
const loadTrendChart = async () => {
try {
const response = await getStatisticsByMonth(selectedYear.value)
if (response.code === 200) {
renderTrendChart(response.data)
}
} catch (error) {
console.error('获取月度统计失败:', error)
}
}
// 渲染趋势图表
const renderTrendChart = (data: any[]) => {
if (!trendChartInstance) return
const months = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
const applicationCounts = new Array(12).fill(0)
const approvedCounts = new Array(12).fill(0)
data.forEach(item => {
const monthIndex = item.month - 1
if (monthIndex >= 0 && monthIndex < 12) {
applicationCounts[monthIndex] = item.applicationCount || 0
approvedCounts[monthIndex] = item.approvedCount || 0
}
})
const option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
}
},
legend: {
data: ['申报数量', '通过数量']
},
xAxis: {
type: 'category',
data: months
},
yAxis: {
type: 'value'
},
series: [
{
name: '申报数量',
type: 'line',
data: applicationCounts,
smooth: true,
itemStyle: { color: '#409EFF' }
},
{
name: '通过数量',
type: 'line',
data: approvedCounts,
smooth: true,
itemStyle: { color: '#67C23A' }
}
]
}
trendChartInstance.setOption(option)
}
// 渲染状态分布图
const renderStatusChart = () => {
if (!statusChartInstance) return
const option = {
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b}: {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 'left'
},
series: [
{
name: '申报状态',
type: 'pie',
radius: ['40%', '70%'],
data: [
{ value: statistics.approvingCount, name: '审批中', itemStyle: { color: '#E6A23C' } },
{ value: statistics.approvedCount, name: '已通过', itemStyle: { color: '#67C23A' } },
{ value: statistics.rejectedCount, name: '已拒绝', itemStyle: { color: '#F56C6C' } }
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
}
statusChartInstance.setOption(option)
}
// 初始化图表
const initCharts = async () => {
await nextTick()
if (trendChart.value) {
trendChartInstance = echarts.init(trendChart.value)
loadTrendChart()
}
if (statusChart.value) {
statusChartInstance = echarts.init(statusChart.value)
renderStatusChart()
}
// 监听窗口大小变化
window.addEventListener('resize', () => {
trendChartInstance?.resize()
statusChartInstance?.resize()
})
}
// 组件挂载
onMounted(() => {
generateYearOptions()
loadStatistics()
initCharts()
})
</script>
<style lang="scss" scoped>
.page-container {
min-height: calc(100vh - 84px);
}
// 快捷操作卡片
.quick-action-card {
cursor: pointer;
transition: all 0.3s ease;
border: 1px solid #e4e7ed;
&:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
border-color: #409EFF;
}
.quick-action {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
.quick-icon {
font-size: 28px;
color: #409EFF;
margin-bottom: 8px;
}
span {
font-size: 14px;
color: #606266;
font-weight: 500;
}
}
}
// 统计卡片
.stat-card {
border: none;
border-radius: 8px;
overflow: hidden;
&.stat-card-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
&.stat-card-success {
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
color: white;
}
&.stat-card-warning {
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
color: white;
}
&.stat-card-danger {
background: linear-gradient(135deg, #ff6b6b 0%, #ffa726 100%);
color: white;
}
&.stat-card-info {
background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
color: #2c3e50;
}
:deep(.el-card__body) {
padding: 0;
}
}
.stat-content {
display: flex;
align-items: center;
padding: 20px;
.stat-icon {
font-size: 32px;
margin-right: 16px;
opacity: 0.8;
}
.stat-info {
.stat-value {
font-size: 24px;
font-weight: bold;
line-height: 1.2;
margin-bottom: 4px;
}
.stat-label {
font-size: 12px;
opacity: 0.9;
line-height: 1;
}
}
}
// 图表卡片
.chart-card {
border-radius: 8px;
border: 1px solid #e4e7ed;
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 600;
color: #2c3e50;
}
}
// 表格卡片
.table-card {
border-radius: 8px;
border: 1px solid #e4e7ed;
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
font-weight: 600;
color: #2c3e50;
}
.amount-text {
font-weight: 600;
color: #606266;
&.success {
color: #67C23A;
}
}
.rate-text {
font-size: 12px;
margin-left: 8px;
color: #909399;
}
}
// 动画效果
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.quick-action-card,
.stat-card,
.chart-card,
.table-card {
animation: fadeInUp 0.6s ease forwards;
}
// 响应式设计
@media (max-width: 768px) {
.quick-action {
padding: 15px;
.quick-icon {
font-size: 24px;
}
span {
font-size: 12px;
}
}
.stat-content {
padding: 15px;
.stat-icon {
font-size: 24px;
margin-right: 12px;
}
.stat-info .stat-value {
font-size: 20px;
}
}
}
</style>