<template>
  <div class="sign_box">
    <div class="sign_item" v-for="item in this.sidebarRouters.filter(res => {
          return res.hidden == false || res.redirect == 'index'
        })"
      @click="tabBtn(item)">
      <img src="@/assets/images/pic_tabbg@2x.png" draggable="false" v-show="activeMenu.includes((item.path||item.redirect))"
        alt="" class="img">
      <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
      <item v-if="!item.meta" :icon="item.meta && item.meta.icon" :title="'首页'" />
    </div>
  </div>
</template>

<script>
  import {
    mapGetters,
    mapState
  } from "vuex";
  import Item from '@/layout/components/Sidebar/Item'

  export default {
    data() {
      return {
        indexs: 1,
        newArr: [],
      }
    },
    components: {
      Item
    },
    computed: {
      ...mapGetters(["sidebarRouters", "sidebar", "tabIndex"]),
      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;
        // }
        console.log(this.tabIndex, 887)
        return this.tabIndex;
      },
    },
    mounted() {
      this.init()
    },
    watch: {

    },
    methods: {
      tabBtn(item) {
        if(this.activeMenu.includes((item.path||item.redirect))){
          return
        }
        if (item.redirect == 'index') {
          if(this.$route.path!=='/index'){
            this.$router.push({
              path: '/index'
            })
          }
          this.$store.dispatch('TabFn', item.redirect)
          return
        }
        this.$store.dispatch('TabFn', item.path)
      },
      init() {
        const route = this.$route;
        const {
          meta,
          path
        } = route;
        // if set path, the sidebar will highlight the path you set
        console.log(route)
        if (meta.activeMenu) {
          this.$store.dispatch('TabFn', meta.activeMenu)
        }
        this.$store.dispatch('TabFn', path)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .sign_box {
    padding-left: 52px;

    .sign_item {
      cursor: pointer;
      float: left;
      display: flex;
      height: 60px;
      justify-content: center;
      align-items: center;
      position: relative;
      width: 153px;
      padding-top: 10px;
      box-sizing: border-box;
      color: #fff;

      .img {
        width: 153px;
        height: 48px;
        position: absolute;
        left: 0;
        bottom: 0;
      }

      .icon {
        position: relative;
        z-index: 1;
        width: 20px;
        height: 20px;
        margin-right: 8px;
      }

      span {
        position: relative;
        z-index: 1;
        color: #fff !important;
        font-size: 17px !important;
      }

      svg {
        color: #fff !important;
        z-index: 2;
        line-height: 1;
        margin-right: 5px;
      }
    }
  }
</style>
