<template>
  <div class="main-nav">
    <el-menu
      ref="navbar"
      :default-active="activeIndex"
      text-color="#333"
      active-text-color="#1F71FF"
      router
      :default-openeds="openeds"
    >
      <nav-bar-item
        v-for="(item, index) in leftMenu"
        :item="item"
        :navIndex="String(index)"
        :index="index"
        :key="index"
        :class="{'is-active':activeIndex==index}"
      ></nav-bar-item>
    </el-menu>
  </div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
import NavBarItem from './NavBarItem'
import Bus from '../../util/Bus';
export default {
  components: { NavBarItem },
  computed: {
    ...mapGetters([
      'menuMap'
    ])
  },
  data() {
    return {
      activeIndex: '0',
      openeds: ['0', '1', '2'],
      leftMenu: []
    }
  },
  watch: {
  },
  mounted() {
    this.initNav()
    // this.leftMenu = [
    //   {
    //     name: '急救资源',
    //     icon: 'fa-address-book-o',
    //     child: [
    //       { name: '急救车资源', path: '/resources/emergencyCar' },
    //       { name: '急救绿道资源', path: '/resources/greenWay' },
    //       { name: '急诊科抢救资源', path: '/resources/rescue' },
    //       { name: '急诊专家资源', path: '/resources/expert' },
    //       { name: '急救药品耗材资源', path: '/resources/medical' },
    //       { name: '急诊站点资源', path: '/resources/sitePage' }
    //     ]
    //   },
    //   {
    //     name: '业务监管',
    //     icon: 'fa-address-book-o',
    //     child: [
    //       { name: '急救站点查询', path: '/business/siteQuery' },
    //     ]
    //   },
    //   {
    //     name: '基础信息管理',
    //     icon: 'fa-address-book-o',
    //     child: [
    //       { name: '用户管理', path: '/basicInfo/user' },
    //       { name: '菜单管理', path: '/basicInfo/nav' },
    //     ]
    //   }
    // ]
  },
  created() {

  },
  methods: {
    initNav() {
      const navList = []
      this.menuMap.forEach(item => {
        if (item.secondMenuList && item.secondMenuList.length > 0) {
          const child = []
          item.secondMenuList.forEach(_item => {
            child.push({
              name: _item.menuName,
              path: _item.url
            })
          })
          const nav = {
            name: item.menuName,
            child: child
          }
          navList.push(nav)
        }
      });
      this.leftMenu = navList
    }
  },

}
</script>

<style>
</style>
