<template>
	<view class="content">
		<view class="content-money">
			<view class="status_bar"><!-- 这里是状态栏 --></view>
				<image class="tuiguang_bg" src="../../static/img/share.png"></image>
			<view class="money-box">
				<view class="goback-box" @click="toBack"><image class="goback" src="../../static/img/fanhui.png" mode=""></image></view>
				<view class="header">我的团队</view>
				<view class="money-frame">
					<!-- <view class="money_name">我的推广</view> -->
					<view class="money_num">
						<text class="money_ren">共</text>
						{{ all || '0' }}
						<text class="money_ren">人</text>
					</view>
				</view>
			</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" scroll-y @scrolltolower="loadData">
					<!-- 空白页 -->
					<!-- <empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></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.account }}</text>
								</view>
							</view>
						</view>
					</view>
					<!-- <uni-load-more :status="tabItem.loadingType"></uni-load-more> -->
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>
<script>
import { spread } from '@/api/user.js';
import { mapState, mapMutations } from 'vuex';
export default {
	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 {
			// 头部图高度
			maxheight: '',
			tabCurrentIndex: 0,
			navList: [
				{
					state: 0,
					text: '直接推荐',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页数
					limit: 10 //每次信息条数
				}
			],
			all: '',
			list: ''
		};
	},
	onLoad(options) {},
	onShow() {
		this.loadData();
	},
	methods: {
		// 页面跳转
		navto(e) {
			uni.navigateTo({
				url: e
			});
		},
		//获取收入支出信息
		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') {
				//防止重复加载
				return;
			}
			if (navItem.loadingType === 'noMore') {
				//防止重复加载
				return;
			}
			// 修改当前对象状态为加载中
			navItem.loadingType = 'loading';
			spread({
				page: navItem.page,
				limit: navItem.limit
			})
				.then(({ data }) => {
					console.log(data)
					this.total = data.total;
					this.totalLevel = data.totalLevel;
					this.all = this.total + this.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);
				});
		},
		//swiper 切换
		changeTab(e) {
			this.tabCurrentIndex = e.target.current;
			this.loadData('tabChange');
		},
		//顶部tab点击
		tabClick(index) {
			this.tabCurrentIndex = index;
		},
		// 点击返回 我的页面
		toBack() {
			uni.switchTab({
				url: '/pages/user/user'
			});
		}
	}
};
</script>

<style lang="scss">
.status_bar {
	height: var(--status-bar-height);
	width: 100%;
}
page {
	background: #f8f8f8;
	height: 100%;
}

.content-money {
	background: $page-color-base;
	position: relative;
	.tuiguang_bg {
		width: 750rpx;
		height: 484rpx;
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
	}
	.buttom-box {
		position: relative;
		background-color: #ffffff;
		text-align: center;
		margin: 0 30rpx;
		padding: 30rpx 0;
		border-radius: $border-radius-sm;
		margin-top: -80rpx;

		.buttom {
			font-size: $font-lg;
			flex-grow: 1;

			.money {
				font-weight: bold;
				font-size: 32rpx;
				color: #ff0000;
			}
		}

		.text {
			color: #666666;
		}

		.interval {
			width: 2rpx;
			height: 60rpx;
			background-color: #eeeeee;
		}

		.icon {
			height: 50rpx;
			width: 48rpx;
			margin: 0 auto;

			.icon-img {
				width: 100%;
				height: 100%;
			}
		}
	}
}

.money-box {
	// background: $base-color;
	height: 484rpx;
	color: #ffffff;
	text-align: center;
	font-size: 35rpx;
	position: relative;

	// padding-top: 60rpx;
	.header {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 80rpx;
		font-size: 32rpx;
		font-weight: 700;
		z-index: 99;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.goback-box {
		position: absolute;
		left: 18rpx;
		top: 0;
		height: 80rpx;
		display: flex;
		align-items: center;
	}

	.goback {
		z-index: 100;
		width: 34rpx;
		height: 34rpx;
	}
	.right {
		position: absolute;
		top: 140rpx;
		right: 40rpx;
		text-align: right;
		line-height: 1;
		.right-num {
			font-size: 50rpx;
			font-family: PingFang SC;
			font-weight: bold;

			color: #ffffff;
		}
		.right-font {
			margin-top: 10rpx;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #ffffff;
		}
		.time {
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			line-height: 35px;
		}
	}
	.user {
		position: absolute;
		top: 140rpx;
		left: 34rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		z-index: 10;
		.avtor {
			width: 102rpx;
			height: 102rpx;
			border-radius: 50%;
			position: relative;
			.portrait {
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
			.he {
				position: absolute;
				height: 30rpx;
				bottom: -4rpx;
				left: 0;
				.image {
					width: 102rpx;
					height: 30rpx;
				}
			}
		}
		.name {
			margin-left: 30rpx;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			display: flex;
			justify-content: start;
			.name-left {
				width: 220rpx;
			}
			.name-right {
				margin-left: 20rpx;
				width: 50rpx;
				height: 60rpx;
				position: relative;
				image {
					width: 100%;
					height: 100%;
				}
				.level {
					position: absolute;
					top: 35%;
					left: 50%;
					margin-left: -12rpx;
					font-size: 20rpx;
				}
			}
		}
		.id {
			margin-left: 30rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
		}
	}

	.money_img {
		width: 100%;
		height: 120rpx;
		text-align: center;
		padding-top: 50rpx;
		padding-bottom: 135rpx;

		image {
			width: 120rpx;
			height: 120rpx;
			border: 4rpx solid #fd5f6f;
			border-radius: 50%;
		}
	}

	.money-frame {
		position: absolute;
		top: 0;
		width: 100%;
		padding-top: 200rpx;
	}
	.money_num {
		font-size: 72rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #ffffff;

		.money_ren {
			font-size: 36rpx;
		}
	}
}

.order-item {
	padding: 20rpx 30rpx;
	line-height: 1.5;

	.title-box {
		width: 100%;

		.title-avatar {
			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-base;
				color: $font-color-light;
			}
		}
	}

	.money {
		color: #db1935;
		font-size: $font-lg;
	}
}
</style>