<template>
  <div class="navbar">
    <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar(0)" />

    <!-- <breadcrumb id="breadcrumb-container" class="breadcrumb-container" /> -->
      <!-- <SignNumArr class="SignNumArr"/> -->
	  <div class="sign_box">
	    <div class="sign_item" :class="{active: activeMenu.includes((item.path||item.redirect))}"  v-for="(item,index) in this.sidebarRouters.filter(res => {
	          return res.hidden == false || res.redirect == 'index'
	        })" :key="index"
	      @click="tabBtn(item)">
	      <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>
    <div class="right-menu">
      <!-- <template v-if="device!=='mobile'">
        <search id="header-search" class="right-menu-item" />

        <el-tooltip content="源码地址" effect="dark" placement="bottom">
          <ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />
        </el-tooltip>

        <el-tooltip content="文档地址" effect="dark" placement="bottom">
          <ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" />
        </el-tooltip>

        <screenfull id="screenfull" class="right-menu-item hover-effect" />

        <el-tooltip content="布局大小" effect="dark" placement="bottom">
          <size-select id="size-select" class="right-menu-item hover-effect" />
        </el-tooltip>

      </template> -->

      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
        <div class="avatar-wrapper">
          <img :src="avatar" class="user-avatar">
		  <span></span>
          <i class="el-icon-caret-bottom" />
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/user/profile">
            <el-dropdown-item>个人中心</el-dropdown-item>
          </router-link>
          <el-dropdown-item @click.native="setting = true">
            <span>布局设置</span>
          </el-dropdown-item>
          <el-dropdown-item >系统人数:<span style="color: #00a8ec;">{{users.allCount}}</span>
            </el-dropdown-item>


            <el-dropdown-item @click.native="nhyel" >在线人数:<span style="color: #00a8ec;">{{users.onlineNum}}</span></el-dropdown-item>

          <el-dropdown-item divided @click.native="logout">
            <span>退出登录</span>
          </el-dropdown-item>

        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapState } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import SignNumArr from '@/components/SignNumArr'
import Hamburger from '@/components/Hamburger'
import Screenfull from '@/components/Screenfull'
import SizeSelect from '@/components/SizeSelect'
import Search from '@/components/HeaderSearch'
import RuoYiGit from '@/components/RuoYi/Git'
import RuoYiDoc from '@/components/RuoYi/Doc'
import Item from '@/layout/components/Sidebar/Item'
import { rensh } from "@/api/system/user";
export default {
	data() {
	  return {
	    indexs: 1,
	    newArr: [],
      showde:true,
      users:{}
	  }
	},
  components: {
    SignNumArr,
    Hamburger,
    Screenfull,
    SizeSelect,
    Search,
    RuoYiGit,
    RuoYiDoc,
	  Item
  },
  mounted() {
	   this.init()
     this.getUserre()
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'device',
	    "sidebarRouters", "sidebar", "tabIndex"
    ]),
    activeMenu() {
      return this.tabIndex;
    },
    setting: {
      get() {
        return this.$store.state.settings.showSettings
      },
      set(val) {
        this.$store.dispatch('settings/changeSetting', {
          key: 'showSettings',
          value: val
        })
      },

    }
  },
  methods: {
    nhyel(){

      // console.log(235)name:'Profiles', params: {id:1}
      if(this.users.roles[0] == 'region'){
        this.$router.push({name:'Profiles'})
      }else if(this.users.roles[0] == 'admin') {
        this.$router.push({name:'Profiles'})
      }else{
         return false
      }

    },
    toggleSideBar(index) {
      this.$store.dispatch('app/toggleSideBar')
       // console.log( this.$store.dispatch('app/toggleSideBar'))
    },
    async logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          location.href = '/index';
        })
      })
    },
	tabBtn(item) {
    console.log(item)
	  if(this.activeMenu.includes((item.path||item.redirect))){
	    return
	  }
    this.$store.dispatch('app/toggleSideBartwo')
	  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)
    this.showde = true

	},
	init() {
	  const route = this.$route;
	  const {
	    meta,
	    path
	  } = route;
	  // if set path, the sidebar will highlight the path you set
	  console.log(route,13)
	  if (meta.activeMenu) {
	    this.$store.dispatch('TabFn', meta.activeMenu)
	  }
	  this.$store.dispatch('TabFn', path)
	},
  getUserre() {
    rensh().then(response => {
      this.users = response.data;
      console.log(this.users.roles[0] == 'admin')
    });
  }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background-color: #1890ff ;
  box-shadow: 0 1px 4px rgba(0,21,41,.08);

  .SignNumArr{
    float: left;
  }

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background .3s;
    color: #fff;
    -webkit-tap-highlight-color:transparent;
    svg{
      color: #fff!important;
    }

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

  .breadcrumb-container {
    float: left;
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      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: 5px;
        position: relative;

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

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          color: #fff;
          font-size: 12px;
        }
      }
    }
  }
}

.sign_box {
    // padding-left: 12px;
    width: calc(100% - 160px);
    overflow-x: scroll;
    float: left;
     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>
