<template>
  <div class="sale">
    <!-- 标题区域 -->
    <div class="sale_title">
      <div class="title_text">近12月销售额</div>
      <img src="@/assets/images/33.png" />
    </div>

    <!-- 图表区域 -->
    <div class="sale_chart" ref="lineChart"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import * as Echarts from "echarts";
import { getNearMonth } from "@/utils/getNearMonth";

// 折线图DOM元素
const lineChart = ref(null);

onMounted(() => {
  // 初始化折线图
  initLineChart();
});

const initLineChart = () => {
  let myLineChart = Echarts.init(lineChart.value);
  // 折线图配置
  const options = {
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow",
      },
    },
    grid: {
      left: "1%",
      right: "1%",
      top: "20%",
      bottom: "1%",
      containLabel: true,
    },
    xAxis: {
      type: "category",
      boundaryGap: true,
      axisLabel: {
        color: "#fff",
        fontSize: 16,
        margin: 20,
        interval: 0,
      },
      data: getNearMonth(11),
    },
    yAxis: {
      type: "value",
      name: "万元",
      nameTextStyle: {
        color: "#fff",
        fontSize: 16,
      },
      axisLabel: {
        color: "#fff",
        fontSize: 16,
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: ["rgba(255, 255, 255, 0.15)"],
        },
      },
    },
    series: [
      {
        data: [16, 19, 12, 16, 16, 16, 12, 16, 16, 16, 12, 16],
        type: "line",
        smooth: true,
        color: "#FFE0B3",
        tooltip: {
          valueFormatter: function (value: any) {
            return value + "万元";
          },
        },
        areaStyle: {
          color: {
            type: "linear",
            x: 0,
            y: 1,
            x2: 0,
            y2: 0,
            colorStops: [
              {
                offset: 0,
                color: "rgba(255, 224, 179, 0)",
              },
              {
                offset: 1,
                color: "rgba(255, 224, 179, 0.6)",
              },
            ],
          },
        },
      },
    ],
  };
  myLineChart.setOption(options);
};
</script>

<style lang="scss" scoped>
.sale {
  width: 100%;
  height: 100%;

  .sale_title {
    position: relative;
    width: 515px;
    height: 41px;
    line-height: 41px;

    .title_text {
      position: absolute;
      left: 15px;
      z-index: 1;
      font-size: 23.5px;
      font-weight: bold;
      color: #e0efff;
    }

    img {
      position: absolute;
      left: 0;
      bottom: 0;
      width: 515px;
      height: 16px;
    }
  }

  .sale_chart {
    width: 100%;
    height: 280px;
  }
}
</style>
