<template>
  <div class="yygl_container">
    <side-nav-bar
      :nav-list="navList"
      title="我的应用"
      :title-icon="require('@/assets/imgs/tool_yingyong.png')"
      :title-path="navList[0] && navList[0].path"
    ></side-nav-bar>
    <div class="main_container">
      <router-view
        :key="'type_' + $route.params.level + '_' + $route.params.type"
      ></router-view>
    </div>
  </div>
</template>

<script>
import sideNavBar from "@/components/side-nav-bar";
import { mapState } from "vuex";

export default {
  components: {
    sideNavBar,
  },
  data: () => ({
    navList: [],
  }),
  computed: {
    ...mapState({
      yyglNav: "yyglNav",
    }),
  },
  watch: {
    "$route.fullPath"(path) {
      this.initNavList();
    },
  },
  methods: {
    initNavList() {
      let level = parseInt(this.$route.params.level);

      this.navList = this.yyglNav[level].map((item, index) => ({
        name: item,
        path: `/yygl/${level}/${index}`,
      }));
    },
  },
  mounted() {
    this.initNavList();
  },
};
</script>

<style scoped>
.yygl_container {
  height: calc(100vh - 58px);
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
}
.side_nav_bar {
  width: 180px;
  flex-shrink: 0;
}
.main_container {
  width: calc(100% - 180px);
  flex-grow: 1;
  flex-shrink: 1;
  background-color: #f6f7fb;
  overflow: auto;
}
</style>
