<template>
	<view class="main">
		<!-- nav -->
		<navigation>{{ i18n.MyTeam }}</navigation>
		<view class="body">
			<view class="top flex">
				<view class="item">
					<view class="t1">
						{{inviteData.totalPeople}}
					</view>
					<view class="t2">
						{{i18n.Numberofclionts}}
					</view>
				</view>
				<view class="item">
					<view class="t1">
						{{Number(inviteData.yestodayRevenue)}}
					</view>
					<view class="t2">
						{{i18n.Earnlingsyesterday}}(U)
					</view>
				</view>
				<view class="item">
					<view class="t1">
					{{Number(inviteData.totalRevenue)}}
					</view>
					<view class="t2">
						{{i18n.Totalincome}}(U)
					</view>
				</view>
			</view>
			<u-subsection :list="list" activeColor="#00E8A2" inactiveColor="#fff" :current="curNow"
				@change="sectionChange" bgColor="#211F32"></u-subsection>
			<view class="container">
				<table class="table">
					<thead class="thead">
						<tr>
							<td>{{i18n.User}}</td>
							<td v-if="curNow==1">{{i18n.Rebateamount}}</td>
							<td>{{i18n.Financialfunds}}</td>
							<td>{{i18n.Time}}</td>
						</tr>
					</thead>
					<tbody  class="tbody">
						<tr v-for="item,index in userInfoObj" :key="index">
							<td style="width: 100px;"><div style="width: 100%;"><div style="width: 130px;word-break: break-all;">{{item.email}}</div></div></td>
							<td v-if="curNow==1">{{item.amount}}USDT</td>
							<td v-if="curNow==1">{{i18n.Financialfunds}}{{item.divideLev}}</td>
							<td v-if="curNow==0">{{i18n.Financialfunds}}{{item.userLevel}}</td>
							<!-- <td v-if="curNow==0">{{item.tranAmt}}{{coinTypeInfo.system_coin_code}}</td>-->
							<td>{{item.timestr}}</td>
						</tr>
					</tbody>
				</table>
				<u-empty :text="i18n.Dataisempty" mode="data" v-if="userInfoObj.length==0"></u-empty>
				<u-loadmore :status="loadStatus" :loading-text="loadingText" :loadmore-text="loadmoreText"
					:nomore-text="nomoreText" v-if="userInfoObj.length" height="80" />
			</view>
		</view>
	</view>
</template>

