<template>
  <el-dialog
    width="70%"
    @open="opened()"
    @closed="closed()"
    :show-close="true"
    class="dialogs"
  >
    <template #title>
      <div class="showTitles">
        <div class="stationName">
          <div class="titleName">{{ showData?.name?.name }}</div>
          <div class="titleNames" v-if="showData?.name?.names">
            ({{ showData?.name?.names }})
          </div>
        </div>
      </div>
    </template>
    <div class="bodyy">
      <div id="showEcharts" class="echarts"></div>
    </div>
  </el-dialog>
</template>
<script>
import * as echarts from "echarts";
export default {
  props: {
    showData: {
      type: String,
      default: "",
    },
  },
  updated() {
    this.showEcharts(this.showData);
  },
  methods: {
    showEcharts(showData) {
      let chartDom = document.getElementById("showEcharts");
      let myChart = echarts.init(chartDom, "#ffffff");
      let option;
      option = {
        tooltip: {
          trigger: "axis",
        },
        legend: {
          show: true,
          data: showData.value.map((t) => {
            return t.title;
          }),
          right: 56,
          icon: "circle",
          itemWidth: 6,
          inactiveColor: "#606769",
          textStyle: {
            color: "#B3BDC0",
            fontSize: 12,
          },
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            axisLabel: {
              interval: 60,
              showMinLabel: true,
              showMaxLabel: true,
              formatter: "{value}",
              fontSize: 14,
              textStyle: {
                color: "#606769",
              },
            },
            axisLine: {
              show: false,
            },
            data: showData.value[0].value.map((item) => {
              return item.text;
            }),
          },
        ],
        yAxis: {
          type: "value",
          axisLabel: {
            formatter: "{value}",
            fontSize: 14,
          },
          axisLine: {
            show: false,
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#606769",
              type: "dashed",
            },
          },
        },
        series: [
          {
            name: showData.value[0].title,
            smooth: true,
            showSymbol: false,
            data: showData.value[0].value.map((item) => {
              return item.value;
            }),
            type: "line",
            lineStyle: {
              normal: {
                color: "rgba(75, 85, 174, 1)",
                width: 1,
              },
            },
          },
          {
            name: showData.value[1].title,
            smooth: true,
            showSymbol: false,
            data: showData.value[1].value.map((item) => {
              return item.value;
            }),
            type: "line",
            lineStyle: {
              normal: {
                color: "rgba(05, 187, 76, 1)",
                width: 1,
              },
            },
          },
        ],
      };
      option && myChart.setOption(option);
    },
    opened() {},
    closed() {
      this.$emit("closeds");
    },
  },
};
</script>
<style scoped>
.echarts {
  width: 1300px;
  height: 60vh;
}

.stationName {
  font-size: 20px;
  width: 400px;
  height: 45px;
  display: flex;
  flex-direction: row;
  align-items: baseline;
  justify-content: center;
  color: #ffffff;
}

.titleName {
  margin-top: 10px;
}

.titleNames {
  font-size: 12px;
  margin-left: 10px;
  margin-top: 10px;
}
</style>