<template>
  <div>
    <div id="productProportion" style="width:420px; height: 160px;"></div>
  </div>
</template>

<script>
import resize from "./mixins/resize";
import { selectLast } from "@/api/aspen/dashboarddata";

export default {
  data() {
    return {
      chart: null,
      // dashboard抓取数据
      dashboarddata: {
        energyYixi: null,
        energyBingxi: null,
        energyQingqi: null,
        energyJiawan: null,
        energyCsi: null,
        energyBenzene: null,
        energyToluene: null,
        energyXylene: null,
        energyTanliu: null,
        energyWashoil: null,
        energyTanwu: null,
        energyIma: null,
        energyCjiu: null,
        energyRpg: null,
        energyfeedNap: null,
        energyfeedYiwan: null,
        energyfeedTanwu: null,
        energyfeedTanliu: null,
        energyfeedLpg: null,
        energyOffgas: null,
        energyLpg: null,
        steamSsinfur: null,
        steamSsoutlet: null,
        steamSsoutaeu: null,
        steamSsoutesi: null,
        steamSsoutksan: null,
        steamSsoutsc: null,
        steamHsinsub: null,
        steamHsinlet: null,
        steamHsinksan: null,
        steamHsoutpjiu: null,
        steamHsoutaeu: null,
        steamHsoutlet: null,
        steamHsoutesan: null,
        steamHsoutphyi: null,
        steamHsoutpher: null,
        steamHsouthwu: null,
        steamHsoutkliu: null,
        steamHsoutsc: null,
        steamHhpsub: null,
        steamMsinaeu: null,
        steamMsinlet: null,
        steamMsinphyi: null,
        steamMsinkliu: null,
        steamMsoutflare: null,
        steamMsoutaeu: null,
        steamMsoutsctu: null,
        steamMsouteer: null,
        steamMsoutfur: null,
        steamMsoutva: null,
        steamMsouttracing: null,
        steamLsinsub: null,
        steamLsinpjiu: null,
        steamLsinaeu: null,
        steamLsineer: null,
        steamLsinpher: null,
        steamLsoutsctu: null,
        steamLsoutvjiu: null,
        steamLsoutewuliu: null,
        steamLsoutewusan: null,
        steamLsouttracing: null,
        steamLsoutesan: null,
        steamLsoutesi: null,
        steamLsoutother: null
      },
      // 查询参数
      queryParams: {
      },
    };
  },
  mixins: [resize],
  mounted() {
    this.getList()
    // 每隔30秒请求一次数据
    // 每隔秒请求一次数据
    setInterval(() => {
      this.getList();
    }, 10000)

  },
  methods: {
    /** 查询dashboard抓取数据列表 */
    getList()
    {
      selectLast(this.queryParams).then(response => {
        this.dashboarddata = response.data;
        this.initChart();
      });
    },
    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" scoped>
</style>