<script>
	import api from '@/utils/api'
	import constant from '@/utils/constant.js';
	export default {
		name: "myTeam",
		data() {
			return {
				form: {
					pageNumber: 1,
					pageSize: 20,
				},
				isLoadMore: false, //是否加载中
				loadStatus: 'loadmore',
				loadingText: this.$t("login").toload,
				loadmoreText: this.$t("login").pullup,
				nomoreText: this.$t("login").Nomore,
				userInfoObj: [],
				
				inviteData:{},
				list: [ this.$t("me").Myclient, this.$t("me").Incomerecord],
				// 或者如下，也可以配置keyName参数修改对象键名
				// list: [{name: '未付款'}, {name: '待评价'}, {name: '已付款'}],
				curNow: 0,

			};
		},
		computed: {
			i18n() {
				return this.$t("me");
			},
			// 获取币种
			coinTypeInfo(){
				return uni.getStorageSync('coinTypeInfo')
			}
		},
		onReachBottom() {
			if (!this.isLoadMore) {
				this.form.pageNumber += 1
				this.getList();
			}
		},
		onLoad() {
			this.invitation()
			this.getList()
		},
		onShow() {},
		methods: {
			// 重置
			reset(){
				this.form={
					pageNumber: 1,
					pageSize: 20,
				}
				this.isLoadMore=false //是否加载中
				this.loadStatus='loadmore'
				this.loadingText=this.$t("login").toload
				this.loadmoreText=this.$t("login").pullup
				this.nomoreText=this.$t("login").Nomore
				this.userInfoObj=[]
			},
			// 获取用户下级列表
			getList() {
				this.isLoadMore = true
				api.promotionRecords(this.form).then(res => {
					if (res.content.length) {
						if (this.form.pageNumber > 1) {
							this.userInfoObj = this.userInfoObj.concat(res.content)
							for (var i = 0; i < this.userInfoObj.length; i++) {
								if (this.userInfoObj[i].addTime) {
									this.userInfoObj[i].timestr = this.$index.formatyymmddhhmmss(this.userInfoObj[
										i].addTime)
								}
							
							}
						} else {
							this.userInfoObj = res.content
							for (var i = 0; i < this.userInfoObj.length; i++) {
								if (this.userInfoObj[i].addTime) {
									this.userInfoObj[i].timestr = this.$index.formatyymmddhhmmss(this.userInfoObj[
										i].addTime)
								}
							}
						}
						if (this.userInfoObj.length >= Number(res.totalElements)) { // 判断接口返回数据量小于请求数据量，则表示此为最后一页
							this.isLoadMore = true
							this.loadStatus = 'nomore'
						} else {
							this.isLoadMore = false
						}
					} else {
						this.isLoadMore = true
						this.loadStatus = 'nomore'
						// this.userInfoObj = []
					}
					this.$forceUpdate()
				})
			},
			// 获取用户返佣记录
			getListRecord(){
				this.isLoadMore = true
				api.bonusRecords(this.form).then(res => {
					if (res.content.length) {
						if (this.form.pageNumber > 1) {
							this.userInfoObj = this.userInfoObj.concat(res.content)
							for (var i = 0; i < this.userInfoObj.length; i++) {
								if (this.userInfoObj[i].addTime) {
									this.userInfoObj[i].timestr = this.$index.formatyymmddhhmmss(this.userInfoObj[
										i].addTime)
								}
							
							}
						} else {
							this.userInfoObj = res.content
							for (var i = 0; i < this.userInfoObj.length; i++) {
								if (this.userInfoObj[i].addTime) {
									this.userInfoObj[i].timestr = this.$index.formatyymmddhhmmss(this.userInfoObj[
										i].addTime)
								}
							}
						}
						if (this.userInfoObj.length >= Number(res.totalElements)) { // 判断接口返回数据量小于请求数据量，则表示此为最后一页
							this.isLoadMore = true
							this.loadStatus = 'nomore'
						} else {
							this.isLoadMore = false
						}
					} else {
						this.isLoadMore = true
						this.loadStatus = 'nomore'
						this.userInfoObj = []
					}
					this.$forceUpdate()
				})
			},
			
			//获取用户邀请数据
			invitation() { 
				api.invitData().then(res => {
					this.inviteData=res
				})
			},
			sectionChange(index) {
				this.curNow = index;
				if(this.curNow==0){
					this.getList()
				}else{
					this.getListRecord()
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	.table{
		width: 100%;
		text-align: center;
		border-collapse: collapse;
		.thead{
			height: 84rpx;
			line-height: 84rpx;
			tr{
				td{
					color: #A1A0A8;
					font-size: 24rpx;
				}
			}
		}
		.tbody{
			tr{
				height: 84rpx;
				// line-height: 84rpx;
				border-top: 2rpx solid #323045 !important;
				td{
					color: #fff;
					font-size: 24rpx;
				}
			}
		}
	}
	.container {
		padding: 0 32rpx;
	}

	/deep/ .u-subsection--button {
		height: 80rpx;
	}

	/deep/ .u-subsection--button__bar {
		background: #323045;
		height: 80rpx;
	}

	.flex {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.top {
		padding: 68rpx 32rpx;
		background: url('@/static/me/myTeambg.png') no-repeat;
		background-size: cover;

		.item {
			text-align: center;
			line-height: 60rpx;
		}

		.t2 {
			font-size: 24rpx;
			color: #A1A0A8;
		}

		.t1 {
			color: #00E8A2;
			font-size: 32rpx;
			font-weight: bolder;
		}
	}

	.main {

		.body {
			overflow: hidden;
			margin-top: 200rpx;

			.userItem {
				position: relative;
				background: #211F32;
				border-radius: 32rpx;
				display: flex;
				flex-wrap: wrap;
				margin-top: 32rpx;

				.icon {
					height: 160rpx;
					margin-left: 20rpx;
					margin-right: 26rpx;
				}

				.email {
					width: 520rpx;
					height: 52rpx;
					line-height: 52rpx;
					margin-top: 28rpx;
					font-size: 32rpx;
				}

				.date {
					width: 180rpx;
					height: 52rpx;
					line-height: 52rpx;
					font-size: 28rpx;
				}

				.button {
					position: absolute;
					top: 72rpx;
					right: 32rpx;
					width: 120rpx;
					height: 48rpx;
					line-height: 48rpx;
					font-size: 28rpx;
					color: #15141F !important;
					margin-left: 200rpx;
					margin-top: 20rpx;
					border-radius: 16rpx;
				}
			}

		}

	}
</style>
