<template>
	<view class="content">
		<view class="content-money">
			<view class="money-box">
			   <view class="money_name money">{{all}}</view>
			   <view class="money_name">推荐奖励</view>
			</view>
			<view class="flex buttom-box">
				<view class="buttom">
					<view class="money">{{total || 0}}</view>
					<text class="text">推荐用户</text>
				</view>
				<view class="interval"></view>
				<view class="buttom">
					<view class="money">{{totalLevel || 0}}</view>
					<text class="text">推荐医生</text>
				</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.text }}</view>
		</view>
		<swiper :current="tabCurrentIndex" :style="{ height: maxheight + 'px' }" 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">
									<text>{{ item.nickname }}</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 uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import empty from '@/components/empty';
export default {
	components: {
		empty,
		uniLoadMore,
	},
	onReady() {
		// 初始化获取页面宽度
		uni.createSelectorQuery()
			.select('.content')
			.fields(
				{
					size: true
				},
				data => {
					// console.log(data);
					// console.log(Math.floor((data.width / 750) * 300));
					// 保存头部高度
					this.maxheight = data.height - Math.floor((data.width / 750) * 570);
					// console.log(this.maxheight);
				}
			)
			.exec();
	},
	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 //每次信息条数
				}
			],
			all: 0,
			list:'',
			total:'',
			totalLevel:'',
		};
	},
	onLoad(options) {},
	onShow() {
		// this.loadData();	
	},
	methods: {
		// 页面跳转
		navto(e) {
			uni.navigateTo({
				url: e
			});
		},
		
		//swiper 切换
		changeTab(e) {
			this.tabCurrentIndex = e.target.current;
			// this.loadData('tabChange');
		},
		//顶部tab点击
		tabClick(index) {
			this.tabCurrentIndex = index;
		}
	}
};
</script>

<style lang="scss">
page {
	// background: #ffffff;
	height: 100%;
}
.content-money {
	padding-bottom: 30rpx;
	background: $page-color-base;
	.buttom-box {
		background-color: #ffffff;
		text-align: center;
		margin: 0 30rpx;
		padding: 30rpx 0;
		border-radius: $border-radius-sm;
		margin-top: -60rpx;
		.buttom {
			font-size: $font-lg;
			flex-grow: 1;
			.money{
				font-weight: bold;
				font-size: 32rpx;
				color: $font-color;
			}
		}
		.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:linear-gradient(52deg,rgba(126,153,254,1),rgba(151,143,250,1));
	height: 320rpx;
	color: #ffffff;
	text-align: center;
	padding-top: 60rpx;
	.money_name{
		width: 100%;
		text-align: center;
		font-size: 36rpx;
		padding-bottom: 25rpx;
	}
	.money {
		font-size: 44rpx;
	}
}

.navbar {
	display: flex;
	height: 40px;
	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: $font-color-dark;
		position: relative;
		&.current {
			color: $font-color;
			&:after {
				content: '';
				position: absolute;
				left: 50%;
				bottom: 0;
				transform: translateX(-50%);
				width: 44px;
				height: 0;
				border-bottom: 2px solid $font-color;
			}
		}
	}
}
// 列表

.swiper-box {
	padding-top: 10rpx;
	background: #ffffff;
	.order-item {
		margin: 0 24rpx;
		padding: 20rpx 0;
		line-height: 1.5;
		border-bottom: 1px solid #F0F0F0;
		.title-box {
			width: 100%;
			.title-avatar{
				width:80rpx;
				height:80rpx;
				border-radius:50%;
				margin-right: 20rpx;
				image{
					width: 100%;
					height: 100%;
					border-radius: 100%;
				}
			}
			.list_tpl{
				width: 85%;
				.title {
					font-size: $font-base + 2rpx;
					color: $font-color-base;
					font-weight: 500;
					overflow:hidden;            //超出的文本隐藏
					text-overflow:ellipsis;     //溢出用省略号显示
					white-space:nowrap; 
				}
				.time {
					font-size: 22rpx;
					color: $font-color-light;
				}
			}
		}
	}
}
.list-scroll-content {
	height: 100%;
}
.content {
	height: 100%;
	.empty-content {
		background-color: #ffffff;
	}
}
</style>
