<template>
  <div
    class="mine-conatainer"
    ref="fbyMine">
    <div>
      <div class="header">
        <div class="avatar">
          <img
            :src="userInfo.user_head_img_url"
            alt="">
        </div>
      </div>
      <div class="income-wrap">
        <div>
          <p>上月预估收入(元)</p>
          <p>￥{{ userInfo.last_month_money | fen2Yuan }}</p>
        </div>
        <div>
          <p>本月预估收入(元)</p>
          <p>￥{{ userInfo.month_money | fen2Yuan }}</p>
        </div>
      </div>
      <ul>
        <li @click="$router.push({name: 'Order'})">
          <p class="left">
            <i class="label icon-order"></i>
            <span class="label">下单记录</span>
          </p>
          <p class="right">
            <i class="arrow"></i>
          </p>
        </li>
        <li @click="$router.push({name: 'Wallet'})">
          <p class="left">
            <i class="label icon-wallet"></i>
            <span class="label">可提现余额</span>
          </p>
          <p class="right">
            <span class="value">{{ userInfo.user_balance | fen2Yuan }}</span>
            <i class="arrow"></i>
          </p>
        </li>
        <li @click="$router.push({name: 'Fans'})">
          <p class="left">
            <i class="label icon-wallet"></i>
            <span class="label">粉丝</span>
          </p>
          <p class="right">
            <span class="value">{{ userInfo.user_fans_num }}</span>
            <i class="arrow"></i>
          </p>
        </li>
      </ul>
      <router-link
        class="jump-recommend"
        :to="{name: 'Recommend'}"></router-link>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
import { mapGetters } from 'vuex'

export default {
  name: 'index',
  data () {
    return {
      scroll: null
    }
  },
  computed: {
    ...mapGetters({
      userInfo: 'common/userinfo'
    })
  },
  activated () {
    if (!this.$route.meta.isUseCache) {
      setTimeout(() => {
        this.scroll = new BScroll(this.$refs.fbyMine, {
          click: true,
          scrollbar: true
        })
      }, 500)
    } else {
      if (this.scroll) {
        this.scroll.refresh()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.mine-conatainer {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 50px;
  width: 100%;
  overflow: hidden;

  & > div {
    padding-bottom: 50px;
  }
}

.header {
  width: 100%;
  padding-top: 59px;
  background: url("./image/bg_header@2x.png") center top/100% 94px no-repeat;
}

.avatar {
  width: 73px;
  height: 73px;
  margin: 0 auto;
  border-radius: 50%;
  overflow: hidden;

  img {
    display: block;
    width: 100%;
  }
}

.income-wrap {
  display: flex;
  align-items: center;
  width: 335px;
  margin: 17px auto;
  padding: 16px 0;
  border-radius: 10px;
  background: #FFFFFF;
  box-shadow: 0 2px 4px 0 rgba(31, 49, 74, 0.12);

  & > div {
    position: relative;
    left: 0;
    top: 0;
    flex: 1;

    &:nth-of-type(2) {
      &:before {
        @include vertical-center;
        left: 0;
        height: 86%;
        content: '';
        border-left: 1px solid #ccc;
      }
    }
  }

  p {
    width: 100%;
    font-size: 14px;
    color: #333333;
    line-height: 20px;
    text-align: center;

    &:nth-of-type(2) {
      margin-top: 4px;
    }
  }
}

ul {
  width: 335px;
  margin: 0 auto;

  li {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 16px 0;
    background: #FFFFFF;
    box-shadow: 0 2px 4px 0 rgba(31, 49, 74, 0.12);
    border-radius: 10px;
    margin-top: 17px;

    &:nth-of-type(1) {
      margin-top: 4px;
    }
  }

  .left,
  .right {
    display: flex;
    align-items: center;
    width: 50%;
  }

  .left {
    padding-left: 19px;
  }

  .right {
    justify-content: flex-end;
    padding-right: 14px;
  }

  i.label {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    background-position: center center;
    background-size: 20px 20px;
    background-repeat: no-repeat;

    &.icon-order {
      background-image: url("./image/ic_order@2x.png");
    }

    &.icon-wallet {
      background-image: url("./image/ic_wallet@2x.png");
    }

    &.icon-fans {
      background-image: url("./image/ic_fans@2x.png");
    }
  }

  span.label {
    padding-top: 2px;
    font-size: 14px;
    color: #333333;
    line-height: 20px;
  }

  .value {
    font-size: 12px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #FA4A4A;
    line-height: 17px;
  }

  .arrow {
    width: 24px;
    height: 24px;
    background: url("./image/ic_arrow@2x.png") center center/24px 24px no-repeat;
  }
}

.jump-recommend {
  display: block;
  width: 335px;
  height: 61px;
  margin: 25px auto 0;
  background: url("./image/bg_recommend@2x.png") center center/335px 61px no-repeat;
}
</style>
