<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  <member-base :show="false"><view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view-wrapper div container">
    <view class="div common-header-wrap">
      <view class="status-holder"></view>
      <view :style="'height:'+navHeight+'px'"></view>
      <view class="common-header-holder"></view>
      <view class="common-header-fixed">
      <title-header />
      <uni-nav-bar title="推广会员" class="common-header" left-icon="back" @clickLeft="goBack()">
      </uni-nav-bar>
    </view>
    </view>
<view class="scroll-view div" style="position:relative">
    <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="div" @scrolltolower="loadMore" scroll-y="true">
      <view class="div"  v-if="userList && userList.length">
        <view class="div inviter-item" v-for="(v,k) in userList" :key="v.member_id">
          <view class="div avatar">
            <image mode="aspectFit" class="img" :src="v.member_avatar" />
          </view>
          <view class='div inviter'>
            <view class='div users'>
              <strong>{{v.member_name}}</strong>
              <text class="span" v-for="(i_u,n) in v.inviters" :key="n">->{{i_u}}</text>
            </view>
            <view class='div time'>注册时间：{{v.member_addtime}}</view>
            <view class='div time'>最后登录：{{v.member_logintime}}</view>
          </view>
        </view>
      </view>
      <empty-record v-else-if="userList && !userList.length"></empty-record>
    </scroll-view>
</view>
  </view></member-base>
</template>

<script>
import {getFontSize} from '@/util/common'
import TitleHeader from '../../TitleHeader'
import MemberBase from '../MemberBase'
import { getInviterUser } from '../../../api/memberInviter'
import EmptyRecord from '../../EmptyRecord'
export default {
  name:'MemberInviterUser',
  components:{
    TitleHeader,
    MemberBase,
    EmptyRecord
  },
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
      navHeight: 0,
      params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      userList: false
    }
  },
  created () {

  this.loadMore()

  },

  mounted(){

  // #ifdef  MP-WEIXIN

  this.navHeight = uni.getMenuButtonBoundingClientRect().height

  // #endif

  },
  methods:{
    goBack(){uni.navigateBack({delta:1})},
    getUserList (ispush) {
      uni.showLoading({ title: '加载中' })
      let params = this.params
      getInviterUser(params).then(res => {
        uni.hideLoading()
        if (res) {
          if (ispush && this.userList) {
            this.userList = this.userList.concat(res.result.list)
          } else {
            this.userList = res.result.list
          }
          if (res.result.hasmore) {
            this.isMore = true
          } else {
            this.isMore = false
          }
        }
      })
    },
    loadMore () {
      this.loading = true
      this.params.page = ++this.params.page
      if (this.isMore) {
        this.loading = false
        this.getUserList(true)
      }
    }
  }
}
</script>

<style scoped lang="scss">
.scroll-view-wrapper{display: flex;flex-direction: column;}
.scroll-view{flex:1}
.inviter-item{display:flex;padding:.5rem;background:#fff;border-bottom:1px solid #e4e4e4;
  .avatar{width:4.5rem;
    .img{width:4rem}
  }
  .inviter{flex:1;font-size:$subFontSize;
    .users{font-size:$h3;margin-bottom:1rem;margin-top:.5rem}
    .time{color:gray;margin-top:.2rem}
  }
}
</style>
