<template>
  <div class="navbar">

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { Breadcrumb, Hamburger, ErrorLog, Screenfull, SizeSelect, Search } from '@/components'
import { getUnReadCounter } from '@/api/system/msgApi'
import { isNotNull } from '@/utils'

export default {
  name: 'NaveBarComponent',
  data() {
    return {
      logo: require('@/assets/images/logo/logo3.png'),
    }
  },
  computed: {
    ...mapGetters([
      'device',
      'sidebar',
      'avatar',
      'userData',
      'permission_routes',
      'menuSiderTab',
      'permits'
    ]),
    hideMenuBt() {
      return this.permission_routes.filter(item => !item.hidden).length < 1
    }
  },
  watch: {
    menuSideTab(val) {
      const item = this.sideMenuTabList[val]
      this.sideTabChange(val, item)
    },
    $route() {
      localStorage.setItem('sidepath', this.$route.path)
    }
  },
  mounted() {
    this.getUnReadMsg()
    this.initSideMenu()
    this.initSideTab()
  },
  methods: {
    getUnReadMsg() {
      getUnReadCounter().then((resp) => {
        this.unReadCount = resp.data
      })
    },
    initSideMenu() {
      const permits = JSON.parse(JSON.stringify(this.permits))
      let sideMenuTabList = JSON.parse(JSON.stringify(this.sideMenuTabList))
      sideMenuTabList = sideMenuTabList.filter(item => permits.includes(item.permit))
      this.sideMenuTabList = sideMenuTabList
    },
    initSideTab() {
      if (!this.sideMenuTabList[0]) return
      let id = this.sideMenuTabList[0].id
      if (isNotNull(localStorage.getItem('aqpt_tabId'))) {
        id = parseFloat(localStorage.getItem('aqpt_tabId'))
      }
      if (this.sideMenuTabList.length < 1) return
      this.sideTabChange(id, {
        path: localStorage.getItem('sidepath') || this.sideMenuTabList.filter(item => item.id === id)[0].path
      })
    },
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },

    navToPage(path) {
      this.$emit('initMessage')
    },

    async logout() {
      localStorage.clear() // 垃圾数据清除
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    },
    sideTabChange(index, item) {
      this.sideMenuTabIndex = index
      this.$router.replace({
        path: item.path
      })
      localStorage.setItem('aqpt_tabId', index)
      let permission_routes = localStorage.getItem('aqpt_permission_routes')
      if (permission_routes) { permission_routes = JSON.parse(permission_routes) } else {
        permission_routes = this.permission_routes
        localStorage.setItem('aqpt_permission_routes', JSON.stringify(permission_routes))
      }
      // 获取权限路由，根据groupId进行过滤
      const filterRoutes = permission_routes.filter((item) => {
        if (item.groupId) {
          return item.groupId.includes(index)
        }
        return item
      })
      this.$store.state.permission.routes = filterRoutes
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  height: var(--navHeight);
  // overflow: auto;
  background: unset;
  box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
  border-bottom: 1px solid #457486;
  position: fixed;
  width: 100%;
  z-index: 999;
  left: 0;
  box-sizing: border-box;
  background-color: var(--menuBg, #113144);
  top: 0;
  display: flex;
  .sys-name{
    height: 100%;
    display: flex;
    align-items: center;
    float: left;
    padding-left: 10px;
    color: #fff;
    #nav-logo{
        display: block;
        height: 40px;
    }

    .breadcrumb-container {
      padding-top:10px;
      float: left;
    }

    .oc-name{
      font-size: 16px;
      line-height: 1;
      font-weight: 400;
      padding-left: 5px;
      margin-top: 8px;
      white-space:nowrap;
      &.authorization{
        font-size: 12px;
        margin-top: 15px;
        color: #a33e3e;
        // color: rgba(255, 255, 255, 0.7);
      }
    }

    .hamburger-container {
      padding: 7px;
      text-align: center;
      line-height: var(--navHeight);
      height: 100%;
      font-size: 16px;
      float: left;
      color: rgb(195, 229, 241) !important;
      cursor: pointer;
      transition: background .3s;
      -webkit-tap-highlight-color:transparent;

      &:hover {
        background: rgba(0, 0, 0, .025)
      }
    }
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }
  .center.flex{
    flex: 1;
  }
  .right-menu {
    float: right;
    // width: calc(100% - 500px);
    height: 100%;
    line-height: var(--navHeight);
    display: flex;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #fff;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background .3s;

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 12px;
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 14px;
        }
      }
    }
    .sideMenuTab{
        height: 100%;
        display: flex;
        justify-content: flex-start;
        padding-right: 20px;
      .item{
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        color: #ccc;
        line-height: 1;
        font-weight: 600;
        padding: 0 15px;
        cursor: pointer;
        transition: 0.2s;
        p{
          white-space:nowrap;
        }
        &.active-0{color: #1890ff;font-weight: 600;}
        &.active-1{color: #b97741;font-weight: 600;}
        &.active-2{color: #97cd38;font-weight: 600;}
        &.active-3 {color: #dc5a2c;font-weight: 600;}
        &.active-4{color: #414ab9;font-weight: 600;}
        &.active-5{color: #c13ac9;font-weight: 600;}
        &.active-6{color: #29c761;font-weight: 600;}
        &.active-7 {color: #c7795c;font-weight: 600;}
        &.active-8{color: #bd966f;font-weight: 600;}
        &.active-9{color: #832188;font-weight: 600;}
        &.active-10{color: #66db8f;font-weight: 600;}
        .iconfont{
          color: inherit;
        }
        .iconfont{
          font-size: 36px;
          &.el-icon-s-platform{
                font-family: "element-icons" !important;
          }
          &.icon-common_health{
            font-size: 28px;
          }
        }
        p{
          padding-top: 3px;
          margin: 2px 0px;
          font-size: 14px;
          color: #ccc;
        }
      }
    }
  }
}
</style>
