<template>
  <div class="user-wrapper">
    <router-link :to="{ name: 'help' }">
    <span class="action">
        <a-icon type="question-circle-o"></a-icon>
    </span>
    </router-link>
    <a-dropdown>
      <span class="action ant-dropdown-link user-dropdown-menu">
        <a-icon type="user"></a-icon>
        <span> {{ username() }}</span>
      </span>
      <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
        <a-menu-item key="0">
          <router-link :to="{ name: 'settingUser' }">
            <a-icon type="setting"></a-icon>
            <span>用户设置</span>
          </router-link>
        </a-menu-item>
        <a-menu-item key="1">
          <a @click="handleLogout">
            <a-icon type="logout"></a-icon>
            <span>注销</span>
          </a>
        </a-menu-item>
      </a-menu>
    </a-dropdown>
  </div>
</template>

<script>
  import { mapActions, mapGetters } from 'vuex'

  export default {
    name: 'UserMenu',
    methods: {
      ...mapActions(['Logout']),
      ...mapGetters(['username']),
      handleLogout () {
        const that = this
        this.$confirm({
          title: '提示',
          content: '确定要注销登录吗?',
          onOk () {
            return that.Logout({})
              .then(() => {
                that.$router.push({ name: 'login' })
              })
          },
          onCancel () {
          }
        })
      }
    }
  }
</script>
