<template>
  <scroll-bar class="side-bar">
    <ul class="nav-list">
      <li class="nav-item" v-for="(nav, navNo) in menus" :key="navNo">
        <p class="nav-item-content">
          <i :class="['icon', `${nav.icon}`]"></i>
          <span>{{ nav.title }}</span>
          <span></span>
        </p>
        <ul class="nav-sublist">
          <li
            v-for="(subnav, subNo) in nav.children"
            :key="subNo"
            :class="[
              'nav-sub-item',
              { 'nav-item-act': subnav.name === curRouterName },
            ]"
          >
            <p @click="toRouter(subnav)">
              <span>{{ subnav.title }}</span>
              <span></span>
            </p>
          </li>
        </ul>
      </li>
    </ul>
  </scroll-bar>
</template>

<script>
import ScrollBar from "./ScrollBar";

export default {
  name: "SideBar",
  components: { ScrollBar },
  props: {
    menus: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      curRouterName: this.$route.meta.relate || this.$route.name,
    };
  },
  methods: {
    toRouter(nav) {
      this.curRouterName = nav.name;
      this.$router.push({ name: nav.name });
    },
  },
};
</script>

<style lang="scss" scoped>
.side-bar {
  line-height: 20px;
  font-size: 14px;
  p {
    margin: 0;
  }
  li {
    list-style: none;
  }
}
.nav-list {
  padding: 30px;
  margin: 0;
}
.nav-item {
  margin-bottom: 24px;
  font-weight: 400;

  &-content {
    padding: 6px 0;
    margin: 0;
    color: #202b4b;
    font-weight: 600;

    > * {
      display: inline-block;
      vertical-align: middle;
    }
    > i {
      margin-right: 10px;
    }
  }
}
.nav-sublist {
  padding-left: 26px;
  color: #626a82;
  .nav-sub-item {
    padding: 6px 0;
    font-weight: 400;
    cursor: pointer;

    &:hover {
      color: #1886fe;
    }
  }

  .nav-item-act {
    color: #1886fe;
    font-weight: 600;
  }
}
</style>
