tk-overview.vue 2.95 KB
<template>
  <workbench-card title="拓客活动概览" subtitle="当月拓客转化" icon="el-icon-s-custom" tone="green" :loading="loading">
    <template #extra>
      <el-button type="text" size="mini" @click="goMore">更多</el-button>
    </template>
    <div class="wb-kpi-grid kpi-4">
      <div class="wb-kpi-cell wb-kpi-cell--primary" @click="goMore">
        <div class="wb-kpi-cell__label">拓客数</div>
        <div class="wb-kpi-cell__value">{{ formatNumber(overview.tkCount) }}</div>
      </div>
      <div class="wb-kpi-cell wb-kpi-cell--success" @click="goMore">
        <div class="wb-kpi-cell__label">到店数</div>
        <div class="wb-kpi-cell__value">{{ formatNumber(overview.visitCount) }}</div>
      </div>
      <div class="wb-kpi-cell wb-kpi-cell--warning" @click="goMore">
        <div class="wb-kpi-cell__label">开单数</div>
        <div class="wb-kpi-cell__value">{{ formatNumber(overview.billingCount) }}</div>
      </div>
      <div class="wb-kpi-cell wb-kpi-cell--info" @click="goMore">
        <div class="wb-kpi-cell__label">到店率</div>
        <div class="wb-kpi-cell__value">{{ overview.visitRate }}%</div>
      </div>
    </div>
  </workbench-card>
</template>

<script>
import { getDashboardOverview } from '@/api/lqTkDashboard'
import WorkbenchCard from '../workbench-card.vue'
import { formatNumber, getCurrentMonthRange } from '../utils'

export default {
  name: 'WidgetTkOverview',
  components: { WorkbenchCard },
  data() {
    return {
      loading: false,
      overview: { tkCount: 0, visitCount: 0, billingCount: 0, visitRate: '0.00' }
    }
  },
  mounted() {
    this.load()
  },
  methods: {
    formatNumber,
    async load() {
      this.loading = true
      try {
        const range = getCurrentMonthRange()
        const res = await getDashboardOverview({
          startTime: range.startTime,
          endTime: range.endTime
        })
        const d = res.data || {}
        const tkCount = Number(d.TotalExpansionCount || d.totalExpansionCount || d.TotalTkCount || d.totalTkCount || 0)
        const visitCount = Number(d.TotalVisitCount || d.totalVisitCount || 0)
        const billingCount = Number(d.TotalBillingCount || d.totalBillingCount || d.BillingCount || d.billingCount || 0)
        const visitRate = Number(d.OverallVisitRate || d.overallVisitRate || d.VisitRate || d.visitRate || 0)
        this.overview = {
          tkCount,
          visitCount,
          billingCount,
          visitRate: visitRate.toFixed(2)
        }
      } catch (e) {
        this.overview = { tkCount: 0, visitCount: 0, billingCount: 0, visitRate: '0.00' }
      } finally {
        this.loading = false
      }
    },
    goMore() {
      this.$router.push('/lqTkjlb').catch(() => {})
    }
  }
}
</script>

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