<template>
	<view class="content">
		<view class="status_bar"></view>
		<view class="top-wrap flex">
			<view class="item">
				<view class="">
					下级人数
				</view>
				<view class="val">
					90
				</view>
			</view>
			<view class="item">
				<view class="">
					团队业绩
				</view>
				<view class="val">
					￥900
				</view>
			</view>
		</view>
		<!-- <view class="content-money">
			
			
			<view class="body-title">
				<view class="goback-box" @click="toBack">
					<image class="goback" src="../../static/icon/fanhui.png" mode=""></image>
				</view>
				<view class="header">我的推广</view>
			</view>
			<view class="content-bg">
				<image src="../../static/img/tg-bg.png" mode=""></image>
			</view>
			<view class="money-box">
				<view class="money">{{ alls|| '0' }}</view>
				<view>我的团队</view>
			</view>
		</view> -->
		<swiper :current="tabCurrentIndex" :style="{ height: maxheight }" class="swiper-box" duration="300"
			@change="changeTab" disable-touch>
			<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"></empty>

					<view v-for="(item, index) in tabItem.orderList" :key="index" class="order-item">
						<view class="top flex">
							<view class="name clamp">
								{{item.nickname}}
							</view>
							<image src="https://stx2.qiniu1314.com/static/img/level0.png" mode="" class="gp"></image>
							<view class="tc">
							</view>
							<image src="../../static/icon/call.png" mode="" class="call"></image>
						</view>
						<view class="info">
							<view class="info-item flex">
								<view class="">
									待处理单数：<text>5</text>
								</view>
								<view class="">
									待处理单数：<text>5</text>
								</view>
								<view class="">
									待处理单数：<text>5</text>
								</view>
							</view>
							<view class="info-val flex">
								<view class="">
									累计金额：<text>￥5000</text>
								</view>
								<view class="more">
									查看明细<image src="../../static/index/in-go.png" mode=""></image>
								</view>
							</view>
						</view>
						
					</view>
					<uni-load-more :status="tabItem.loadingType"></uni-load-more>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>
<script>
	import {
		myspread,
		getLevelList
	} from '@/api/user.js';
	import empty from '@/components/empty';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	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 {
				// 头部图高度
				maxheight: '',
				tabCurrentIndex: 0,
				navList: [{
					state: 0,
					text: '直接推荐',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页数
					limit: 10 //每次信息条数
				},
				{
					state: 1,
					text: '间接推荐',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页数
					limit: 10 //每次信息条数
				}],
				alls: 0,
				all: '',
				list: '',
				totalLevel: '',
				order: '',
				zt_order: '',
				jt_order: '',
				listList: []
			};
		},
		computed: {
			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin']),
			...mapState(['baseURL'])
		},
		onLoad(options) {},
		onShow() {
			this.loadData();
			getLevelList().then(res => {
				console.log(res);
				this.listList = res.data.list
			})
		},
		methods: {
			showLevel(val) {
				let data = this.listList.find(item => item.grade == val.level)
				if(data) {
					return data.name
				}else {
					if(val.orderCount > 0) {
						return '会员'
					}else {
						return '粉丝'
					}
				}
			},
			// 页面跳转
			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';
				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.alls = data.all;
						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);
					});
			},
			//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">
	page {
		background: #f8f8f8;
		height: 100%;
	}
	
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
		background: #5dbc7c;
	}
	.top-wrap {
		background-color: $base-color;
		padding: 34rpx 32rpx;
		.item {
			width: 327rpx;
			height: 152rpx;
			padding: 30rpx 0 0 30rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			font-size: 28rpx;
			font-weight: bold;
			color: #303133;
			view {
				padding-bottom: 15rpx;
			}
			.val {
				font-size: 36rpx;
			}
		}
		
	}

	.order-item {
		width: 684rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		margin: 0 auto 20rpx;
		.top {
			width: 684rpx;
			height: 76rpx;
			background: #E9EEFF;
			border-radius: 16rpx 16rpx 0 0;
			justify-content: flex-start;
			padding:0 32rpx;
			.name {
				width: 150rpx;
			}
			.gp {
				width: 150rpx;
				height: 48rpx;
			}
			.tc {
				flex-grow: 1;
			}
			.call {
				width: 52rpx;
				height: 52rpx;
			}
		}
		.info {
			// height: 164rpx;
			.info-item {
				width: 618rpx;
				margin: auto;
				height: 80rpx;
				font-size: 28rpx;
				border-bottom:#DDE1EB 1px solid;
				text {
					font-weight: bold;
				}
				
			}
			.info-val {
				padding:0 33rpx;
				height: 80rpx;
				font-weight: 500;
				font-size: 28rpx;
				color: #303133;
				text {
					font-weight: bold;
					font-size: 28rpx;
					color: #FF6B2E;
				}
				
				.more {
					font-weight: 500;
					font-size: 24rpx;
					color: #999999;
				}
				image {
					display: inline-block;
					margin-left: 10rpx;
					width: 10rpx;
					height: 20rpx;
					vertical-align: middle;
				}
			}
		}
	}
	.list-scroll-content {
		padding-top: 20rpx;
	}
	
</style>
