<template>
  <div class="avatar-wrapper">
    <!-- <img :src="avatar" class="user-avatar"> -->
    <img src="https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif" class="user-avatar">
    <span>{{ userName }}</span>
    <template v-if="isSupplier">
      <!-- 未开通会员时 -->
      <!-- 开通会员已到期 -->
      <!-- 开通会员未到期 -->
      <i v-if="!notOpen" class="vip-icon" :class="{ close: vipInfo.vipStatus === 0 }" />
      <el-button
        v-if="notOpen || beExpired"
        type="primary"
        size="mini"
        class="open"
        @click.stop="toOpenVip"
      >开通会员</el-button>
      <el-button
        v-if="hasOpen"
        type="danger"
        size="mini"
        class="renewal"
        @click.stop="toOpenVip"
      >续费</el-button>
    </template>
    <i class="el-icon-caret-bottom" />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import avatar from '@/assets/img/avatar.png'
export default {
  name: 'AvatarWrapper',
  computed: {
    ...mapGetters(['name', 'userIdentity', 'mobile', 'loginAccount', 'vipInfo']),
    // isSupplier
    isSupplier() {
      return this.userIdentity === 2
    },
    mobileWidthStar() {
      return this.mobile ? this.mobile.replace(/^(\w{3})\w+(\w{4})$/, '$1****$2') : ''
    },
    userName() {
      return this.loginAccount || this.mobileWidthStar || this.name
    },
    // 未开通会员
    notOpen() {
      return this.vipInfo.vipStatus === 3
    },
    // 已开通会员
    hasOpen() {
      return this.vipInfo.vipStatus === 1
    },
    // 已到期
    beExpired() {
      return this.vipInfo.vipStatus === 0
    },
    avatar() {
      return avatar
    }
  },
  methods: {
    toOpenVip() {
      this.$router.push('/vip/vip-open')
    }
  }
}
</script>

<style scoped lang="scss">
.avatar-wrapper {
  position: relative;

  .user-avatar {
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    vertical-align: middle;
  }
  span {
    margin-left: 10px;
  }
  .el-icon-caret-bottom {
    cursor: pointer;
    position: absolute;
    right: -20px;
    top: 25px;
    font-size: 12px;
  }
  .el-button{
    height: 24px;
    padding: 0 12px;
    margin-left: 10px;
  }
}
</style>
