<!-- 统计卡片 -->
<template>
  <el-row :gutter="15">
    <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
      <el-card class="analysis-chart-card" shadow="never">
        <template v-slot:header>
          <div class="ele-cell">
            <div class="ele-cell-content">今日新增线索</div>
            <el-tag size="mini" type="danger">日</el-tag>
          </div>
        </template>
        <div
          class="analysis-chart-card-num ele-text-heading"
          style="margin-bottom: 10px"
          >{{ data.today_clues }}条</div
        >
        <el-divider />
        <div class="analysis-chart-card-text"
          >累计线索：{{ data.total_clues }}条</div
        >
      </el-card>
    </el-col>
    <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
      <el-card class="analysis-chart-card" shadow="never">
        <template v-slot:header>
          <div class="ele-cell">
            <div class="ele-cell-content">当前用户数</div>
          </div>
        </template>
        <div
          class="analysis-chart-card-num ele-text-heading"
          style="margin-bottom: 10px"
          >{{ data.member }}人</div
        >
        <el-divider />
        <div class="analysis-chart-card-text"
          >历史成交：{{ data.orders }}单</div
        >
      </el-card>
    </el-col>
  </el-row>
</template>

<script>
  import { use } from 'echarts/core';
  import { CanvasRenderer } from 'echarts/renderers';
  import { LineChart, BarChart } from 'echarts/charts';
  import { GridComponent, TooltipComponent } from 'echarts/components';
  import { echartsMixin } from '@/utils/echarts-mixin';
  import { pageIndex } from '@/api/home';

  use([CanvasRenderer, LineChart, BarChart, GridComponent, TooltipComponent]);

  export default {
    components: {},
    mixins: [echartsMixin(['visitChart', 'payNumChart'])],
    data() {
      return {
        // 访问量折线图配置
        visitChartOption: {},
        // 支付笔数柱状图配置
        payNumChartOption: {},
        data: {
          total_clues: 0,
          today_clues: 0,
          member: 0,
          orders: 0
        }
      };
    },
    computed: {
      // 是否开启响应式布局
      styleResponsive() {
        return this.$store.state.theme.styleResponsive;
      }
    },
    created() {
      this.fetchData();
    },
    methods: {
      fetchData() {
        pageIndex()
          .then((res) => {
            this.$util.assignObject(this.data, {
              ...res
            });
          })
          .catch((e) => {
            this.$message.error(e.message);
          });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .analysis-chart-card-num {
    font-size: 30px;
  }

  .analysis-chart-card-content {
    height: 40px;
    box-sizing: border-box;
    margin-bottom: 12px;
  }

  .analysis-chart-card-text {
    padding-top: 12px;
  }
</style>
