<template>
	<view class="content">
		<view class="user-top">
			<!-- <view class="select-time">
				<picker mode="date" @change="bindDateChange" fields="month">
					<view class="uni-input">{{showdate}}</view>
				</picker>
				<image src="../../static/img/downjian.png" mode="widthFix"></image>
			</view> -->
			<view class="top-val">
				{{count}}
			</view>
			<view class="top-tit">
				转介绍人数
			</view>
		</view>
		<!-- <view class="sz-wrap">
			<view class="sz-item">
				<view class="sz-tit">
					上月收入
				</view>
				<view class="sz-val">
					200
				</view>
			</view>
			<view class="jg">

			</view>
			<view class="sz-item">
				<view class="sz-tit">
					累计收入
				</view>
				<view class="sz-val">
					200
				</view>
			</view>
		</view> -->
		<!-- <view class="navbar">
			<view v-for="(item, index) in navlist" :key="index" class="nav-item"
				:class="{ current: tabCurrentIndex === index }" @click="tabClick(index)">{{ item.title }}</view>
		</view> -->
		<swiper :current="tabCurrentIndex" :style="{ height: height }" class="swiper-box" duration="300" disable-touch>
			<swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navlist" :key="tabIndex">
				<scroll-view scroll-y="true" class="list-scroll-content" @scrolltolower="loadData">
					<!-- 空白页 -->
					<u-empty text="暂无数据" mode="list" v-if="tabItem.loaded && tabItem.list.length == 0"></u-empty>

					<!-- 订单列表 -->
					<view class="order-item" v-for="(item, index) in tabItem.list" :key="index">
						<image :src="item.avatar" mode="" class="logo"></image>
						<view class="title-box">
							<view class="title">
								<!-- <text>{{ item.mark }}</text> -->
								{{item.name}}
							</view>
							<view class="time">
								<!-- <text>{{ item.create_time }}</text> -->
								{{$utils.formatDate(item.createTime)}}
							</view>
						</view>
						<!-- <view class="money" @click="goPage('/pagesS/yg/fcxq')">
							<view>{{ (item.pm == 0 ? '-' : '+') + 1500 }}</view>
							<image src="../../static/img/downright.png" mode=""></image>
						</view> -->
					</view>
					<u-loadmore :status="tabItem.loadingType" />
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				count: 0,
				showdate: '',
				tabCurrentIndex: 0,
				height: '',
				id: '',
				navlist: [{
						status: 0,
						title: '收入',
						list: [],
						page: 1,
						pageSize: 100,
						loaded: false,
						loadingType: 'loadmore'
					},
					{
						status: 1,
						title: '扣除',
						list: [],
						page: 1,
						pageSize: 100,
						loaded: false,
						loadingType: 'loadmore'
					}
				]
			}
		},
		onLoad(opt) {},

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

		},
		onReady() {
			var _this = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.swiper-box').boundingClientRect();
					query.exec(function(res) {
						_this.height = resu.windowHeight - res[0].top + 'px';
						console.log('打印页面的剩余高度', _this.height);
					});
				},
				fail: res => {}
			});
		},
		methods: {
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
				this.loadData('tab')
			},
			// 选择年月
			bindDateChange(e) {
				let time = e.detail.value.split('-')
				this.showdate = time[0] + '年' + time[1] + '月'

				this.loadData('reload')
			},
			// 获取当前年月
			getTime() {
				let date = new Date()
				this.showdate = date.getFullYear() + '年' + (date.getMonth() + 1) + '月'
				this.loadData()
			},
			// 获取数据
			loadData(type) {
				let that = this
				let index = that.tabCurrentIndex
				let item = that.navlist[index]
				if (type == 'reload') {
					item.loaded = false
					item.loadingType = 'loadmore'
					item.page = 1
					item.list = []
				}
				if (type == 'tab' && item.loaded) {
					return
				}
				if (item.loadingType == 'loading' || item.loadingType == 'nomore') {
					return
				}

				item.loadingType = 'loading'
				that.$u.api.referral({
					page: item.page,
					pageSize: item.pageSize
				}).then(res => {
					that.count = res.count
					if (res.data.length > 0) {
						item.list = item.list.concat(res.data)
					}
					item.page++
					item.loaded = true
					if (item.pageSize == res.data.length) {
						item.loadingType = 'loadmore'
					} else {
						item.loadingType = 'nomore'
					}
					that.count = res.count
				})

			},
		}
	}
</script>

<style lang="scss">
	.user-top {
		width: 100%;
		height: 400rpx;
		background-color: #4075d6;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		padding-bottom: 60rpx;

		// position: relative;
		.top-tit {
			font-size: 30rpx;
			font-weight: bold;
			color: #FFFFFF;
		}

		.top-val {
			font-size: 72rpx;
			font-weight: 500;
			color: #FFFFFF;
		}

		.select-time {
			position: absolute;
			top: 30rpx;
			right: 30rpx;
			font-size: 26rpx;
			font-weight: 500;
			color: #fff;
			display: flex;
			align-items: center;

			image {
				width: 17rpx;
				margin-left: 10rpx;
			}
		}
	}

	.sz-wrap {
		width: 670rpx;
		height: 186rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
		border-radius: 20rpx;
		margin: -90rpx auto 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;

		.jg {
			width: 2rpx;
			height: 74rpx;
			background: #DCDFE6;
		}

		.sz-item {
			width: 330rpx;
			height: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-size: 30rpx;
			font-weight: bold;

			.sz-tit {
				color: #999999;

			}

			.sz-val {
				margin-top: 30rpx;
				color: #181818;
			}
		}
	}

	.navbar {
		margin-top: 20rpx;
		display: flex;
		height: 88rpx;
		padding: 0 5px;
		background: #fff;
		box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
		position: relative;
		z-index: 10;

		.nav-item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 15px;
			color: #999999;
			position: relative;

			&.current {
				color: #000;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					border-bottom: 2px solid #fe5b38;
				}
			}
		}
	}

	//列表
	.swiper-box {
		margin-top: 20rpx;
		padding: 0 20rpx;
		background-color: #fff;

		.order-item:last-child {
			margin-bottom: 60rpx;
		}

		.order-item {
			width: 100%;
			// background-color: red;
			padding: 20rpx 30rpx;
			line-height: 1.5;
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #F0F0F0;

			.logo {
				flex-shrink: 0;
				margin-right: 20rpx;
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				background-color: #eee;
			}

			.title-box {
				flex-grow: 1;
				padding-right: 50rpx;

				.title {
					font-size: 30rpx;
					color: #333333;
				}

				.time {
					font-size: 26rpx;
					color: #AEAEAE;
				}
			}

			.money {
				color: #fd5b23;
				min-width: 150rpx;
				font-size: 26rpx;
				text-align: right;
				display: flex;
				align-items: center;
				justify-content: flex-end;

				image {
					width: 10rpx;
					height: 20rpx;
					margin-left: 15rpx;
				}

				.status {
					color: #AEAEAE;
				}
			}
		}
	}

	.list-scroll-content {
		background: #ffffff;
		height: 100%;
	}
</style>
