<template>
  <div class="box-item">
    <el-menu
      class="el-menu-vertical-demo"
      text-color="#fff"
      active-color="#000"
      :default-active="activeIndex"
      :collapse="menuClose"
      @select="handleSelect"
    >
      <!-- <div class="logo">logo</div> -->
      <div class="logo el-menu-item">
        <el-icon :size="20"
          ><img src="@/assets/logo.png" style="width: 30px; height: 24px"
        /></el-icon>
      </div>
      <el-menu-item :index="9">
        <img
          v-if="activeIndex == 9"
          src="@/assets/busqueryA.png"
          alt=""
          style="width: 22px; height: 22px; margin: 0 18px"
        />
        <img
          v-else
          src="@/assets/busquery.png "
          alt=""
          style="width: 22px; height: 22px; margin: 0 18px"
        />
        <span>车辆调度</span>
      </el-menu-item>
      <el-menu-item :index="1">
        <img v-if="activeIndex == 1" src="@/assets/statementA.png" alt="" />
        <img v-else src="@/assets/statement.png " alt="" />
        <span>报表统计</span>
      </el-menu-item>
      <el-menu-item :index="2">
        <img v-if="activeIndex == 2" src="@/assets/staffA.png" alt="" />
        <img v-else src="@/assets/staff.png" alt="" />
        <span>驾驶员管理</span>
      </el-menu-item>
      <el-menu-item :index="11">
        <img
          v-if="activeIndex == 11"
          style="width: 22px; height: 22px; margin: 0 20px 0 18px"
          src="@/assets/reportA.png"
          alt=""
        />
        <img
          v-else
          style="width: 22px; height: 22px; margin: 0 20px 0 18px"
          src="@/assets/report.png"
          alt=""
        />
        <span>报备管理</span>
      </el-menu-item>
      <el-menu-item :index="3">
        <img v-if="activeIndex == 3" src="@/assets/accountA.png" alt="" />
        <img v-else src="@/assets/account.png" alt="" />
        <span>账号管理</span>
      </el-menu-item>
      <el-menu-item :index="4">
        <img v-if="activeIndex == 4" src="@/assets/carA.png" alt="" />
        <img v-else src="@/assets/car.png" alt="" />
        <span>车辆管理</span>
      </el-menu-item>
      <el-menu-item :index="5">
        <img v-if="activeIndex == 5" src="@/assets/pathA.png" alt="" />
        <img v-else src="@/assets/path.png" alt="" />
        <span>路线管理</span>
      </el-menu-item>
      <el-menu-item :index="6">
        <img v-if="activeIndex == 6" src="@/assets/classesA.png" alt="" />
        <img v-else src="@/assets/classes.png" alt="" />
        <span>班次管理</span>
      </el-menu-item>
      <el-menu-item :index="7">
        <img v-if="activeIndex == 7" src="@/assets/blacklistA.png" alt="" />
        <img v-else src="@/assets/blacklist.png" alt="" />
        <span>黑名单管理</span>
      </el-menu-item>
      <el-menu-item :index="10">
        <img
          v-if="activeIndex == 10"
          src="@/assets/logA.png"
          alt=""
          style="width: 21px; height: 21px; margin: 0 20px"
        />
        <img
          v-else
          src="@/assets/log.png"
          alt=""
          style="width: 21px; height: 21px; margin: 0 20px"
        />
        <span>操作日志</span>
      </el-menu-item>
      <el-menu-item :index="8">
        <img
          v-if="activeIndex == 8"
          src="@/assets/systemA.png"
          alt=""
          style="width: 20px; height: 20px"
        />
        <img
          v-else
          src="@/assets/system.png"
          alt=""
          style="width: 20px; height: 20px"
        />
        <span>系统设置</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script setup>
import { ref, onBeforeMount, onMounted, watch, reactive } from "vue";
import { useStore } from "vuex";

import { useRouter } from "vue-router";

const store = useStore();
const router = useRouter();

const menuClose = ref(false);
const activeIndex = ref(9);
const acitveItems = reactive({ list: [] });

watch(
  () => store.state.user.collapse,
  (newValue, oldValue) => {
    menuClose.value = newValue;
  }
);
watch(
  () => store.state.user.activeIndex,
  (newValue, oldValue) => {
    console.log(newValue);

    activeIndex.value = newValue;
  }
);

const handleSelect = (key) => {
  store.commit("indexUp", key);
  activeIndex.value = key;
  sessionStorage.setItem("sidevarItem", key);

  if (activeIndex.value == 1) {
    router.push({
      path: `/schoolBus/statement`,
    });
  }
  if (activeIndex.value == 2) {
    router.push({
      path: `/schoolBus/staff`,
    });
  }
  if (activeIndex.value == 3) {
    router.push({
      path: `/schoolBus/account`,
    });
  }
  if (activeIndex.value == 4) {
    router.push({
      path: `/schoolBus/bus`,
    });
  }
  if (activeIndex.value == 6) {
    router.push({
      path: `/schoolBus/classes`,
    });
  }
  if (activeIndex.value == 5) {
    router.push({
      path: `/schoolBus/buspath`,
    });
  }
  if (activeIndex.value == 8) {
    router.push({
      path: `/schoolBus/system`,
    });
  }
  if (activeIndex.value == 7) {
    router.push({
      path: `/schoolBus/blacklist`,
    });
  }
  if (activeIndex.value == 9) {
    router.push({
      path: `/schoolBus/busquery`,
    });
  }
  if (activeIndex.value == 10) {
    router.push({
      path: `/schoolBus/log`,
    });
  }
  if (activeIndex.value == 11) {
    router.push({
      path: `/schoolBus/report`,
    });
  }
  if (activeIndex.value == 0) {
    router.push({
      path: `/schoolBus/news`,
    });
  }
};
onBeforeMount(() => {
  activeIndex.value = Number(sessionStorage.getItem("sidevarItem"));
  store.commit("indexUp", Number(sessionStorage.getItem("sidevarItem")));
});
</script>

<style lang="scss" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  // min-height: 400px;
}
.el-menu {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    0deg,
    rgba(134, 132, 255, 1) 0%,
    rgba(60, 80, 232, 1) 100%
  );
  box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.16);

  .logo {
    height: 65px;
    color: rgb(255, 255, 255);
    cursor: default;
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
  .logo:hover {
    background-color: transparent !important;
  }
  .el-menu-item {
    // border-left: 3px solid rgba(248, 220, 38);
    padding: 0 10px;
  }
  .el-menu-item:hover {
    background-color: rgba(255, 255, 255, 0.4);
  }
  .el-menu-item.is-active:hover {
    background-color: #fff;
  }
  .el-menu-item img {
    width: 18px;
    height: 18px;
    margin: 0 20px;
  }
}

.el-menu-item.is-active {
  box-sizing: border-box;
  background-color: #fff;
  color: #000;
}
</style>
