<template>
  <div id="app-container-proportion">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span style="color:#5cd9e8">
          <icon name="chart-area"></icon>
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">产品占比图</span>
          <div class="decoration2">
            <dv-decoration-2 :reverse="true" style="width:5px;height:200px;" />
          </div>
        </div>
      </div>
      <div>
        <div>
          <div id="productProportion" :style="transformdata ? 'transform: scale('+transformdata+') translate(0,0) !important;width:420px; height: 160px;margin: auto;' :'width:420px; height: 160px;margin: auto;'"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import resize from "@/views/dashboard/mixins/resize";
export default {
  props: ['dashboarddata','transformdata'],
  components: {
  },
  data() {
    return {
      chart: null,
    };
  },
  mixins: [resize],
  mounted() {
    console.log(this.dashboarddata);
    this.initChart();
    setInterval(() => {
      this.initChart();
    }, 3600000);
  },

  methods: {
    initChart() {
      // 基于准备好的dom，初始化echarts实例
      this.chart = this.echarts.init(document.getElementById("productProportion"));
      this.chart.setOption({
        color: [
          "#37a2da",
          "#32c5e9",
          "#9fe6b8",
          "#ffdb5c",
          "#ff9f7f",
          "#fb7293",
          "#e7bcf3",
          "#8378ea"
        ],
        tooltip: {
          trigger: "item",
          formatter: "{b} : {c} ({d}%)"
        },
        toolbox: {
          show: true
        },
        calculable: true,
        legend: [{
          icon: "circle",
          orient: 'vertical',
          right: 62,
          top: 40,
          bottom: 20,
          data: ["H2", "C2H4", "CH4", "C3H6"],
          textStyle: {
            color: "#fff"
          }
        }, {
          icon: "circle",
          orient: 'vertical',
          right: -6,
          top: 40,
          bottom: 20,
          data: ["Offgas", "LPG", "C4", "RPG"],
          textStyle: {
            color: "#fff"
          }
        }],
        label: {
          alignTo: 'edge',
          formatter: '{name|{b}}\n{weight|{c} 吨({d}%)}',
          minMargin: 5,
          edgeDistance: 10,
          lineHeight: 15,
          rich: {
            name: {
              fontSize: 12,
              color: '#ffffff'
            },
            weight: {
              fontSize: 8,
              color: '#ffffff'
            }
          }
        },
        series: [
          {
            type: "pie",
            radius: [10, 55],
            roseType: "area",
            center: ["36%", "50%"],
            data: [
              { value: this.dashboarddata.energyQingqi, name: "H2" },
              { value: this.dashboarddata.energyYixi, name: "C2H4" },
              { value: this.dashboarddata.energyJiawan, name: "CH4" },
              { value: this.dashboarddata.energyBingxi, name: "C3H6" },
              { value: this.dashboarddata.energyOffgas, name: "Offgas" },
              { value: this.dashboarddata.energyLpg, name: "LPG" },
              { value: this.dashboarddata.energyCsi, name: "C4" },
              { value: this.dashboarddata.energyRpg, name: "RPG" }
            ],
          }
        ]
      });
    }
  },
  destroyed() {
    window.onresize = null;
  }
}
</script>

<style lang="scss">
  #app-container-proportion {
    padding: 0.2rem 0.2rem 0;
    height: 240px;
    min-width: 3.75rem;
    border-radius: 0.0625rem;
    .bg-color-black {
      height: 90%;
      border-radius: 0.125rem;
    }
    .text {
      color: #c3cbde;
    } //下滑线动态
    .decoration2 {
      position: absolute;
      right: 0.125rem;
    }
    .chart-box {
      margin-top: 0.2rem;
      width: 2.125rem;
      height: 2.125rem;
      .active-ring-name {
        padding-top: 0.125rem;
      }
    }
  }
</style>
