home.vue 4.63 KB
<template>
  <div class="dashboard-container">
    <div class="dashboard-editor-container">
      <github-corner class="github-corner" />
      <panel-group />
      <div class="active-open-card">
        <el-card>
          <div slot="header" class="clearfix">
            <span>开卡地区</span>
          </div>
          <el-row>
            <el-col :xs="24" :sm="24" :lg="24">
              <div class="chart-wrapper">
                <bar-chart :option-data="regionStatistics[0]" :option="{title: { show: true, text: '开卡地区:地区分布' }}" />
              </div>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="24">
              <div class="chart-wrapper">
                <bar-chart :option-data="batchStatistics[0]" :option="{title: { show: true, text: '开卡地区:批次分布' }}" />
              </div>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="24">
              <div class="chart-wrapper">
                <bar-chart :option-data="channelStatistics[0]" :option="{title: { show: true, text: '开卡地区:渠道分布' }}" />
              </div>
            </el-col>
          </el-row>
        </el-card>
        <el-card>
          <div slot="header" class="clearfix">
            <span>激活地区</span>
          </div>
          <el-row>
            <el-col :xs="24" :sm="24" :lg="24">
              <div class="chart-wrapper">
                <bar-chart :option-data="regionStatistics[1]" :option="{title: { show: true, text: '激活地区:地区分布' }}" />
              </div>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="24">
              <div class="chart-wrapper">
                <bar-chart :option-data="batchStatistics[1]" :option="{title: { show: true, text: '激活地区:批次分布' }}" />
              </div>
            </el-col>
            <el-col :xs="24" :sm="24" :lg="24">
              <div class="chart-wrapper">
                <bar-chart :option-data="channelStatistics[1]" :option="{title: { show: true, text: '激活地区:渠道分布' }}" />
              </div>
            </el-col>
          </el-row>
        </el-card>
      </div>
    </div>
  </div>
</template>
<script>
import GithubCorner from '@/components/GithubCorner'
import PanelGroup from './dashboard/PanelGroup'
import BarChart from './dashboard/BarChart'
import homeData from '@/api/home/homeData'

export default {
  name: 'Dashboard',
  components: {
    GithubCorner,
    PanelGroup,
    BarChart
  },
  data() {
    return {
      regionStatistics: [{}, {}],
      batchStatistics: [{}, {}],
      channelStatistics: [{}, {}]
    }
  },
  mounted() {
    this.getRegionStatistics(0)
    this.getBatchStatistics(0)
    this.getChannelStatistics(0)
    this.getRegionStatistics(1)
    this.getBatchStatistics(1)
    this.getChannelStatistics(1)
  },
  methods: {
    getRegionStatistics(status) {
      homeData.getRegionStatistics({
        userId: this.$store.state.user.user.id,
        status: status
      }).then(res => {
        console.log(res)
        this.$set(this.regionStatistics, status, res)
      }).catch(err => {
        this.$message.error(err.message)
        this.$set(this.regionStatistics, status, [])
        console.log(err)
      })
    },
    getBatchStatistics(status) {
      homeData.getBatchStatistics({
        userId: this.$store.state.user.user.id,
        status: status
      }).then(res => {
        console.log(res)
        this.$set(this.batchStatistics, status, res)
      }).catch(err => {
        this.$message.error(err.message)
        this.$set(this.batchStatistics, status, [])
        console.log(err)
      })
    },
    getChannelStatistics(status) {
      homeData.getChannelStatistics({
        userId: this.$store.state.user.user.id,
        status: status
      }).then(res => {
        console.log(res)
        this.$set(this.channelStatistics, status, res)
      }).catch(err => {
        this.$message.error(err.message)
        this.$set(this.channelStatistics, status, [])
        console.log(err)
      })
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;
  .github-corner {
    position: absolute;
    top: 0;
    border: 0;
    right: 0;
  }
  .chart-wrapper {
    background: #fff;
    padding: 16px;
    border-top: 1px solid #ccc;
  }
  .el-col:nth-of-type(1) {
    .chart-wrapper {
      border-top: 0;
    }
  }
}
@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
.active-open-card {
  display: flex;
  justify-content: space-between;
}
.el-card {
  width: 48%;
  flex-shrink: 0;
  flex-grow: 0;
}
</style>