<template>
    <div class="user" v-if="user">
      <div class="user-bg">
        <div class="user-head">
          <van-icon name="setting-o" color="#fff" size="20" @click="$router.push('/settings')" />
        </div>
        <div class="user-info">
          <div class="user-info__avatar">
<!--            <img src="@/assets/images/avatar.png" alt="">-->
            <img :src="user.avatar" alt="">
          </div>
          <div class="user-info__text">
            <div class="d-flex align-items-center">
              <span class="user-info__name">{{ user.nickname || user.username }}</span>
              <img class="user-info__vip" src="@/assets/images/vip.png" alt="" v-if="user.is_vip">
            </div>
            <div class="d-flex">
              <div class="user-info__id">ID: {{ user.id }}</div>
            </div>
            <div class="user-info__gold">金币: {{ user.gold }}</div>
          </div>
        </div>
        <div class="user-main">
          <div class="user-balance">
            <div>
              <p class="user-balance__count">{{ user.follow_num }}</p>
              <p class="user-balance__label">粉丝</p>
            </div>
            <div>
              <p class="user-balance__count">{{ user.my_follow_num }}</p>
              <p class="user-balance__label">关注</p>
            </div>
            <div>
              <p class="user-balance__count">{{ user.like_num }}</p>
              <p class="user-balance__label">获赞</p>
            </div>
            <div @click="$router.push('/invite')">
              <p class="user-balance__count">{{ user.ref_num }}</p>
              <p class="user-balance__label">推广</p>
            </div>
          </div>
          <div class="user-menu">
            <div class="user-menu__item" @click="$router.push('/works')">
              <div class="user-menu__icon">
                <van-icon class-prefix="fa fa-tachometer" color="#2196F3" size="20" />
              </div>
              <p class="user-menu__title">我的作品</p>
            </div>
            <div class="user-menu__item">
              <div class="user-menu__icon">
                <van-icon class-prefix="fa fa-heart" color="#2196F3" size="20" />
              </div>
              <p class="user-menu__title">我喜欢的</p>
            </div>
            <div class="user-menu__item">
              <div class="user-menu__icon">
                <van-icon class-prefix="fa fa-cloud-download" color="#2196F3" size="20" />
              </div>
              <p class="user-menu__title">我的下载</p>
            </div>
            <div class="user-menu__item">
              <div class="user-menu__icon">
                <van-icon class-prefix="fa fa-diamond" color="#2196F3" size="20" />
              </div>
              <p class="user-menu__title">提现金币</p>
            </div>
            <div class="user-menu__item">
              <div class="user-menu__icon">
                <van-icon class-prefix="fa fa-list-alt" color="#2196F3" size="20" />
              </div>
              <p class="user-menu__title">帐变记录</p>
            </div>
            <div class="user-menu__item">
              <div class="user-menu__icon">
                <van-icon class-prefix="fa fa-list-ol" color="#2196F3" size="20" />
              </div>
              <p class="user-menu__title">推广记录</p>
            </div>
            <div class="user-menu__item">
              <div class="user-menu__icon">
                <van-icon class-prefix="fa fa-dollar" color="#2196F3" size="20" />
              </div>
              <p class="user-menu__title">VIP充值</p>
            </div>
            <div class="user-menu__item">
              <div class="user-menu__icon">
                <van-icon class-prefix="fa fa-list-ul" color="#2196F3" size="20" />
              </div>
              <p class="user-menu__title">我的帖子</p>
            </div>
            <div class="user-menu__item" @click="$router.push('/user-data')">
              <div class="user-menu__icon">
                <van-icon class-prefix="fa fa-address-card-o" color="#2196F3" size="20" />
              </div>
              <p class="user-menu__title">个人资料</p>
            </div>
          </div>
        </div>
      </div>
    </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'user',
  created () {
    this.$store.dispatch('getUser')
  },
  computed: {
    ...mapState(['user'])
  }
}
</script>

<style lang="scss" scoped>
.user {
  color: #ffffff;
  padding-bottom: 50px;
  min-height: 100vh;
  display: flex;
  &-bg {
    background: url('../../assets/images/page-bg.png') no-repeat;
    background-size: cover;
    width: 100%;
  }
  &-head {
    display: flex;
    justify-content: flex-end;
    padding: 10px 20px 0;
  }
  &-info {
    padding: 12px 20px;
    display: flex;
    &__avatar {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 8px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    &__name {
      font-size: 20px;
      font-weight: 500;
    }
    &__vip {
      height: 14px;
      margin-left: 4px;
    }
    &__id {
      font-size: 10px;
      background: rgba(255, 255, 255, 0.1);
      border-radius: 4px;
      padding: 4px;
      margin-top: 8px;
      display: inline-block;
    }
    &__gold {
      margin-top: 8px;
      font-size: 13px;
    }
  }
  &-main {
    padding: 12px;
  }
  &-balance {
    height: 92px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: space-around;
    &__label {
      font-size: 13px;
    }
    &__count {
      font-size: 20px;
      font-weight: bold;
      margin-bottom: 8px;
    }
  }
  &-menu {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-row-gap: 32px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin-top: 16px;
    padding: 32px 0;
    &__item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
    &__icon {
      width: 48px;
      height: 48px;
      border-radius: 50%;
      background-color: #ffffff;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    &__title {
      font-size: 14px;
      margin-top: 12px;
    }
  }
}
</style>
