zzw
1 天以前 781b8b3e072a4e00b1cee56f961280c753cbb460
emergency-repair-web/src/views/report/ReportPage.vue
@@ -11,7 +11,7 @@
    <div v-if="type === 'overview'" class="stat-grid">
      <div class="stat-card"><div class="label">工程总数</div><div class="value">{{ stats.engineeringTotal || 0 }}</div></div>
      <div class="stat-card"><div class="label">重大故障</div><div class="value">{{ stats.majorFault || 0 }}</div></div>
      <div class="stat-card"><div class="label">涉H统计</div><div class="value">{{ stats.hRelated || 0 }}</div></div>
      <div class="stat-card"><div class="label">涉rk_H统计</div><div class="value">{{ stats.hRelated || 0 }}</div></div>
      <div class="stat-card"><div class="label">监测项目</div><div class="value">{{ stats.monitorItem || 0 }}</div></div>
      <div class="stat-card"><div class="label">未完工</div><div class="value">{{ stats.unfinished || 0 }}</div></div>
      <div class="stat-card"><div class="label">已完工</div><div class="value">{{ stats.completed || 0 }}</div></div>
@@ -42,14 +42,14 @@
    type: { type: String, required: true }
  },
  data() {
    return { stats: {}, rows: [], chart: null }
    return { stats: {}, rows: [], chart: null, loadSeq: 0 }
  },
  computed: {
    title() {
      return {
        overview: '装备故障总体分析',
        overview: '设备故障总体分析',
        'top-equipment': '故障高发设备Top',
        'by-team': '按T统计',
        'by-team': 'rk_按T统计',
        contractors: '厂家维修情况',
        trend: '故障数 / 备品备件消耗年度趋势'
      }[this.type] || '统计报表'
@@ -76,7 +76,7 @@
        { prop: 'value', label: '故障数', width: 100 }
      ]
      if (this.type === 'by-team') return [
        { prop: 'name', label: 'T队专业', width: 150 },
        { prop: 'name', label: 'rk_T队专业', width: 150 },
        { prop: 'faultCount', label: '故障数' },
        { prop: 'partsCount', label: '备品备件消耗' }
      ]
@@ -107,14 +107,25 @@
  },
  methods: {
    load() {
      const requests = {
        overview: api.get('/reports/overview').then(res => { this.stats = res.data || {}; this.rows = this.stats.chart || [] }),
        'top-equipment': api.get('/reports/top-equipment').then(res => { this.rows = res.data || []; this.stats = {} }),
        'by-team': api.get('/reports/by-team').then(res => { this.rows = res.data || []; this.stats = {} }),
        contractors: api.get('/reports/contractors').then(res => { this.rows = res.data || []; this.stats = {} }),
        trend: api.get('/reports/yearly-trend').then(res => { this.rows = res.data || []; this.stats = {} })
      const loaders = {
        overview: () => api.get('/reports/overview').then(res => ({
          stats: res.data || {},
          rows: (res.data && res.data.chart) || []
        })),
        'top-equipment': () => api.get('/reports/top-equipment').then(res => ({ stats: {}, rows: res.data || [] })),
        'by-team': () => api.get('/reports/by-team').then(res => ({ stats: {}, rows: res.data || [] })),
        contractors: () => api.get('/reports/contractors').then(res => ({ stats: {}, rows: res.data || [] })),
        trend: () => api.get('/reports/yearly-trend').then(res => ({ stats: {}, rows: res.data || [] }))
      }
      ;(requests[this.type] || Promise.resolve()).then(() => this.$nextTick(this.renderChart))
      const seq = ++this.loadSeq
      const loader = loaders[this.type]
      const request = loader ? loader() : Promise.resolve({ stats: {}, rows: [] })
      request.then(result => {
        if (seq !== this.loadSeq) return
        this.stats = result.stats
        this.rows = result.rows
        this.$nextTick(this.renderChart)
      }).catch(() => {})
    },
    renderChart() {
      if (!this.$refs.chart) return