kpi-overview.vue 2.71 KB
<template>
  <workbench-card title="经营核心KPI" subtitle="全公司当月概览" icon="el-icon-wallet" tone="blue" :loading="loading">
    <div class="wb-kpi-grid kpi-6">
      <div v-for="item in items" :key="item.key" class="wb-kpi-cell" :class="'wb-kpi-cell--' + item.type">
        <div class="wb-kpi-cell__label">{{ item.label }}</div>
        <div class="wb-kpi-cell__value">{{ item.value }}</div>
      </div>
    </div>
  </workbench-card>
</template>

<script>
import request from '@/utils/request'
import WorkbenchCard from '../workbench-card.vue'
import { formatMoney, getCurrentMonthRange } from '../utils'

export default {
  name: 'WidgetKpiOverview',
  components: { WorkbenchCard },
  data() {
    return { loading: false, kpiData: {} }
  },
  computed: {
    items() {
      const d = this.kpiData || {}
      const tk = d.TkCount || d.tkCount || 0
      return [
        { key: 'billing', label: '营收核心', value: '¥' + formatMoney(d.TotalBillingAmount), type: 'primary' },
        { key: 'consume', label: '服务产出', value: '¥' + formatMoney(d.TotalConsumeAmount), type: 'success' },
        { key: 'net', label: '净收益', value: '¥' + formatMoney(d.CompletedBillingAmount), type: 'warning' },
        { key: 'target', label: '目标完成', value: (d.BillingCompletionRate || 0) + '%', type: 'info' },
        { key: 'tk', label: '新客增长', value: tk, type: 'danger' },
        { key: 'refund', label: '退卡风险', value: '¥' + formatMoney(d.TotalRefundAmount), type: 'danger' }
      ]
    }
  },
  mounted() {
    this.load()
  },
  methods: {
    async load() {
      this.loading = true
      const p = getCurrentMonthRange()
      try {
        const res = await request({
          url: '/api/Extend/LqReport/get-business-statistics',
          method: 'POST',
          data: { startTime: p.startTime, endTime: p.endTime, storeIds: [] }
        })
        const data = res.data || {}
        this.kpiData = {
          TotalBillingAmount: data.TotalBillingAmount || data.billing_amount || 0,
          TotalConsumeAmount: data.TotalConsumeAmount || data.consume_amount || 0,
          TotalRefundAmount: data.TotalRefundAmount || data.refund_amount || 0,
          CompletedBillingAmount: (data.TotalBillingAmount || 0) - (data.TotalRefundAmount || 0),
          BillingCompletionRate: data.BillingCompletionRate || 0,
          TkCount: data.TkCount || data.NewCustomerCount || 0
        }
      } catch (e) {
        this.kpiData = {}
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../widget-common.scss';
.kpi-6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 1400px) {
  .kpi-6 { grid-template-columns: repeat(3, 1fr); }
}
</style>