<template>
  <div :class="{ 'has-logo': showLogo }">
    <logo v-if="showLogo" :collapse="isCollapse" />
    <el-scrollbar wrap-class="scrollbar-wrapper">
      <el-menu
        :default-active="activeMenu"
        :collapse="isCollapse"
        :background-color="variables.menuBg"
        :text-color="variables.menuText"
        :unique-opened="false"
        :active-text-color="variables.menuActiveText"
        :collapse-transition="false"
        :default-openeds="openeds" 
        mode="vertical"
      >
        <sidebar-item
          v-for="route in routes"
          :key="route.path"
          :item="route"
          :base-path="route.path"
        />
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import Logo from "./Logo";
import SidebarItem from "./SidebarItem";
import variables from "@/styles/variables.scss";

export default {
  components: { SidebarItem, Logo },
  computed: {
    ...mapGetters(["sidebar", "menu"]),
    // routes() {
    //   return this.getRoute()
    // },
    activeMenu() {
      const route = this.$route;
      const { meta, path } = route;
      // if set path, the sidebar will highlight the path you set
      if (meta.activeMenu) {
        return meta.activeMenu;
      }
      return path;
    },
    showLogo() {
      return this.$store.state.settings.sidebarLogo;
    },
    variables() {
      return variables;
    },
    isCollapse() {
      return !this.sidebar.opened;
    },
  },
  data() {
    return {
      routes: [],
      openeds:['/business','/system']
    };
  },
  created() {
    this.routes = this.$router.options.routes;
    // this.routes = this.getRoute()
  //   let parentArr = []
  //   for (const key in this.menu) {
  //     parentArr.push(key+'Menu')
  //   }
  //   this.routes.map(item=>{
  //     parentArr.map(pr=>{
  //       if (condition) {
          
  //       }
  //     })
  //   })
  //   console.log('parentArr',parentArr);
  },
  methods: {
    getRoute() {
      let that = this;
      let newMenu = getNewMenu(that.$router.options.routes);
      // 设置需要隐藏的菜单
      function getNewMenu(arr) {
        // debugger
        arr.map((item) => {
          if (!item.name) {
            return;
          } else {
            item.hidden = item.hasOwnProperty("hidden")
              ? item.hidden
              : !that.menu[item.name];
            if (item.children) {
              getNewMenu(item.children);
            }
          }
        });
        return arr;
      }
      return newMenu;
    },
  },
};
</script>
