<template>
  <div class="user-avatar-dropdown">
    <Dropdown @on-click="handleClick">
      <!-- <Badge :dot="!!messageUnreadCount">
        <Avatar :src="userAvatar"/>
      </Badge> -->
      <Icon :size="18" type="md-arrow-dropdown"></Icon>
      <DropdownMenu slot="list">
        <!-- <DropdownItem name="message">
          消息中心<Badge style="margin-left: 10px" :count="messageUnreadCount"></Badge>
        </DropdownItem> -->
        <DropdownItem name="userInfo">{{$t('personal_info')}}</DropdownItem>
        <DropdownItem name="recentLogin">{{$t('rencently_sign_in')}}</DropdownItem>
        <DropdownItem name="resetPassword">{{$t('pwd_alter')}}</DropdownItem>
        <DropdownItem name="logout">{{$t('logout')}}</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
import './user.less'
import { mapActions } from 'vuex'
export default {
  name: 'User',
  props: {
    userAvatar: {
      type: String,
      default: ''
    },
    messageUnreadCount: {
      type: Number,
      default: 0
    }
  },
  methods: {
    ...mapActions([
      'handleLogOut'
    ]),
    logout () {
      this.handleLogOut().then(() => {
        this.$router.push({
          name: 'login'
        })
      })
    },
    message () {
      this.$router.push({
        name: 'Message_page'
      })
    },
    checkInfo () {
      this.$router.push({
        name: 'accountInfo'
      })
    },
    loginInfo () {
      this.$router.push({
        name: 'loginRecord'
      })
    },
    resetPassword () {
      this.$router.push({
        name: 'resetPassword'
      })
    },
    handleClick (name) {
      switch (name) {
        case 'logout': this.logout()
          break
        case 'userInfo': this.checkInfo()
          break
        case 'recentLogin': this.loginInfo()
          break
        case 'resetPassword': this.resetPassword()
          break
      }
    },
    outLogin () {
      this.$router.push({ name: 'login' })
    }
  }
}
</script>
