<script>
import tokenpocketBnb from "@/common/wallet/tokenpocket-wallet/tokenpocket-bnb";
import {getTotalMoney} from "@/api/money";
import {getTeamList} from "@/api/member";

export default {
  name: "my-index",
  props:{
    address:{
      default:''
    }
  },
  components: {},
  watch:{
    'address':function () {
      this.getIconNum()
    }
  },
  data() {
    return {
      coinNum:'',
      coinText:'',
      pledgeTotal:'',
      revenueTotal:'',
      list:[],
      page:1,
    };
  },
  mounted() {
    this.getIconNum()
    this.getTotalMoney()
    this.getTeamList()
  },
  methods: {
    abbreviateString(str ){
      let startLength=4;
      let endLength=4;
      if (str.length <= startLength + endLength + 1) {
        return str; // 如果字符串长度不足以被截断，则返回原字符串
      }
      return str.slice(0, startLength) + '...' + str.slice(-endLength);
    },
    getTeamList(){
      getTeamList({'page':this.page}).then(res=>{
        if(res.code===1){
          ++this.page
          this.list.push(...res.data.items)
        }
      })
    },
    getTotalMoney(){
      getTotalMoney().then(res=>{
        if (res.code===1){
          this.pledgeTotal=res.data.pledgeTotal
          this.revenueTotal=res.data.revenueTotal

        }
      })
    },
      getIconNum(){
        this.address=tokenpocketBnb.getMyAddress()
      if(this.address===''){
        return
      }
       tokenpocketBnb.getTokenBalance(this.address,0).then(coinNum=>{
        this.coinNum=coinNum
      })

    },
    goUrl() {
      uni.navigateTo({
      	url: 'pages/my/inner-page/all_profit'
      });
    }
  },
}
</script>

<template>
<view>
  <view class="align-items-center mb-32">
    <view class="h-80 b-rad-20 bg-one flex-1 flex-direction-column align-items-center flex-justify-center mr-20">
      <view class="fs-28 fc-f">余额</view>
      <view class="fs-30 fc-f fw-b">
        {{coinNum}}
      </view>
    </view>
    <view class="h-80 b-rad-20 bg-two flex-1 flex-direction-column align-items-center flex-justify-center mr-20">
      <view class="fs-28 fc-f">贡献</view>
      <view class="fs-30 fc-f fw-b">
        {{pledgeTotal}}
      </view>
    </view>
    <view @click="goUrl" class="h-80 b-rad-20 bg-one flex-1 flex-direction-column align-items-center flex-justify-center">
      <view class="fs-28 fc-f">总收益</view>
      <view class="fs-30 fc-f fw-b">
        {{revenueTotal}}
      </view>
    </view>
  </view>
  <view class="fs-34 fw-b mb-20">
    我的团队
  </view>
  <view class="bgc-f p-10 box-sizing-border b-rad-20" v-for="item in list">
    <view class="pb-10 border-bottom-e5e5e5 fs-28 mb-20">
      {{abbreviateString(item.address,6)}}
    </view>
    <view class="align-items-start flex-justify-space pb-10">
      <view class="flex-1 left-box">
          <view class="fs-28 mb-4">注册时间: {{item.created_date}}</view>
          <view class="fs-28 mb-4">团队人数:{{item.clanNum}}</view>
          <view class="fs-28">直推人数:{{item.recomNum}}</view>
      </view>
<!--      <view class="flex-1 pl-20 box-sizing-border">-->
<!--        <view class="fs-28 mb-4">自身业绩:10000</view>-->
<!--        <view class="fs-28">团队业绩:10000</view>-->
<!--      </view>-->
    </view>
  </view>
  <view>

  </view>
</view>
</template>

<style scoped lang="scss">
.bg-one{
  background-image: linear-gradient(270deg, #2353db, #54c8ff);
}
.bg-two{
  background-image: linear-gradient(270deg, #ffc62c, #ffa954);
}
.h-80{
  height: 160rpx;
}
.left-box{
  border-right: 2rpx solid #ccc;
}
</style>
