<template>
  <div class="trend">
    <!-- 标题区域 -->
    <div class="trend_title">
      <div class="title_text">近7天房间预定趋势</div>
      <img src="@/assets/images/33.png" />
    </div>

    <!-- 柱状图区域 -->
    <div class="trend_bar" ref="barChart"></div>
  </div>
</template>

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

// 柱状图DOM元素
const barChart = ref(null);

onMounted(() => {
  // 初始化柱状图
  initBarChart();
});

const initBarChart = () => {
  let myBarChart = Echarts.init(barChart.value);
  // 柱状图配置
  const options = {
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow",
      },
    },
    grid: {
      left: "1%",
      right: "4%",
      top: "15%",
      bottom: "16%",
      containLabel: true,
    },
    xAxis: {
      type: "category",
      axisLabel: {
        color: "#fff",
      },
      data: getNearDay(7),
    },
    yAxis: {
      type: "value",
      splitLine: {
        show: false,
      },
      axisLabel: {
        color: "#fff",
      },
    },
    series: [
      {
        data: [120, 200, 150, 80, 70, 110, 130],
        type: "bar",
        barWidth: 35,
        showBackground: true,
        itemStyle: {
          color: new Echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: "rgba(56, 114, 161, 1)" },
            { offset: 1, color: "rgba(16, 40, 54, 0.1)" },
          ]),
        },
      },
    ],
  };
  myBarChart.setOption(options);
};
</script>

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

  .trend_title {
    position: relative;
    margin-top: 31px;
    width: 548px;
    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: 548px;
      height: 16px;
    }
  }

  .trend_bar {
    width: 548px;
    height: 350px;
  }
}
</style>
