member-sleep.vue 2.46 KB
<template>
  <workbench-card title="沉睡会员概览" subtitle="沉睡区间分布" icon="el-icon-moon" tone="purple" :loading="loading">
    <div class="wb-kpi-grid kpi-2">
      <div class="wb-kpi-cell wb-kpi-cell--warning">
        <div class="wb-kpi-cell__label">60-89天</div>
        <div class="wb-kpi-cell__value">{{ formatNumber(data.sleep_60_89) }}</div>
      </div>
      <div class="wb-kpi-cell wb-kpi-cell--danger">
        <div class="wb-kpi-cell__label">90-179天</div>
        <div class="wb-kpi-cell__value">{{ formatNumber(data.sleep_90_179) }}</div>
      </div>
      <div class="wb-kpi-cell wb-kpi-cell--info">
        <div class="wb-kpi-cell__label">180-359天</div>
        <div class="wb-kpi-cell__value">{{ formatNumber(data.sleep_180_359) }}</div>
      </div>
      <div class="wb-kpi-cell wb-kpi-cell--primary">
        <div class="wb-kpi-cell__label">360天+</div>
        <div class="wb-kpi-cell__value">{{ formatNumber(data.sleep_360_plus) }}</div>
      </div>
    </div>
    <div class="sleep-total">合计沉睡:{{ formatNumber(data.totalSleepMembers) }} 人</div>
  </workbench-card>
</template>

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

export default {
  name: 'WidgetMemberSleep',
  components: { WorkbenchCard },
  data() {
    return { loading: false, data: {} }
  },
  mounted() {
    this.load()
  },
  methods: {
    formatNumber,
    async load() {
      this.loading = true
      try {
        const res = await request({
          url: '/api/Extend/LqReport/get-dashboard-data',
          method: 'POST',
          data: { StatisticsMonth: getCurrentMonthYm() }
        })
        const ms = (res.data && res.data.Success && res.data.Data && res.data.Data.MemberStatistics)
          ? res.data.Data.MemberStatistics : {}
        this.data = {
          totalSleepMembers: ms.TotalSleepMembers || 0,
          sleep_60_89: ms.SleepMembers60_89 || 0,
          sleep_90_179: ms.SleepMembers90_179 || 0,
          sleep_180_359: ms.SleepMembers180_359 || 0,
          sleep_360_plus: ms.SleepMembers360Plus || 0
        }
      } catch (e) {
        this.data = {}
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../widget-common.scss';
.kpi-2 { grid-template-columns: repeat(2, 1fr); }
.sleep-total {
  margin-top: 10px;
  text-align: center;
  font-size: 12px;
  color: #94a3b8;
}
</style>