<template>
  <div class="dashboard-container">
    <div class="dashboard-editor-container">

      <panel-group @handleSetLineChartData="handleSetLineChartData" :visitorVolume="this.visitorVolume"/>
      <a href="javascript:" style="font-size: 20pt;display: block;text-align: center;">{{ this.name }}</a>
      <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
        <line-chart :chart-data="lineChartData"/>
      </el-row>
<!--            <el-row :gutter="32">
              <el-col :xs="24" :sm="24" :lg="8">
                <div class="chart-wrapper">
                  <radar-chart />
                </div>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="8">
                <div class="chart-wrapper">
                  <pie-chart />
                </div>
              </el-col>
              <el-col :xs="24" :sm="24" :lg="8">
                <div class="chart-wrapper">
                  <bar-chart />
                </div>
              </el-col>
            </el-row>-->
    </div>
  </div>
</template>

<script>
// import GithubCorner from '@/components/GithubCorner'
import PanelGroup from './dashboard/PanelGroup'
import LineChart from './dashboard/LineChart'
import RadarChart from '@/components/Echarts/RadarChart'
import PieChart from '@/components/Echarts/PieChart'
import BarChart from '@/components/Echarts/BarChart'

const lineChartData = {
  Day: {
    sptData: [],
    zjbData: [],
    data: []
  },
  Month: {
    //expectedData
    sptData: [],
    //expectedData
    zjbData: [],
    data: []
  },
}

export default {
  name: 'Dashboard',
  components: {
    PanelGroup,
    LineChart,
    RadarChart,
    PieChart,
    BarChart
  },
  data() {
    return {
      name: '每日访问量',
      visitorVolume: {
        sptDay: 0,
        sptMonth: 0,
        zjbDay: 0,
        zjbMonth: 0
      },
      lineChartData: lineChartData.Day
    }
  },
  methods: {
    init() {
      this.getDataList();
    },
    getDataList() {
      this.$http.post("api/IndexController/selectVisitsList").then(function (res) {
        for (const re of res.body.content) {
          switch (re.LABLE) {
            case "住建部当日" :
              this.visitorVolume.zjbDay = re.SL;
              break;
            case "住建部当月" :
              this.visitorVolume.zjbMonth = re.SL;
              break;
            case "省平台当日" :
              this.visitorVolume.sptDay = re.SL;
              break;
            default :
              this.visitorVolume.sptMonth = re.SL;
              break;
          }
        }
      })
      this.$http.post("api/IndexController/selectMyfwlList").then(function (res) {
        lineChartData.Month.data = []
        lineChartData.Month.sptData = []
        lineChartData.Month.zjbData = []
        for (const re of res.body.content) {
          lineChartData.Month.data.push(re.YUEFEN)
          lineChartData.Month.sptData.push(re.SPTYFWL)
          lineChartData.Month.zjbData.push(re.ZJBYFWL)
        }
      })
      this.$http.post("api/IndexController/selectMrfwlList").then(function (res) {
        lineChartData.Day.data = []
        lineChartData.Day.sptData = []
        lineChartData.Day.zjbData = []
        for (const re of res.body.content) {
          lineChartData.Day.data.push(re.RIQI)
          lineChartData.Day.sptData.push(re.SPTRFWL)
          lineChartData.Day.zjbData.push(re.ZJBRFWL)
        }
      })
    },
    handleSetLineChartData(type) {
      type === "Day" ? this.name = "每日访问量" : this.name = "每月访问量"
      this.lineChartData = lineChartData[type]
    }
  },
  mounted() {
    this.init();
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
