<template>
  <div class="side_nav_bar apaas_scroll">
    <h3 class="side_nav_bar_title" @click="titleAction">
      <img :src="titleIcon" width="20" style="margin-right: 10px;" />
      <span v-text="title"></span>
    </h3>
    <ul class="side_nav_bar_list">
      <!-- active-class="current" -->
      <template v-for="(nav, index) in navList">
        <li v-if="nav.children && nav.children.length" :key="'nav_' + index">
          <a class="text_clip toggle_bar" @click.prevent="toggleNav(nav)">
            {{ nav.name }}

            <i
              :class="nav.open ? 'el-icon-arrow-down' : 'el-icon-arrow-right'"
            ></i>
          </a>
          <ul class="second_list" v-show="nav.open">
            <li v-for="(v, i) in nav.children" :key="'nav_' + index + 'v_' + i">
              <router-link
                class="text_clip"
                :class="{ current: $route.path.indexOf(v.path) > -1 }"
                :to="v.path"
              >
                {{ v.name }}
              </router-link>
            </li>
          </ul>
        </li>
        <li v-else-if="nav.disabled" :key="'nav_' + index">
          <a class="disabled text_clip">
            {{ nav.name }}
          </a>
        </li>
        <li v-else :key="'nav_' + index">
          <router-link
            class="text_clip"
            :class="{ current: $route.path.indexOf(nav.path) > -1 }"
            :to="nav.path"
          >
            {{ nav.name }}
          </router-link>
        </li>
      </template>
    </ul>
  </div>
</template>

<script>
export default {
  name: "sideNavBar",
  props: {
    title: {
      type: String,
      default: () => "我的服务",
    },
    titleIcon: {
      type: String,
      default: () => require("../assets/imgs/tool_fuwu.png"),
    },
    titlePath: {
      type: String,
      default: () => "",
    },
    navList: {
      type: Array,
      default: () => [],
    },
    imgSrc: {
      type: String,
      default: "tool_fuwu",
    },
  },
  methods: {
    titleAction() {
      if (this.titlePath) {
        this.$router.push(this.titlePath);
      }
    },
    toggleNav(nav) {
      this.$set(nav, "open", !nav.open);
    },
  },
};
</script>

<style scoped>
.side_nav_bar {
  background-color: #0d1847;
  overflow-x: hidden;
  overflow-y: auto;
}
.side_nav_bar_title {
  height: 40px;
  background-color: #182665;
  border-radius: 10px;
  overflow: hidden;
  margin: 20px 15px 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
.side_nav_bar_title > span {
  font-size: 16px;
  color: #c3caf8;
}
.side_nav_bar_list > li > a {
  display: block;
  padding: 12px 10px 12px 42px;
  border-left: 5px solid #0d1847;
  font-size: 14px;
  font-weight: bold;
  line-height: 24px;
  color: #e6ebfe;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
}
.side_nav_bar_list > li > a.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.side_nav_bar_list > li > a:hover,
.side_nav_bar_list > li > a.current {
  border-left: 5px solid #e56600;
  background-color: #182665;
  color: #e6ebfe;
}
.toggle_bar {
  padding-right: 30px !important;
  position: relative;
}
.toggle_bar > i {
  position: absolute;
  top: 16px;
  right: 8px;
}
.second_list > li > a {
  display: block;
  padding: 12px 10px 12px 56px;
  border-left: 5px solid #0d1847;
  font-size: 14px;
  line-height: 24px;
  color: #6573ae;
  text-decoration: none;
}
.second_list > li > a:hover,
.second_list > li > a.current {
  border-left: 5px solid #e56600;
  background-color: #182665;
  color: #e6ebfe;
}
</style>
