<template>
  <div class="catering">
    <!-- 标题区域 -->
    <div class="catering_title">景区餐饮</div>

    <!-- 图表盒子区域 -->
    <div class="catering_box">
      <div class="box_title">
        <div class="title_text">类型统计</div>
        <img src="@/assets/images/33.png" />
      </div>
      <div class="box_chart" ref="barChart"></div>
    </div>
  </div>
</template>

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

// 柱状图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: "3%",
      containLabel: true,
    },
    xAxis: {
      type: "category",
      axisLabel: {
        color: "#A2C7FF",
        fontSize: 16,
      },
      axisTick: {
        show: false,
      },
      axisLine: {
        lineStyle: {
          color: "#063F8B",
        },
      },
      data: ["中餐", "西餐", "小吃", "小卖部", "其他"],
    },
    yAxis: {
      type: "value",
      splitLine: {
        show: false,
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: "#063F8B",
        },
      },
      axisLabel: {
        color: "#A2C7FF",
        fontSize: 16,
      },
    },
    series: [
      {
        data: [120, 200, 150, 80, 70],
        type: "bar",
        barWidth: 35,
        itemStyle: {
          color: new Echarts.graphic.LinearGradient(0, 0, 0, 1, [
            { offset: 0, color: "rgba(10, 140, 240, 1)" },
            { offset: 0.9, color: "rgba(10, 140, 240, 0)" },
            { offset: 1, color: "rgba(10, 140, 240, 0)" },
          ]),
        },
      },
    ],
  };
  myBarChart.setOption(options);
};
</script>

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

  .catering_title {
    padding-left: 45px;
    width: 100%;
    height: 48px;
    font-size: 28px;
    font-family: "庞门正道标题体";
    background-image: url(@/assets/images/34.png);
    background-size: 100% 100%;
  }
  .catering_box {
    margin-top: 24px;
    padding-left: 46px;
    padding-top: 26px;
    width: 100%;
    height: 368px;
    background-image: url(@/assets/images/9.png);
    background-size: 100% 100%;

    .box_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;
      }
    }

    .box_chart {
      width: 515px;
      height: 294px;
    }
  }
}
</style>
