<template>
  <div class="bottom_utils">
    <div class="items">
      <div
        v-for="(item, index) in list"
        :key="index"
        :class="['item', { active: current === item.name }]"
        @click="router.push({ name: '/index', params: { type: item.name } })"
      >
        {{ item.name }}
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter, onBeforeRouteUpdate, useRoute } from "vue-router";

const router = useRouter();
const route = useRoute();
const current = ref(route.params.type || "降雨量");
const list = [
  { name: "降雨量" },
  { name: "河流" },
  { name: "水库" },
  { name: "地质灾害点" },
  { name: "城市防涝" },
  { name: "山洪灾害村" },
  { name: "尾矿库" },
];
onBeforeRouteUpdate((to) => {
  current.value = to.params.type;
});
</script>

<style scoped lang="scss">
.bottom_utils {
  position: absolute;
  bottom: 20px;
  left: 500px;
  right: 500px;

  .items {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .item {
      width: 122px;
      height: 46px;
      line-height: 40px;
      text-align: center;
      cursor: pointer;
      background-image: url("/src/assets/images/map/listbg1.png");
      color: #fff;
      font-weight: bold;
      font-size: 16px;

      &.active {
        background-image: url("/src/assets/images/map/listbg2.png");
      }
    }
  }
}
</style>
