<template>
  <div class="app-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>
    <el-card>
      <bar-chart :chartData="admindata1" />
    </el-card>
    <el-row :gutter="6" style="margin-top: 6px">
      <el-col :xs="24" :md="12">
        <el-card>
          <china-map :chartData="companydis" />
        </el-card>
      </el-col>
      <el-col :xs="24" :md="12">
        <el-card>
          <china-map :chartData="consumerdis" />
        </el-card>
      </el-col>
    </el-row>
    <el-card style="margin-top: 6px">
      <line-chart :chartData="monidata" />
    </el-card>
  </div>
</template>
<script>
import BarChart from "../components/BarChart";
import ChinaMap from "../components/ChinaMap";
import LineChart from "../components/LineChart";
import {
  getAdmindata1,
  getCompanydis,
  getConsumerdis,
  getMonitest,
} from "@/api/analyse";
import { option } from 'runjs';
export default {
  components: { BarChart, ChinaMap, LineChart },
  data() {
    return {
      admindata1: {},
      companydis: {},
      consumerdis: {},
      monidata: {},
      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: {
    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.handleFilter()
    },
    handleFilter() {
      this.query.datestart = this.daterange[0];
      this.query.dateend = this.daterange[1];
      this.getadmindata1(this.query);
      this.getcompanydis(this.query);
      this.getconsumerdis(this.query);
      this.getmonitest(this.query);
    },
    getadmindata1(query) {
      getAdmindata1(query).then((res) => {
        this.admindata1 = res.data;
      });
    },
    getcompanydis(query) {
      getCompanydis(query).then((res) => {
        this.companydis = res.data;
      });
    },
    getconsumerdis(query) {
      getConsumerdis(query).then((res) => {
        this.consumerdis = res.data;
      });
    },
    getmonitest(query) {
      getMonitest(query).then((res) => {
        this.monidata = res.data;
      });
    },
    change(v){
      console.log(v)
      if (v == null) this.daterange=["",""]
    }
  },
};
</script>