<template>
  <div class="process-div">
    <span>{{ itemData.label }}</span>
    <!-- <div :id="'process' + itemData.id" class="process-echart"></div> -->
    <div class="process-echart">
      <el-progress
        :text-inside="true"
        :stroke-width="20"
        :percentage="itemData.value"
        :color="itemData.color"
      />
    </div>
  </div>
</template>
<script>
import { onMounted, reactive, ref, toRefs } from "vue";
import * as echarts from "echarts";
export default {
  name: "Process",
  props: {
    itemData: Object,
  },

  setup(props) {
    let myChart = null;
    let data = {};
    const state = reactive({});
    onMounted(() => {
      getEchart();
    });
    const getEchart = () => {
      data = {};
      let dom = document.getElementById("process" + props.itemData.id);
      if (dom) {
        myChart = echarts.init(dom);
        loadProcessChart(myChart, data);
      }
    };
    const loadProcessChart = (myChart, data) => {
      console.log(123, myChart);
      var option = {
        grid: {
          top: "0",
          left: "1%",
          right: "10%",
          bottom: "0",
        },
        xAxis: {
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            show: false,
          },
          splitLine: {
            show: false,
          },
        },
        yAxis: [
          {
            data: ["水"],
            inverse: true,
            splitLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            axisLine: {
              show: false,
            },
            axisLabel: {
              color: "#fff",
              fontSize: 18,
            },
          },
          {
            type: "category",
            axisTick: { show: false }, // 不显示刻度线
            axisLabel: {
              color: "#000",
            },
            axisLine: {
              show: false,
            },
            inverse: true,
          },
        ],
        series: [
          {
            name: "进度条",
            yAxisIndex: 0,
            type: "pictorialBar",
            symbol: "rect", // 长方形
            symbolRepeat: "fixed",
            symbolMargin: "0", // 缝隙
            symbolClip: true,
            symbolSize: ["3", "16"],
            barCategoryGap: 50,
            label: {
              show: true,
              position: [0, 50],
              fontSize: 14,
              formatter: "水(m³)",
            },
            zlevel: 1, //  zlevel 大的 Canvas 会放在 zlevel 小的 Canvas 的上面
            data: [
              {
                value: 780,
                itemStyle: {
                  normal: {
                    color: "#047CFF",
                  },
                },
              },
            ],
          },
          {
            name: "进度条背景",
            type: "bar",
            yAxisIndex: 1,
            barGap: "-100%", // 不同系列的柱间距离，为百分比。
            barCategoryGap: 5,
            barWidth: 20,
            left: "50",
            data: [1000],
            color: "#00baff", // 柱条颜色
            itemStyle: {
              normal: {
                color: function (params) {
                  return '#fff';
                },
                barBorderRadius: [10], //设置圆角
              },
            },
            label: {
              normal: {
                show: true, // 是否显示进度条上方的百分比
                formatter: (series) => "780/1000",
                position: [913, -20],
                textStyle: {
                  color: "#000", // 进度条上方百分比字体颜色
                  fontSize: 14,
                },
              },
            },
          },
        ],
      };
      myChart.setOption(option);
    };
    return {
      ...toRefs(state),
      getEchart,
      loadProcessChart
    };
  },
};
</script>
<style lang="scss" scoped>
.process-div {
  display: flex;
  justify-content: space-between;
  height: 50px;
  align-items: center;
  margin: 10px 0;
  .process-echart {
    width: 83%;
  }
}
</style>
