<template>
  <el-header class="app-header">
    <h3>{{ title }}</h3>
    <el-dropdown class="dropdown-container" trigger="click">
      <div class="dropdown-wrapper">
        <span style="line-height:50px;">欢迎您，{{ name }}</span>
        <!--<img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar">-->
        <i class="el-icon-arrow-down"/>
      </div>
      <el-dropdown-menu slot="dropdown" class="user-dropdown">
        <el-dropdown-item v-if="!baseConfig.singleSys">
          <span style="display:block;" @click="backToIndex">回首页</span>
        </el-dropdown-item>
        <el-dropdown-item :divided="!baseConfig.singleSys">
          <span style="display:block;" @click="resetPwd">修改密码</span>
        </el-dropdown-item>
        <el-dropdown-item divided>
          <span style="display:block;" @click="logout">注销</span>
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <reset-pwd v-show="showSetPwd" ref="retPwd"/>
  </el-header>
</template>

<script>
import { mapGetters } from 'vuex'
import ResetPwd from '@/views/system/user/resetPwd'

export default {
  name: 'AppHeader',
  components: { ResetPwd },
  data() {
    return {
      title: this.baseConfig.title, // 标题
      name: this.$store.getters.name, // 用户姓名
      showSetPwd: false // 是否显示修改密码按钮
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar'
    ])
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('ToggleSideBar')
    },
    logout() {
      this.$store.dispatch('LogOut').then(() => {
        location.reload() // 为了重新实例化vue-router对象 避免bug
      })
    },
    resetPwd() {
      this.showSetPwd = true
      this.$refs.retPwd.initDialog(true)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  h3{
    margin-left:24px;
    display: inline-block;
    float:left;
  }
  .dropdown-container {
    /*height: 50px;*/
    display: inline-block;
    float: right;
    z-index:500;
    position: fixed;
    top:0px;
    right: 35px;
    .dropdown-wrapper {
      cursor: pointer;
      margin-top: 5px;
      position: relative;
      line-height: initial;
      .user-avatar {
        width: 40px;
        height: 40px;
        border-radius: 10px;
      }
      .el-icon-caret-bottom {
        font-size: 12px;
      }
    }
  }
</style>
