<template>
  <div class="user-wrapper">
    <div class="content-box">
      <a-dropdown>
        <span class="action ant-dropdown-link user-dropdown-menu">
          <a-avatar class="avatar" size="small" :src="avatar()"/>
          <span>{{ nickname() }}</span>
        </span>
        <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
          <a-menu-item >
            <a @click="visible = true">
              <a-icon type="logout"/>
              <span>退出登录</span>
            </a>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </div>
    <a-modal
      title="提示"
      v-model="visible"
      @ok="handleOk"
    >
      <p>是否确定退出？</p>
    </a-modal>
  </div>
</template>

<script>
import NoticeIcon from '@/components/NoticeIcon'
import { mapActions, mapGetters } from 'vuex'

export default {
  name: 'UserMenu',
  data: function() {
    return {
      visible: false
    }
  },
  components: {
    NoticeIcon
  },
  methods: {
    ...mapActions(['Logout']),
    ...mapGetters(['nickname', 'avatar']),
    handleOk(e) {
      this.visible = false
      this.Logout({}).then(() => {
        window.location.reload();
      }).catch(err => {
        this.$message.error({
          title: '错误',
          description: err.message
        });
      });
    }
  }
}
</script>
