<template>
  <div class="sign_box">
    <div class="sign_item" :class="{active: activeMenu.includes((item.path||item.redirect))}" 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;
        // }
        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: 12px;
    width: calc(100% - 160px);
    overflow-x: scroll;
     white-space: nowrap;


    .sign_item {
      cursor: pointer;
      float: left;
      display: inline-table;
      height: 50px;
      text-align: center;
      line-height: 50px;
      position: relative;
      width: 143px;
      box-sizing: border-box;
      color: #fff;

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

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

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

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