xyc
2026-08-14 1f4a6cc6045f47861c3e8d49a782afc3e11e3843
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<template>
  <el-container>
    <el-header>交通统计报表审核系统 - 报表生成</el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu router default-active="/report">
          <el-menu-item index="/dashboard">工作台</el-menu-item>
          <el-menu-item index="/import">数据导入</el-menu-item>
          <el-menu-item index="/data">数据查看</el-menu-item>
          <el-menu-item index="/explain">企业解释</el-menu-item>
          <el-menu-item index="/audit">审核结果</el-menu-item>
          <el-menu-item index="/report">报表生成</el-menu-item>
          <el-menu-item index="/rules">规则管理</el-menu-item>
          <el-menu-item index="/users">用户管理</el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <div class="page-scroll">
        <h3>生成统计报表</h3>
        <el-card style="max-width:640px">
          <el-form label-width="100px">
            <el-form-item label="报表期">
              <el-date-picker v-model="period" type="month" placeholder="选择月份" value-format="yyyy-MM" style="width:100%"></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="exportReport('cityDetail')" :loading="loading === 'cityDetail'">生成_货运量分市州明细</el-button>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="exportReport('freightRank')" :loading="loading === 'freightRank'">生成_货运量排名</el-button>
              <el-button type="primary" @click="exportReport('turnoverRank')" :loading="loading === 'turnoverRank'">生成_周转量排名</el-button>
            </el-form-item>
          </el-form>
        </el-card>
        <el-alert
          title="提示:报表由系统根据已导入数据自动计算生成。货运量:合计来自模板_货运量周转量(左半1-N月)、规上来自H203-2月报、规下=合计-规上;周转量来自规上规下拆分表。"
          type="info" style="margin-top:15px" :closable="false"></el-alert>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import api from '@/api'
export default {
  name: 'ReportExport',
  data() {
    return { period: '', loading: '' }
  },
  methods: {
    exportReport(type) {
      if (!this.period) { this.$message.warning('请选择报表期'); return }
      this.loading = type
      const token = localStorage.getItem('token') || ''
      api.get('/report/export/' + type, { params: { period: this.period }, responseType: 'blob' })
        .then(res => {
          const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
          const url = window.URL.createObjectURL(blob)
          const a = document.createElement('a')
          a.href = url
          a.download = this.fileName(type)
          document.body.appendChild(a)
          a.click()
          window.URL.revokeObjectURL(url)
          this.$message.success('报表生成成功')
        })
        .catch(() => { this.$message.error('报表生成失败,请确认已导入对应数据') })
        .finally(() => { this.loading = '' })
    },
    fileName(type) {
      const map = {
        cityDetail: '生成_货运量分市州明细.xlsx',
        freightRank: '生成_货运量排名.xlsx',
        turnoverRank: '生成_周转量排名.xlsx'
      }
      return map[type] || 'report.xlsx'
    }
  }
}
</script>
<style scoped>
.el-header { background: #409EFF; color: white; line-height: 60px; font-size: 18px; }
</style>