<template>
  <div class="app-container home">
    <div class="top">
      <div class="card">
        <div>pic</div>
        <div>
          <p>总用电量</p>
          <h2>1641kWh</h2>
        </div>
      </div>
      <div class="card">
        <div>pic</div>
        <div>
          <p>当前功率</p>
          <h2>11kW</h2>
        </div>
      </div>
      <div class="card">
        <div>pic</div>
        <div>
          <div>
            <p>当前温度</p>
            <h2>25℃</h2>
          </div>
        </div>
      </div>
      <div class="card">
        <div>pic</div>
        <div>
          <p>运行状态</p>
          <h2 style="color: #1ab394">开启</h2>
        </div>
      </div>
    </div>

    <div class="bottom">
      <div class="bottom1">
        <div class="bottom1-1">
          日用电量
        </div>
        <div id="myEcharts" style="width: 100%; height: 86.7%"></div>
      </div>
      <div class="bottom1">
        <div class="bottom1-1">
          月用电量
        </div>
        <div id="myEcharts2" style="width: 100%; height: 86.7%"></div>
      </div>
      <div class="bottom1">
        <div class="bottom1-1">
          当前功率
        </div>
        <div id="myEcharts3" style="width: 100%; height: 86.7%"></div>
      </div>
      <div class="bottom1">
        <div class="bottom1-1">
          当前温度
        </div>
        <div id="myEcharts4" style="width: 100%; height: 86.7%"></div>
      </div>
    </div>
  </div>
</template>

<script name="Index">
import {getFrdl, getFrld} from '../../../api/emonitor/api'
import { onMounted } from "vue";
import * as echarts from 'echarts';
export default {
  name: "frdl",
  setup() {
    onMounted(() => {//需要获取到element,所以是onMounted的Hook
      getFrld(4).then((res)=>{
        console.log(res)
      })
      // getFrdl(4).then((res)=>{
      //   console.log(res)
      // })

      let myChart = echarts.getInstanceByDom(document.getElementById("myEcharts"));
      if (myChart){
        myChart.dispose()
      }
      myChart = echarts.init(document.getElementById("myEcharts"));

      let myChart2 = echarts.getInstanceByDom(document.getElementById("myEcharts2"));
      if (myChart2){
        myChart2.dispose()
      }
      myChart2 = echarts.init(document.getElementById("myEcharts2"));

      let myChart3 = echarts.getInstanceByDom(document.getElementById("myEcharts3"));
      if (myChart3){
        myChart3.dispose()
      }
      myChart3 = echarts.init(document.getElementById("myEcharts3"));

      let myChart4 = echarts.getInstanceByDom(document.getElementById("myEcharts4"));
      if (myChart4){
        myChart4.dispose()
      }
      myChart4 = echarts.init(document.getElementById("myEcharts4"));

      // 绘制图表
      myChart.setOption({
        title: {},
        tooltip: {},
        textStyle:{
          color:'#BEC3DA'
        },
        xAxis: {
          data: ["12-3", "12-4", "12-5", "12-6", "12-7", "12-8"],
          axisLine:{
            lineStyle:{
              color:'#BEC3DA',
              type:'dashed'
            }
          }
        },
        yAxis: {
          type: 'value',
          name: "kWh",
          splitLine:{
            show:true,
            lineStyle:{
              type:'dashed',
              color:'#BEC3DA'
            }
          },
          axisLine: {
            show: true,
            lineStyle:{
              type:'dashed',
              color:'#BEC3DA'
            }
          },
        },
        series: [
          {
            name: "日用电量",
            type: "bar",
            data: [5, 20, 36, 10, 10, 20],
            itemStyle:{
              color:'#2F8EE0'
            },
          },
        ],
      });
      window.onresize = function () {//自适应大小
        myChart.resize();
      };
      myChart2.setOption({
        title: {},
        tooltip: {},
        textStyle:{
          color:'#BEC3DA'
        },
        xAxis: {
          data: ["12-3", "12-4", "12-5", "12-6", "12-7", "12-8"],
          axisLine:{
            lineStyle:{
              color:'#BEC3DA',
              type:'dashed'
            }
          }
        },
        yAxis: {
          type: 'value',
          name: "kWh",
          splitLine:{
            show:true,
            lineStyle:{
              type:'dashed',
              color:'#BEC3DA'
            }
          },
          axisLine: {
            show: true,
            lineStyle:{
              type:'dashed',
              color:'#BEC3DA'
            }
          },
        },
        series: [
          {
            name: "月用电量",
            type: "bar",
            data: [5, 20, 36, 10, 10, 20],
            itemStyle:{
              color:'#2F8EE0'
            },
          },
        ],
      });
      window.onresize = function () {//自适应大小
        myChart2.resize();
      };
      myChart3.setOption({
        title: {},
        tooltip: {},
        textStyle:{
          color:'#BEC3DA'
        },
        xAxis: {
          data: ["12-3", "12-4", "12-5", "12-6", "12-7", "12-8"],
          axisLine:{
            lineStyle:{
              color:'#BEC3DA',
              type:'dashed'
            }
          }
        },
        yAxis: {
          type: 'value',
          name: "kW",
          splitLine:{
            show:true,
            lineStyle:{
              type:'dashed',
              color:'#BEC3DA'
            }
          },
          axisLine: {
            show: true,
            lineStyle:{
              type:'dashed',
              color:'#BEC3DA'
            }
          },
        },
        series: [
          {
            name: "当前功率",
            type: "line",
            data: [5, 20, 36, 10, 10, 20],
            itemStyle:{
              color:'#2F8EE0'
            },
          },
        ],
      });
      window.onresize = function () {//自适应大小
        myChart3.resize();
      };
      myChart4.setOption({
        title: {},
        tooltip: {},
        textStyle:{
          color:'#BEC3DA'
        },
        xAxis: {
          data: ["12-3", "12-4", "12-5", "12-6", "12-7", "12-8"],
          axisLine:{
            lineStyle:{
              color:'#BEC3DA',
              type:'dashed'
            }
          }
        },
        yAxis: {
          type: 'value',
          name: "℃",
          splitLine:{
            show:true,
            lineStyle:{
              type:'dashed',
              color:'#BEC3DA'
            }
          },
          axisLine: {
            show: true,
            lineStyle:{
              type:'dashed',
              color:'#BEC3DA'
            }
          },
        },
        series: [
          {
            name: '当前温度',
            type: 'line',
            stack: 'Total',
            itemStyle:{
              color:'#2F8EE0'
            },
            data: [120, 132, 101, 134, 90, 230, 210]
          },
        ],
      });
      window.onresize = function () {//自适应大小
        myChart4.resize();
      };
    });
  },
  components: {},
  mounted() {},
};


</script>

<style scoped lang="scss">
.top{
  width: 100%;
  height: 110px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  margin-bottom: 20px;
}
.card{
  width: 24%;
  height: 110px;
  background-color: #2F3D8A;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.bottom{
  width: 100%;
  height: 640px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.bottom1{
  width: 49.35%;
  height: 300px;
  background-color: #2F3D8A;
  margin-bottom: 20px;
}
p{
  margin-bottom: 10px;
}
.bottom1-1{
  width: 100%;
  height: 40px;
  background-color: #374590;
  padding-top: 10px;
  padding-left: 10px;
}
</style>