<template>
	<view style="padding-bottom: 50rpx;">
		<view class="padding margin radius bg-white" style="">
			<view class="text-19">当前收益</view>
			<view class="flex justify-between margin-top">
				<view class="text-bold text-black">¥<text style="font-size: 34px;">{{inviterRecord}}</text></view>
				<view class="" style="position: relative;overflow: hidden;width: 90px;">
					<view style="position: absolute;bottom:0;">
						<!-- <view class="flex"> -->
						<button @tap="getOut" class="cu-btn round">立即提现</button>
						<!-- </view> -->
					</view>
				</view>
			</view>
		</view>
		<view class="margin padding bg-white radius">
			<view class="u-font-16 text-bold margin-bottom">邀请明细</view>
			<!-- <view class="flex justify-between" style="line-height: 30px;" v-for="(item,index) in userList" >
				<view class="flex" style="width: 300rpx;">
					<u-image :src="item.avatar" width="30px" mode="widthFix"></u-image>
					<view class="margin-left-sm userName_view">{{item.userName}}</view>
				</view>
				<view style="width: 120rpx;">邀请好友</view>
				<view style="width: 120rpx;">
					<text class="margin-left text-red">赚{{item.money}}</text>
				</view>
			</view> -->

			<view class="flex justify-between align-center" style="margin-bottom: 40rpx;"
				v-for="(item,index) in userList">
				<view class="flex align-center">
					<image :src="item.avatar?item.avatar:'../../static/images/logo.png'"
						style="width: 80rpx;height:80rpx;border-radius: 50rpx;"></image>
					<view class="margin-left-sm">
						<view class="userName_view">{{item.userName}}</view>
						<view class="text-cut" style="font-size: 24rpx;" v-if="item.userType && item.userType == 2">二级好友
						</view>
						<view class="text-cut" style="font-size: 24rpx;" v-else>一级好友
						</view>
						<!-- <u-image :src="item.avatar" width="30px" mode="widthFix"></u-image> -->
					</view>
				</view>
				<view class="margin-left flex-sub text-right">
					<text class="margin-left text-red">赚{{item.money}}</text>
				</view>
			</view>

			<empty v-if="userList.length == 0" />
		</view>
	</view>
</template>

<script>
	import empty from '../../components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				page: 1,
				limit: 50,
				userList: [],
				inviterRecord: ''
			}
		},
		onLoad() {
			this.getData()
			this.getInviter()
		},
		onReachBottom: function() {
			this.page = this.page + 1;
			this.getInviter();
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getData();
			this.getInviter();
		},
		methods: {
			getData() {
				let data = {
					page: this.page,
					limit: this.limit
				}
				this.$u.api.queryInviter(data).then(res => {
					if (res.code == 0) {
						this.inviterRecord = res.data.inviteMoney.money
					} else {
						uni.showToast({
							title: res.msg,
							duration: 1000,
							icon: 'none'
						});
					}
				})
			},
			getInviter() {
				let data = {
					page: this.page,
					limit: this.limit
				}
				this.$u.api.inviter(data).then(res => {
					if (res.code == 0) {
						if (this.page == 1) {
							this.userList = res.data.list
						} else {
							this.userList = [...this.userList, ...res.data.list]
						}
						uni.stopPullDownRefresh();
					} else {
						uni.showToast({
							title: res.msg,
							duration: 1000,
							icon: 'none'
						});
					}
				})
			},
			getOut() {
				uni.navigateTo({
					url: '/me/invite/cashDetail'
				});
			},
		}
	}
</script>

<style>
	.cu-btn {
		background: rgba(255, 117, 129, 0.2);
		color: #ff7581;
		font-weight: bold;
		font-size: 14px;
	}

	.userName_view {
		width: 280rpx;
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
		margin-bottom: 4rpx;
	}
</style>