<template>
	<view class="content">
		<view class="wrap">
			<view class="top-wrap flex">
				<view class="">
					<view class="">
						{{all|| '0'}}
					</view>
					<view class="tit">
						累计邀请
					</view>
				</view>
				<image src="../../static/img/yq.png" mode=""></image>
			</view>
			<view class="yq">
				<view class="ht"></view>
				<view class="info flex">
					<view class="">
						<view class="">
							邀请好友
						</view>
						<view class="tit">
							邀请更多好友获得更多奖励
						</view>
					</view>
					<view class="btn" @click="goYq">
						去邀请
					</view>
				</view>

			</view>
		</view>
		<view class="p-tit flex">
			<view class="line"></view>
			<view class="">推广列表</view>
			<view class="line"></view>
		</view>
		<swiper :current="tabCurrentIndex" :style="{ height: maxheight }" class="swiper-box" duration="300"
			@change="changeTab">
			<swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
				<scroll-view class="list-scroll-content" :style="{ height: maxheight }" scroll-y
					@scrolltolower="loadData">
					<empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0" :style="{ height: maxheight }"></empty>

					<view v-for="(item, index) in tabItem.orderList" :key="index" class="order-item flex">
						<view class="title-box flex_item">
							<view class="title-avatar">
								<image :src="item.avatar"></image>
							</view>
							<view class="list_tpl">
								<view class="title">
									<view class="title-name clamp">{{ item.nickname }}</view>
								</view>
								<view class="time">
									<text>{{ item.vip ? item.vip_name : '' }}</text>
								</view>
								<view class="time">
									<text>{{ item.time }}</text>
								</view>
							</view>
						</view>
					</view>
					<uni-load-more :status="tabItem.loadingType"></uni-load-more>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';

	import empty from '@/components/empty';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';

	import {
		myspread,
		getLevelList,
		getUser
	} from '@/api/user.js';

	export default {
		components: {
			empty,
			uniLoadMore
		},
		onReady(res) {
			var _this = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.swiper-box').boundingClientRect();
					query.exec(function(res) {
						_this.maxheight = resu.windowHeight - res[0].top + 'px';
						console.log('打印页面的剩余高度', _this.height);
					});
				},
				fail: res => {}
			});
		},
		data() {
			return {
				all: 0,
				tabCurrentIndex: 0,
				maxheight: '',
				navList: [{
						state: 0,
						text: '直接推荐',
						loadingType: 'more',
						orderList: [],
						page: 1, //当前页数
						limit: 10 //每次信息条数
					},
					{
						state: 1,
						text: '间接推荐',
						loadingType: 'more',
						orderList: [],
						page: 1, //当前页数
						limit: 10 //每次信息条数
					}
				],
			}
		},
		computed: {
			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin']),
			...mapState(['baseURL'])
		},
		onLoad() {

		},
		onShow() {
			this.loadData();
		},
		onReachBottom() {

		},
		methods: {
			goYq() {
				uni.navigateTo({
					url: '/pages/user/shareQrCode'
				})
			},
			//获取收入支出信息
			async loadData(source) {
				//这里是将订单挂载到tab列表下
				let index = this.tabCurrentIndex;
				let navItem = this.navList[index];
				let state = navItem.state;
				if (source === 'tabChange' && navItem.loaded === true) {
					//tab切换只有第一次需要加载数据
					return;
				}
				if (navItem.loadingType === 'loading' || navItem.loadingType === 'noMore') {
					//防止重复加载
					return;
				}
				// 修改当前对象状态为加载中
				navItem.loadingType = 'loading';
				myspread({
						page: navItem.page,
						limit: navItem.limit,
						grade:state,
						uid: this.userInfo.uid
					})
					.then(({
						data
					}) => {
						console.log(data,'的');
						this.order = data.order
						this.zt_order = data.zt_order
						this.jt_order = data.jt_order
						this.all = data.total;
						// this.totalLevel = data.totalLevel
						if (data.list.length > 0) {
							this.list = data.list;
							navItem.orderList = navItem.orderList.concat(data.list);
							navItem.page++;
						}
						this.$nextTick(function() {
							if (navItem.limit == data.list.length) {
								//判断是否还有数据, 有改为 more, 没有改为noMore
								navItem.loadingType = 'more';
								return;
							} else {
								//判断是否还有数据, 有改为 more, 没有改为noMore
								navItem.loadingType = 'noMore';
							}
						});
						this.$set(navItem, 'loaded', true);
					})
					.catch(e => {
						console.log(e);
					});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		width: 750rpx;
		background: linear-gradient(180deg, #FE653C, #FE653C, #f8f8f8);
		padding-top: 60rpx;
	}

	.top-wrap {
		width: 674rpx;
		height: 186rpx;
		background-color: #fff;
		margin: auto;
		position: relative;
		border-radius: 20rpx 20rpx 0 0;
		font-weight: bold;
		font-size: 70rpx;
		color: #242424;
		padding: 0 50rpx 0 40rpx;

		.tit {
			font-weight: 500;
			font-size: 28rpx;
			color: #727272;
		}

		image {
			width: 217rpx;
			height: 192rpx;
		}
	}

	.ht {
		width: 702rpx;
		height: 46rpx;
		background: #FFC7B8;
		border-radius: 25rpx;
	}

	.yq {
		width: 702rpx;
		height: 202rpx;
		background: #FFF1ED;
		border-radius: 25rpx;
		margin: -46rpx auto 0;

		.info {
			height: 155rpx;
			padding: 0 50rpx 0 47rpx;
			font-weight: bold;
			font-size: 34rpx;
			color: #242424;

			.btn {
				width: 139rpx;
				line-height: 63rpx;
				border-radius: 10rpx;
				border: 1px solid #D9D7CA;
				font-weight: bold;
				font-size: 29rpx;
				color: #242424;
				text-align: center;
			}

			.tit {
				font-weight: 500;
				font-size: 24rpx;
				color: #81827D;
				padding-top: 15rpx;
			}
		}

	}

	.p-tit {
		justify-content: center;
		font-weight: 500;
		font-size: 30rpx;
		color: #333333;
		padding: 20rpx 0;

		.line {
			width: 43rpx;
			height: 1rpx;
			background: #D4D4D4;
			margin: 0 15rpx;
		}
	}
	.swiper-box {
		background-color: #fff;
		border-radius: 20rpx 20rpx 0 0;
		width: 702rpx;
		margin: auto;
	}
	.order-item {
		padding: 20rpx 30rpx;
		line-height: 1.5;
		// background-color: #fff;
		
		.title-box {
			width: 100%;
	
			.title-avatar {
				flex-shrink: 0;
				width: 100rpx;
				height: 100rpx;
				margin-right: 25rpx;
				border-radius: 100%;
	
				image {
					width: 100%;
					height: 100%;
					border-radius: 100%;
				}
			}
	
			.list_tpl {
				width: 85%;
				
				.title {
					display: flex;
					justify-content: flex-start;
					font-size: $font-lg;
					color: $font-color-base;
					overflow: hidden; //超出的文本隐藏
					text-overflow: ellipsis; //溢出用省略号显示
					white-space: nowrap;
					line-height: 1;
					text-align: center;
	
					.title-name {
						max-width: 40%;
					}
	
					.dl {
						margin-left: 10rpx;
						width: 93rpx;
						height: 32rpx;
						border-radius: 16rpx;
	
						image {
							width: 93rpx;
							height: 32rpx;
							border-radius: 16rpx;
						}
					}
	
					.class {
						display: inline-block;
						margin-left: 10rpx;
						padding: 6rpx;
						text-align: center;
						border: 1px solid #2e58ff;
						border-radius: 16rpx;
						font-size: 20rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #2e58ff;
					}
				}
	
				.time {
					font-size: $font-lg;
					color: $font-color-light;
				}
				.star {
					justify-content: flex-start;
					image {
						width: 36rpx;
						height: 36rpx;
					}
				}
			}
		}
	
		.money {
			width: 50%;
			text-align: right;
			color: #db1935;
			font-size: $font-lg;
		}
	}
	
</style>