<template>
  <div class="user-avatar-dropdown">
    <span style="margin-right: 20px;">{{user.name}}</span>
    <Dropdown @on-click="handleClick">
      <Badge>
        <Avatar :src="userAvatar || replaceImg" />
      </Badge>
      <Icon :size="18" type="md-arrow-dropdown"></Icon>
      <DropdownMenu slot="list">
        <DropdownItem name="logout">退出登录</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
import morenphoto from '@/assets/images/morenlogo.png'

export default {
  name: 'User',
  data () {
    return {
      replaceImg: morenphoto,
    }
  },
  props: {
    userAvatar: {
      type: String,
      default: ''
    },
  },
  computed: {
    user () {
      return this.$store.state.user
    }
  },
  methods: {
    logout () {
      this.$store.dispatch('logout')
    },
    handleClick (name) {
      switch (name) {
        case 'logout':
          this.logout()
          break
        default:
          break
      }
    }
  }
}
</script>
<style lang="less" scoped>
.user {
  &-avatar-dropdown {
    cursor: pointer;
    display: inline-block;
    // height: 64px;
    vertical-align: middle;
    // line-height: 64px;
    .ivu-badge-dot {
      top: 16px;
    }
  }
}
</style>
