<template>
  <div class="navbar">
    <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
    <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
    <div class="right-menu">
      <template>
        <error-log class="errLog-container right-menu-item hover-effect" />
      </template>
      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click" @command="handleCommand">
        <div class="avatar-wrapper">
          <img :src="sysAvatar" class="user-avatar">
          <i class="iconfont iconycxialakuang"/>
        </div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="checkoutApp">
            <span>切换子系统</span>
          </el-dropdown-item>
          <!-- <el-dropdown-item divided>
            <span  @click="changeUserInfo">修改个人信息</span>
          </el-dropdown-item> -->
          <el-dropdown-item command="changePwd" divided>
            <span>修改密码</span>
          </el-dropdown-item>
          <el-dropdown-item command="logout" divided>
            <span>退出登录</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <span class="font-css">您好，{{nikeName}}</span>
      <i class="iconfont iconycshijian font-css">{{todayDate}}</i>
      <screenfull id="screenfull" class="right-menu-item hover-effect screen-full-layout"/>
    </div>
    <CheckoutApp :visible.sync="dialogVisible"></CheckoutApp>
    <ChangePwd :visible.sync="pwdVisible"></ChangePwd>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
import ErrorLog from '@/components/ErrorLog'
import Screenfull from '@/components/Screenfull'
import CheckoutApp from '@/components/tenant/CheckoutApp'
import ChangePwd from '@/components/tenant/ChangePwd'
import { redirctLogin } from '@/utils/auth'
export default {
  components: {
    Breadcrumb,
    Hamburger,
    ErrorLog,
    Screenfull,
    CheckoutApp,
    ChangePwd
  },
  data () {
    return {
      dialogVisible: false,
      pwdVisible: false
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar',
      'nikeName'
    ]),
    sysAvatar () {
      return this.UtilJs.isEmpty(this.avatar) ? require('@/assets/defaultHead.png') : this.avatar + '?imageView2/1/w/80/h/80'
    },
    todayDate () {
      var now = new Date()
      return now.toLocaleDateString()
    }
  },
  methods: {
    toggleSideBar () {
      this.$store.dispatch('ToggleSideBar')
    },
    handleCommand (command) {
      if (command === 'checkoutApp') {
        this.checkoutApp()
      } else if (command === 'changePwd') {
        this.changePwd()
      } else if (command === 'logout') {
        this.logout()
      }
    },
    checkoutApp () {
      this.dialogVisible = true
    },
    changePwd () {
      this.pwdVisible = true
    },
    changeUserInfo () {
      let user = this.$store.getters.user
      this.$router.push({ name: 'userModify', params: user })
    },
    logout () {
      redirctLogin()
    }
  }
}
</script>

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

    .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;
    }

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

    .right-menu {
      float: right;
      height: 100%;
      line-height: 50px;
      display: flex;
      align-items: center;

      &:focus {
        outline: none;
      }

      .right-menu-item {
        display: inline-block;
        padding-right: 10px;
        height: 100%;
        font-size: 20px;
        color: #6e778f;
        vertical-align: text-bottom;

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

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

      .avatar-container {

        .avatar-wrapper {
          display: flex;
          align-items: center;
          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: 12px;
          }
        }
      }
    }
  }

  .font-css {
    font-size: 14px;
    margin-right: 10px;
    color: #6e778f;
  }

  .screen-full-layout {
    display: flex !important;
    align-items: center;
  }
</style>
