<template>
  <div class="dashboard-editor-container">
    <div style="margin-bottom: 2px">
      <el-date-picker
        v-model="daterange"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :picker-options="pickerOptions"
        @change="change"
      >
      </el-date-picker>
      <el-button type="primary" icon="el-icon-query" @click="handleFilter"
        >确定</el-button
      >
    </div>
    <panel-group @handleSetLineChartData="handleSetLineChartData" ref="panelg" :query="query"/>

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <bar-chart :chartData="admindata1" />
    </el-row>
  </div>
</template>

<script>
import PanelGroup from '../components/PanelGroup'
import LineChart from '../components/LineChart'
import BarChart from '../components/BarChart'
import { getAdmindata1, getCompanydis, getConsumerdis } from '@/api/analyse'
const lineChartData = {
  '访问用户': {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145]
  },
  '缴费用户': {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  '模考次数': {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  '题目总数': {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

export default {
  name: 'DashboardAdmin',
  components: {
    PanelGroup,
    LineChart,
    BarChart
  },
  data() {
    return {
      lineChartData: lineChartData.访问用户,
      admindata1:{},
      daterange:[],
      query: { datestart: null, dateend: null },
      pickerOptions: {
        shortcuts: [{
            text: '2020年',
            onClick(picker) {
              picker.$emit('pick', ['2020-01-01','2021-01-01']);
            }
          },
          {
            text: '2021年',
            onClick(picker) {
              picker.$emit('pick', ['2021-01-01','2022-01-01']);
            }
          }]
      },
    }
  },
  created() {
    this.initquery()
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    },
    initquery() {
      let date = new Date();
      let start = date.getFullYear() + "-01-01";
      let end = date.getFullYear() + 1 + "-01-01";
      this.daterange = [start,end];
      // this.$refs["picker"].$emit('pick', [start, end]);
      this.query.datestart = this.daterange[0];
      this.query.dateend = this.daterange[1];
      this.getadmindata1();
    },
    getadmindata1(){
            getAdmindata1(this.query).then(res=>{
                this.admindata1 = res.data
            })
        },
    handleFilter(){
      this.query.datestart = this.daterange[0];
      this.query.dateend = this.daterange[1];
      this.getadmindata1();
      this.$refs['panelg'].getBasicCount();
    },
    change(v){
      if (v == null) this.daterange=["",""]
    }
  }
}
</script>

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

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

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

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