store-kpi.vue 2.78 KB
<template>
  <workbench-card title="本店核心指标" subtitle="当前门店当月" icon="el-icon-office-building" tone="cyan" :loading="loading">
    <div v-if="!storeId" class="wb-empty">
      <div class="wb-empty__circle" style="background:#ecfeff;color:#06b6d4">
        <i class="el-icon-office-building" />
      </div>
      <div class="wb-empty__title">未绑定门店</div>
      <div class="wb-empty__desc">当前账号未绑定门店,无法展示本店指标</div>
    </div>
    <div v-else class="wb-kpi-grid kpi-4">
      <div class="wb-kpi-cell wb-kpi-cell--primary">
        <div class="wb-kpi-cell__label">开单业绩</div>
        <div class="wb-kpi-cell__value">¥{{ formatMoney(perf.BillingPerformance) }}</div>
      </div>
      <div class="wb-kpi-cell wb-kpi-cell--success">
        <div class="wb-kpi-cell__label">消耗业绩</div>
        <div class="wb-kpi-cell__value">¥{{ formatMoney(perf.ConsumePerformance) }}</div>
      </div>
      <div class="wb-kpi-cell wb-kpi-cell--warning">
        <div class="wb-kpi-cell__label">完成率</div>
        <div class="wb-kpi-cell__value">{{ rateText }}%</div>
      </div>
      <div class="wb-kpi-cell wb-kpi-cell--info">
        <div class="wb-kpi-cell__label">净业绩</div>
        <div class="wb-kpi-cell__value">¥{{ formatMoney(perf.NetPerformance) }}</div>
      </div>
    </div>
  </workbench-card>
</template>

<script>
import { mapGetters } from 'vuex'
import { getStoreDashboardStatistics } from '@/api/report'
import WorkbenchCard from '../workbench-card.vue'
import { formatMoney } from '../utils'

export default {
  name: 'WidgetStoreKpi',
  components: { WorkbenchCard },
  data() {
    return { loading: false, perf: {} }
  },
  computed: {
    ...mapGetters(['userInfo']),
    storeId() {
      return (this.userInfo && (this.userInfo.mdid || this.userInfo.organizeId)) || ''
    },
    month() {
      const d = new Date()
      return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`
    },
    rateText() {
      return Number(this.perf.CompletionRate || 0).toFixed(2)
    }
  },
  mounted() {
    this.load()
  },
  methods: {
    formatMoney,
    async load() {
      if (!this.storeId) return
      this.loading = true
      try {
        const res = await getStoreDashboardStatistics({
          storeId: this.storeId,
          month: this.month
        })
        const data = (res.data && res.data.Data) || res.data || {}
        this.perf = (data.Performance || data.performance || data) || {}
      } catch (e) {
        this.perf = {}
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

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