xyc
11 小时以前 5b41c8896ef7850be2672e45b69bb58e149729ec
traffic-audit-web/src/views/DataView.vue
@@ -10,6 +10,7 @@
          <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="/ledger-audit">事后核查</el-menu-item>
          <el-submenu index="/special-stats">
            <template slot="title">专项统计</template>
            <el-menu-item index="/holiday-stat">节假日</el-menu-item>
@@ -24,7 +25,9 @@
        <div class="toolbar">
          <template v-if="!isRollup">
            <span class="toolbar-label">报表期</span>
            <el-date-picker v-model="period" type="month" placeholder="报表期(全部)" value-format="yyyy-MM" clearable style="width:150px" @change="doQuery"></el-date-picker>
            <el-date-picker v-model="period" type="month" placeholder="报表期(全部)" value-format="yyyy-MM" clearable
                            style="width:150px" :picker-options="periodPickerOptions" @change="doQuery"></el-date-picker>
            <span v-if="periodHint" class="toolbar-hint">{{ periodHint }}</span>
          </template>
          <span class="toolbar-sep"></span>
          <span class="toolbar-label">数据类型</span>
@@ -34,6 +37,28 @@
              <el-option v-for="t in g.types" :key="t.value" :label="t.label" :value="t.value"></el-option>
            </el-option-group>
          </el-select>
          <template v-if="!isRollup && type === 'trackMileage'">
            <span class="toolbar-label">数据来源</span>
            <el-select v-model="dataSource" size="small" style="width:150px" @change="doQuery">
              <el-option label="全部来源" value=""></el-option>
              <el-option label="省重载平台" value="PROVINCIAL"></el-option>
              <el-option label="市州第三方" value="CITY_THIRD_PARTY"></el-option>
            </el-select>
            <span class="toolbar-label">市州</span>
            <el-select v-model="cityName" size="small" style="width:130px" filterable clearable @change="doQuery">
              <el-option label="全部市州" value=""></el-option>
              <el-option v-for="city in cities" :key="city" :label="city" :value="city"></el-option>
            </el-select>
            <span class="toolbar-label">企业类别</span>
            <el-select v-model="enterpriseCategory" size="small" style="width:140px" @change="doQuery">
              <el-option label="全部" value=""></el-option>
              <el-option label="规上企业" value="ABOVE_SCALE"></el-option>
              <el-option label="两客企业" value="PASSENGER"></el-option>
              <el-option label="未入规企业" value="UNREGISTERED"></el-option>
            </el-select>
            <el-button type="success" size="small" icon="el-icon-download" :loading="exportingCityTrack"
                       @click="exportTrackMileageCity">生成分市州轨迹</el-button>
          </template>
          <template v-if="canRollup">
            <span class="toolbar-label">视图</span>
            <el-radio-group v-model="viewMode" size="small" @change="onViewChange">
