<template>
  <view style="height: 350upx">
    <l-echart ref="detailedChart"></l-echart>
  </view>
</template>

<script setup>
import * as echarts from "echarts";
import { onLoad, onShow, onHide, onLaunch, onResize } from "@dcloudio/uni-app";
import { defineComponent, ref, onMounted, nextTick } from "vue";

const props = defineProps({
  xAxisDataList: {
    type: Object,
    default: null,
  },
  seriesDataList: {
    type: Object,
    default: null,
  },
});

let myChart;
const detailedChart = ref(null);

let option = {
  tooltip: {
    trigger: "axis",
  },
  legend: {
    show: false,
    // data: ["邮件营销"],
  },
  grid: {
    top: "8%",
    left: "3%",
    right: "4%",
    bottom: "3%",
    containLabel: true,
  },
  xAxis: {
    type: "category",
    boundaryGap: false,
    axisLabel: {
      color: "rgba(0,0,0,0.2)",
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: "rgba(0,0,0,0.1)",
      },
    },
    axisTick: {
      show: false,
    },
    data: props.xAxisDataList,
  },
  yAxis: {
    type: "value",
    axisLabel: {
      color: "rgba(0,0,0,0.2)",
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: "rgba(0,0,0,0.1)",
      },
    },
    splitLine: {
      lineStyle: {
        color: "rgba(0,0,0,0.1)",
      },
    },
  },
  series: [
    {
      name: "指数",
      type: "line",
      stack: "总量",
      smooth: true,
      itemStyle: {
        color: "rgba(73, 185, 245, 1)",
      },
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          {
            offset: 0,
            color: "rgba(73, 185, 245, 1)",
          },
          {
            offset: 1,
            color: "rgba(73, 185, 245, 0.3)",
          },
        ]),
      },
      data: props.seriesDataList,
    },
  ],
};

function initEcharts() {
  myChart = detailedChart.value;
  myChart.init(echarts, (myChart) => {
    myChart.setOption(option);
  });
}

onLoad(() => {
  nextTick(() => {
    initEcharts();
  });
});

onResize(() => {
  myChart.resize();
});
</script>
