<template>
	<view class="main">
		<view class="btn btns">
			<image src="../../static/tuijian/mytuijian.png" mode=""></image>
			<view class="txt">
				我的上级：{{upUser!=null? upUser.realname:'总部'}}
				<!-- 我的推荐人：{{upUser!=null? upUser.realname:'总部'}} -->
			</view>
		</view>
		<view class="btn btns">
			<image src="../../static/tuijian/mine.png" mode=""></image>
			<view class="txt">
				我推荐的人
			</view>
		</view>
		<view class="infoboxData" v-if="tuijians.length<=0">暂无数据</view>
		<view class="infobox btns" v-for="( item , index ) in tuijians" :key="index">
			<view class="top">
				<image :src="item.avatar" mode=""></image>
				<view class="name">
					{{item.realname}}
				</view>
				<view class="time">
					注册时间:{{item.register_time}}
				</view>
				<view class="num">
					推广{{item.invite_num}}人
				</view>
			</view>
			<view class="bottom">
				<view class="xiaofei">
					消费{{item.consume_amount}}元
				</view>
				<view class="dans">
					{{item.complete_order_num}}个订单
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tuijians:[],
				param: {
					page: 0
				},
				loadingType: 0,
				upUser:{}
			}
		},
		onLoad() {
	      this.loadInviteUserList();
		},
		onReachBottom() {
			if (this.loadingType !== 0) {
				return;
			}
			this.loadingType = 1;
			this.loadPage();
		},
		onPullDownRefresh() {
			this.loadInviteUserList();
		},
		methods: {
			loadInviteUserList: function() {
				this.loadingType = 1;
				this.param.page = 0;
				this.loadPage();
			},
			loadPage: async function() {
				if (this.loadingType == 2) {
					return;
				}
				try {
					this.param.page++;
					let data = await this.$request.post('/api/userPromote/inviteUserList', this.param, false);
					console.log(data)
					if (data.code == 200) {
						this.upUser = data.data.upUser;
						if (data.data.list.current_page == 1) {
							this.tuijians = [];
						}
						this.tuijians = this.tuijians.concat(data.data.list.data);
						if (data.data.list.data.current_page == data.data.list.last_page) {
							this.loadingType = 2;
						} else {
							this.loadingType = 0;
						}
					} else {
						uni.showToast({
							icon: 'none',
							title: data.message
						});
						this.loadingType = 0;
					}
				} catch (e) {
					console.info(e)
					uni.showToast({
						icon: 'none',
						title: '数据获取失败'
					});
					this.loadingType = 0;
				}
				uni.stopPullDownRefresh();
			}
		}
	}
</script>

<style>
	page{
		background: #F5F5F5;
	}
	.main{
		width: 100vw;
		height: auto;margin-bottom: 20px;

	}
	.main .btns{
		width: 90vw;
		height: 60px;
		border-radius: 5px;
		background: #fff;
		margin:0 5vw;
		margin-top: 5vw;
	}
	.main .btn{
		display: flex;
	}
	.btn image{
		width: 20px;
		height: 20px;
		margin: 20px;
	}
	.btn .txt{
		width: auto;
		height: 20px;
		font-size: 32rpx;
		line-height: 20px;
		margin: 20px 0;
		font-family: PingFangSC-Regular, sans-serif;
	}
	.infoboxData{
		text-align: center;
		margin: 15px 0;
		font-size: 32rpx;
		font-family: PingFangSC-Regular, sans-serif;
	}
	.main .infobox{
		width: 90vw;
		height: auto;
		padding: 15px;
	}
	.infobox .top{
		width: 100%;
		height: 70px;
		position: relative;
		border-bottom: 1px solid #d8d8d8;
	}
	.top image{
		width: 60px;
		height: 60px;
		border-radius: 60px;
		background: #eee;
	}
	.top .name{
		width: auto;
		height: 30px;
		line-height: 30px;
		font-size: 16px;
		color: #555;
		position: absolute;
		top: 0;
		left: 70px;
	}
	.top .time{
		width: auto;
		height: 30px;
		line-height: 30px;
		color: #888;
		font-size: 14px;
		position: absolute;
		top: 30px;
		left: 70px;
	}
	.top .num{
		width: auto;
		height: 30px;
		line-height: 30px;
		padding: 0 10px;
		position: absolute;
		top: 0;
		right: 0;
		color: #777;
	}
	.infobox .bottom{
		width: 100%;
		height: 30px;
		line-height: 40px;
		display: flex;
		justify-content: space-between;
		color: #888;
		font-size: 14px;
	}
</style>
