<template>
  <div>
     <avue-data-tabs :option="option"></avue-data-tabs>
  </div>
</template>

<script>
  import {mapGetters} from "vuex";
  import request from "@/router/axios";

  export default {
    name: "wel",
    data() {
      return {
        option: {
          span: 6,
          data: [
            {
              click: function (item) {
                 console.log(JSON.stringify(item));
              },
              title: '用户统计',
              subtitle: "",
              count: 0,
              // allcount: 5213,
              // text: '当前用户总数',
              color: 'rgb(27, 201, 142)',
              key: "用"
            },
            {
              click: function (item) {
                 console.log(JSON.stringify(item));
              },
              title: '订单统计',
              subtitle: '',
              count: 0,
              color: 'rgb(230, 71, 88)',
              key: '订'
            },
            // {
            //   click: function (item) {
            //     console.log(JSON.stringify(item));
            //   },
            //   title: '商品统计',
            //   subtitle: '更新时间：2022-03-31 16:26:56',
            //   count: 4,
            //   allcount: 6,
            //   text: '当前上线商品总数',
            //   color: 'rgb(178, 159, 255)',
            //   key: ''
            // },
            {
              click: function (item) {
                console.log(JSON.stringify(item));
              },
              title: '当前抢购场次',
              subtitle: '',
              count: 0,
              color: 'rgb(145, 200, 30)',
              key: '抢'
            }
          ]
        }
      };
    },
    computed: {
      ...mapGetters(["userInfo"]),
    },
    mounted() {
      this.init();
    },
    methods: {
      handleChange(val) {
        window.console.log(val);
      },
      init() {
        request({
          url: '/api/home/statistical',
          method: 'get'
        }).then(res => {
          const data = res.data.data;
          this.option.data.forEach(e => {
            e.subtitle = '更新时间：' + data.currTime;
            if ('用户统计' === e.title) {
              e.count = data.userTotal;
            }
            if ('订单统计' === e.title) {
              e.count = data.orderTotal;
            }
            if ('抢购场次' === e.title) {
              e.count = data.snapTotal;
            }
          })
        })


      }
    },
  };
</script>

<style>
  .el-font-size {
    font-size: 14px;
  }
</style>
