<template>
  <div class="navbar">
    <div class="navbarleft">
      <div class="logoimg">
        <img src="../../assets/images/bluelogo@2x.png" alt="">
        <span>苏州工业园区工业上楼管理系统</span>
      </div>
    </div>
    <div class="right-menu">
      <bearicon />
      <div class="avatar-container right-menu-item hover-effect" >
        <div class="avatar-wrapper">
          <div v-if="checkRole(['common'])">
            <span>{{ name }}</span>
          </div>
          <div v-if="showCompanySection">
            <span>{{ name }}</span>
          </div>
           <img src="@/assets/images/退出登录.png" alt=""  @click="logout">
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import TopNav from '@/components/TopNav'
import bearicon from '@/components/bearicon'
import { checkPermi, checkRole } from "@/utils/permission"

export default {
  components: {
    Breadcrumb,
    TopNav,
    bearicon
  },
  data() {
    return {
      username: "",
      messages: [],
      counts: 0 // 消息计数
    }
  },
  computed: {
    ...mapGetters(["avatar", "name", "sidebarRouters", "nickName"]),
    //展示判断
    showCompanySection() {
      const isCompany = this.checkRole(['company'])
      const isCommon = this.checkRole(['common'])
      return isCompany && !isCommon
    },
    topNav: {
      get() {
        return this.$store.state.settings.topNav
      }
    },
    unreadMessages() {
      return this.messages.length
    }
  },
  mounted() {
    this.username = this.$store.state.user.nickName
  },
  methods: {
    checkPermi,
    checkRole,
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          this.$router.replace('/login')
        })
      }).catch(() => {})
    },
    handleCommand(command) {
      this.$message('点击了: ' + command)
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  display: flex;
  justify-content: space-between;
  height: 50px;
  overflow: hidden;
  position: relative;

  .logoimg {
    display: flex;
    align-items: center;
    gap: .8rem;
  }

  .logoimg img {
    width: 3.69rem;
    height: 2rem;
    margin-left: 1.2rem;
  }

  .logoimg span {
    width: auto;
    height: 2.06rem;
    font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
    font-weight: 500;
    font-size: 1.5rem;
    color: #292C33;
    line-height: 2.06rem;
    text-align: left;
    font-style: normal;
    text-transform: none;

  }

  .navbarleft {
    display: flex;
    align-items: center;
  }

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

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

  .breadcrumb-container {
    float: left;
  }

  .topmenu-container {
    position: absolute;
    left: 50px;
  }

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

  .right-menu {
    float: right;
    height: 100%;
    display: flex;
    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: 2px;
        position: relative;
        display: flex;
        align-items: center;
        .user-avatar {
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }
        img{
          width: 1rem;
          height: 1rem;
          margin-left: 1rem;
          cursor: pointer;
        }
        .el-icon-caret-bottom {
          position: absolute;
          right: -20px;
          top: 17px;
          font-size: 12px;
        }
      }
    }

    .item {
      margin-right: 10px;
      margin-top: .5rem;

      .el-dropdown-link {
        color: black;
      }

      .el-dropdown-link i {
        font-size: 2rem;
        /* 增大图标的大小 */
      }
    }
  }
}
</style>