@@ -88,6 +113,7 @@
<script>
import AppHeader from '@/components/AppHeader.vue'
import api from '@/api'
import { granularityOfImportType, disabledDateFor, granularityHint, snapPeriod } from '@/utils/periodGranularity'
export default {
  components: { AppHeader },
  name: 'DataView',
@@ -97,6 +123,7 @@
        {
          key: 'freight', name: '道路货运', types: [
            { value: 'h2032', label: '道路货物运输月度生产情况' },
            { value: 'h202', label: '公路货物营运车辆拥有情况(H202)' },
            { value: 'transportAuth', label: '运政车辆' },
            { value: 'trackMileage', label: '轨迹里程' },
            { value: 'scaleSplit', label: '规上规下拆分' },
@@ -137,6 +164,11 @@
      type: 'h2032',
      period: '',
      periodType: '',
      dataSource: '',
      cityName: '',
      enterpriseCategory: '',
      cities: ['武汉市', '黄石市', '十堰市', '宜昌市', '襄阳市', '鄂州市', '荆门市', '孝感市', '荆州市', '黄冈市',
        '咸宁市', '随州市', '恩施州', '仙桃市', '潜江市', '天门市', '神农架林区'],
      viewMode: 'detail',
      rollupTypes: [],
      from: '',
@@ -150,10 +182,17 @@
      records: [],
      columns: [],
      loading: false,
      loadingMore: false
      loadingMore: false,
      exportingCityTrack: false
    }
  },
  computed: {
    periodGranularity() { return granularityOfImportType(this.type) },
    periodPickerOptions() {
      const d = disabledDateFor(this.periodGranularity)
      return d ? { disabledDate: d } : {}
    },
    periodHint() { return granularityHint(this.periodGranularity) },
    canRollup() {
      return (this.rollupTypes || []).some(t => t.type === this.type)
    },
@@ -188,6 +227,17 @@
        count++
      }
      return cols.map((c, i) => Object.assign({}, c, { fixed: i < count }))
    }
  },
  watch: {
    // 选到能耗(季报)时把报表期对齐到季度末月
    periodGranularity() {
      const snapped = snapPeriod(this.period, this.periodGranularity)
      if (snapped && snapped !== this.period) {
        this.period = snapped
        const hint = granularityHint(this.periodGranularity)
        if (hint) this.$message.warning(hint + '(已自动调整为 ' + snapped + ')')
      }
    }
  },
  methods: {
@@ -264,10 +314,35 @@
        this.$message.success('汇总表已导出')
      }).catch(() => this.$message.error('导出失败'))
    },
    exportTrackMileageCity() {
      if (!this.period) { this.$message.warning('请先选择报表期'); return }
      this.exportingCityTrack = true
      api.get('/data/trackMileageCityExport', {
        params: { period: this.period },
        responseType: 'blob',
        timeout: 180000
      }).then(res => {
        const blob = res instanceof Blob ? res : new Blob([res], { type: 'application/zip' })
        const url = window.URL.createObjectURL(blob)
        const a = document.createElement('a')
        const fileName = this.period.replace('-', '年') + '月分市州轨迹.zip'
        a.href = url
        a.download = fileName
        document.body.appendChild(a)
        a.click()
        document.body.removeChild(a)
        window.URL.revokeObjectURL(url)
        this.$message.success('分市州轨迹已生成')
      }).catch(() => this.$message.error('生成分市州轨迹失败'))
        .finally(() => { this.exportingCityTrack = false })
    },
    onTypeSelect() {
      const g = this.modules.find(x => x.types.some(t => t.value === this.type))
      if (g) this.activeModule = g.key
      this.periodType = ''
      this.enterpriseCategory = ''
      this.dataSource = ''
      this.cityName = ''
      this.viewMode = 'detail'
      this.summaryHint = ''
      this.doQuery()
@@ -286,6 +361,9 @@
          period: this.period || undefined,
          keyword: this.keyword || undefined,
          periodType: this.periodType || undefined,
          enterpriseCategory: this.type === 'trackMileage' ? (this.enterpriseCategory || undefined) : undefined,
          dataSource: this.type === 'trackMileage' ? (this.dataSource || undefined) : undefined,
          cityName: this.type === 'trackMileage' ? (this.cityName || undefined) : undefined,
          page: this.page,
          size: this.size
        }
@@ -329,6 +407,9 @@
          period: this.period || undefined,
          keyword: this.keyword || undefined,
          periodType: this.periodType || undefined,
          enterpriseCategory: this.type === 'trackMileage' ? (this.enterpriseCategory || undefined) : undefined,
          dataSource: this.type === 'trackMileage' ? (this.dataSource || undefined) : undefined,
          cityName: this.type === 'trackMileage' ? (this.cityName || undefined) : undefined,
          page: nextPage,
          size: this.size
        }
@@ -385,6 +466,7 @@
    //  - 其余数值千分位、保留两位小数;整数原样。
    formatCell(v, prop) {
      if (v === null || v === undefined || v === '') return '-'
      if (this.type === 'h202' && /Value$/.test(String(prop || ''))) return this.formatExactDecimal(v)
      const s = typeof v === 'string' ? v.trim() : v
      if (typeof v !== 'number' && !/^-?\d+(\.\d+)?$/.test(String(s))) return v
      const n = Number(s)
@@ -394,6 +476,17 @@
      if (/(rate|yoy|mom|growth|ratio|percent|share)/.test(key)) return (n * 100).toFixed(2) + '%'
      if (Number.isInteger(n)) return n.toLocaleString('zh-CN')
      return n.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
    },
    // H202 values arrive as exact decimal strings. Format without Number() to preserve source precision.
    formatExactDecimal(v) {
      const text = String(v === null || v === undefined ? '' : v).trim()
      if (!/^-?\d+(?:\.\d+)?$/.test(text)) return v
      const negative = text.charAt(0) === '-'
      const unsigned = negative ? text.slice(1) : text
      const parts = unsigned.split('.')
      const integer = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',')
      const fraction = (parts[1] || '').replace(/0+$/, '')
      return (negative ? '-' : '') + integer + (fraction ? '.' + fraction : '')
    }
  },
  mounted() {