<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useJidiSelectEventStore } from "@/store/modules/jidiSelectEvent";
const loading = ref(false);
const isOpen = ref(true);
const JidiSelectEventStore = useJidiSelectEventStore();

const jidiDataNum = ref(9);
const itemClick = (index: any) => {
  useJidiSelectEventStore().updataJidiData(index);
};
onMounted(() => {});
</script>

<template>
  <div class="jidiSelectorMod">
    <a-spin :spinning="loading">
      <div
        class="qgc-dropdown-select"
        @mouseenter="jidiDataNum = JidiSelectEventStore.jidiData.length"
        @mouseleave="jidiDataNum = 9"
      >
        <div class="title" @click="isOpen = !isOpen">
          <div>水电基地</div>
          <div
            style="padding-right: 5px"
            :style="{ transform: !isOpen ? 'rotate(180deg)' : 'rotate(0deg)' }"
          >
            <i class="icon iconfont icon-topOutline"></i>
          </div>
        </div>
        <div
          v-if="isOpen"
          class="item"
          v-for="(i, index) in JidiSelectEventStore.jidiData.slice(0, jidiDataNum)"
          :class="{ selected: i.selected }"
          @click="itemClick(index)"
        >
          <i class="icon iconfont icon-hydroPower"></i>
          <span style="margin-left: 10px">{{ i.wbsName }}</span>
        </div>
      </div>
    </a-spin>
  </div>
</template>
<style scoped lang="scss">
@use "@/styles/variables.module.scss" as *;
.jidiSelectorMod {
  width: 175px;
  max-height: 941px;
  border: 1px solid #cedce8;
  border-radius: 1px;
  background-color: #e5edf3;
  padding: 4px;
  position: relative;
  border-radius: 1px;
  margin: 16px 0 0 16px;
  z-index: 99;
  pointer-events: auto;
  .qgc-dropdown-select {
    width: 100%;
    max-height: 941px;
    overflow: auto;
    .title {
      height: 26.14px;
      padding: 0 2px;
      font-size: 16px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      font-size: 16px;
      color: $primary-title-color;
      cursor: pointer;

      .icon-topOutline {
        display: inline-block;
        width: 12px;
        height: 12px;
        font-size: 12px;
        scale: 0.6;
        position: relative;
        top: -3px;
      }
    }

    .item {
      margin: 4px 0;
      border-radius: 2px;
      box-sizing: border-box;
      border: 1px solid #acc4d6;
      line-height: 30px;
      padding: 0 8px;
      font-size: 14px;
      background-color: #fff;
      transition: background-color 0.3s, color 0.3s;
      cursor: pointer;
      &:hover,
      &.selected {
        background-color: #2f6b98;
        color: #fff;
      }
    }
  }
}
</style>
