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


    <panel-group :panelData="panelData" @handleSetLineChartData="handleSetLineChartData" />
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <el-col :xs="24" :sm="24" :lg="24">
        <list-chart ref="listChart"/>
      </el-col>

    </el-row>
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <el-col :xs="24" :sm="24" :lg="12">
        <line-chart ref="lineChart" :chart-data="lineChartData"/>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="12">
        <print-chart ref="printChart" :chart-data="lineChartDataMoney"/>
      </el-col>

    </el-row>
    <el-row>
      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper">
          <span style="text-align: center;display: block;width: 100%;line-height: 36px">月订单数量统计</span>
          <bar-chart :chart-data="barChartDataWork"/>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper">
          <span style="text-align: center;display: block;width: 100%;line-height: 36px">月订单金额统计</span>
          <bar-chartmoney :chart-data="barChartDataMoney"/>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper">
          <span style="text-align: center;display: block;width: 100%;line-height: 36px;margin-bottom: 10px">月产品类型统计</span>
          <pie-chart :chart-data="pieChartData" />
        </div>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import ListChart from './components/ListChart'
import LineChart from './components/LineChart'
import PrintChart from './components/PrintChart'
import PieChart from './components/PieChart'
import BarChart from './components/BarChart'
import BarChartmoney from './components/BarChartmoney'
import {getIndexCardPanelData} from '@/api/system/user.js'
const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165]
  },
  newVisitisMoney: {
    expectedData: []
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}


export default {
  name: 'chartSummary',
  components: {
    PanelGroup,
    ListChart,
    LineChart,
    PrintChart,
    PieChart,
    BarChart,
    BarChartmoney
  },
  data() {
    return {
      lineChartData: {},
      lineChartDataMoney: {},
      barChartDataWork:{},
      barChartDataMoney:{},
      pieChartData:{},
      panelData:{},
      xAxisArray:[],
    }
  },
  mounted() {
    const _that = this;
    // return new Promise(function (resolve, reject) {
    //   setTimeout(() => {
    //
    //     resolve(0)
    //   }, 500)
    // })
    _that.getInfo();

  },
  methods: {
    getInfo(){
      const _that = this;
      var data = {}
      getIndexCardPanelData(data).then(response => {
        localStorage.setItem("xAxisArray",JSON.stringify(response.data.day7Work.xAxisArray));
        _that.$refs.listChart.printNameList = response.data.day7ProductPrintCount.legendStrArray;
        _that.$refs.listChart.printData = response.data.day7ProductPrintCount;
        _that.$nextTick(() => {
          _that.$refs.listChart.initChart();
          _that.$refs.lineChart.initChart();
          _that.$refs.printChart.initChart();
        })

        var data = {
          waitBreedOrderCount:response.data.waitBreedOrderCount,
          waitSendOrderCount:response.data.waitSendOrderCount,
          workingOrderCount:response.data.workingOrderCount,
          scheduleBreedCount:response.data.scheduleBreedCount
        }
        _that.panelData = data;
        // console.log("111",_that.panelData);
        var dataProduct = [];
        for (let i = 0; i < response.data.monthOrderProduct.seriesData.length; i++) {
          var itemData = response.data.monthOrderProduct.seriesData[i];
          dataProduct.push(itemData.name)
        }
        // console.log("333",response.data);

        var totalData ={
          newVisitis:{
            expectedData:response.data.day7Work.seriesData[0].data,
            actualData:response.data.day7Work.seriesData[1].data
          },
          newVisitisMoney:{
            expectedData:response.data.day7Money.seriesData[0].data,
          },
          barVisitisWork:{
            expectedData:response.data.month12Work.seriesData[0].data,
          },
          barVisitisMoney:{
            expectedData:response.data.month12Money.seriesData[0].data,
          },

          pieVisitis:{
            expectedData:response.data.monthOrderProduct.seriesData,
            actualData:dataProduct
          },
        }

        _that.lineChartData = totalData.newVisitis;

        _that.lineChartDataMoney = totalData.newVisitisMoney;
        _that.barChartDataWork = totalData.barVisitisWork;
        _that.barChartDataMoney = totalData.barVisitisMoney;
        _that.pieChartData = totalData.pieVisitis;
      }).catch(err => {
        // _that.$message.error(err)
      })
    },
    handleSetLineChartData(type) {
      // this.lineChartData = lineChartData[type]
    }
  }
}
</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>
