<template>
  <div class="parking_scene">
    <!-- 标题区域 -->
    <div class="title">
      <div class="title_text">各停车场实况</div>
      <img src="@/assets/images/33.png" />
    </div>

    <!-- 内容区域 -->
    <div class="content">
      <!-- 选择地点筛选框区域 -->
      <div class="content_search">
        <div class="search_box">
          <el-select v-model="placeValue" placeholder="请选择地点">
            <el-option
              v-for="(item, index) in options"
              :key="index"
              :label="item"
              :value="item"
            />
          </el-select>
        </div>
      </div>

      <!-- 信息展示区域 -->
      <div class="content_msg">
        <div class="msg_box time">
          <div class="value">00:00 - 24:00</div>
          <div>开放时间</div>
        </div>
        <div class="msg_box free">
          <div class="value">不免费</div>
          <div>是否免费</div>
        </div>
        <div class="msg_box rate">
          <div class="value">20/150</div>
          <div>当前占用比</div>
        </div>
      </div>

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

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

const placeValue = ref();

const options = ref(["三爪仑风景区", "虎啸峡", "三清山"]);

// 折线图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: "10%",
      containLabel: true,
    },
    xAxis: {
      type: "category",
      boundaryGap: true,
      axisLabel: {
        color: "#fff",
        fontSize: 16,
        margin: 20,
      },
      data: getNearDay(7),
    },
    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: [160, 199, 126, 116, 216, 516, 126, 316],
        type: "line",
        smooth: true,
        color: "#1F92F6",
        tooltip: {
          valueFormatter: function (value: any) {
            return value + "人";
          },
        },
        areaStyle: {
          color: {
            type: "linear",
            x: 0,
            y: 1,
            x2: 0,
            y2: 0,
            colorStops: [
              {
                offset: 0,
                color: "rgba(31, 146, 246, 0)", // 0% 处的颜色
              },
              {
                offset: 1,
                color: "rgba(54, 161, 255, 0.6)", // 100% 处的颜色
              },
            ],
          },
        },
      },
    ],
  };
  myLineChart.setOption(options);
};
</script>

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

  .title {
    position: relative;
    width: 100%;
    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: 100%;
      height: 16px;
    }
  }

  .content {
    width: 100%;
    height: 555px;

    .content_search {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      height: 115px;

      .search_box {
        width: 288px;
        height: 38px;
      }
    }

    .content_msg {
      display: flex;
      justify-content: space-around;
      height: 86px;
      font-size: 16px;
      border: 1px solid rgba(212, 230, 255, 0.1);
      background: linear-gradient(
        90deg,
        rgba(1, 105, 216, 0.12) 0%,
        rgba(1, 105, 216, 0.01) 100%
      );

      .msg_box {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        height: 100%;

        .value {
          margin-bottom: 8px;
          color: #70b7fa;
          font-size: 20px;
        }
      }

      .time {
        width: 145px;
      }

      .free {
        width: 70px;
      }

      .rate {
        width: 80px;
      }
    }

    .content_chart {
      height: 354px;
    }
  }
}

::v-deep(.el-select__wrapper) {
  height: 38px;
  background-color: transparent;
}
</style>
