<template>
	<view class="cteamStyle" :style="{'height':contentHeight}">
		<view style="width: 100%;height: 100%;">
			<u-tabs :list="list" :is-scroll="false" :current="current" @change="change" :active-color='mainColor' ></u-tabs>
			<u-empty v-if="g.length==0" text="暂无数据" mode="data"></u-empty>
			<template v-if="g.length > 0">
				<view  
				  style="
						height: calc(100vh - 50px);
						width: calc(100vw);
						overflow: hidden;
						
				  ">
					<scroll-view
						:scroll-y="true"
						:enable-back-to-top="true"
						:enable-flex="true"
						@scrolltolower="lower"
						:style="{ height: '100%' }">
						<view style="display: flex;flex-direction: column;align-items: center;">
							<view v-for="(item, index) in g" :key="index" class="listbox">
								<view class="box_top">
									
									<u-avatar :src="item.Photo"  size="110"></u-avatar>
									<view class="box_r">
										<view style="width: 100%;display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
											<view style="width: 190px;">
												<Text class='l_name'>{{item.UserName}}</Text>
											</view>
											<Text style='font-size: 12px;'>推广{{item.GeneralizeNum}}人</Text>
										</view>
										<Text style='font-size: 12px;'>注册时间：{{item.CreateDate}}</Text>
									</view>
								</view>
								<view class="box_b">
									<Text style='color: #BABABA;'>{{item.Income}}元</Text>
									<Text style='color: #BABABA;'>{{item.OrderNum}}个订单</Text>
								</view>
								
							</view>
						</view>
						<u-loadmore
						  :status="status"
						  :load-text="loadText"
						  :font-size="24"
						  :margin-top="20"
						  :margin-bottom="20"
						  bg-color="#f3f4f6"
						/>
					</scroll-view>
					
				</view>
			</template>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageTitle: "我的团队",
				contentHeight:0,
				mainColor:'',
				secondary:'',
				current:0,
				g:[],
				list:[
					{name: '一级分销'},
					{name: '二级分销'},
					{name: '三级分销'},
				],
				msg:{
					pageIndex: 1,
					pageSize:10,
					GradeId:1
				},
				page_count:1,
				status: "loadmore",
				loadText: {
				  loadmore: "轻轻上拉，加载更多",
				  loading: "努力加载中",
				  nomore: "没有更多了",
				},
			
			}
		},
	
		created(){
			 this.contentHeight = this.$utils.calcContentHeight(-40)+'px';
			 this.mainColor = this.$uiConfig.mainColor;
			 this.secondary = this.$uiConfig.secondary;
			 this.init()
		},
		mounted() {
			let currentPages = getCurrentPages();
			 let u = "/" + currentPages[currentPages.length-1].route;
			 let pages = wx.getStorageSync("basedata")
			   ? wx.getStorageSync("basedata").bar_title
			   : [];
			 pages.forEach((x) => {
			   if (x.value == u) {
			     this.pageTitle = x.new_name ? x.new_name : x.name;
			   }
			 });
			 uni.setNavigationBarTitle({
			   title: this.pageTitle,
			 });
		},
		methods: {
			init(){
				
				uni.showLoading({
					title: '加载中'
				});
				this.request2(
					{
						url: '/api/AppletUser/GetUserMyTeamPageList',
						data: this.msg
					},
							
				  (res) => {
					 uni.hideLoading();
					 this.g = this.g.concat(res.data.pageData);
					 this.page_count = res.data.pageCount;
					 if (this.page_count == 1) {
					   this.status = "nomore";
					 }
					
				  }
				);
			},
			change(index){
				this.current = index
				this.msg.GradeId = index+1;
				this.msg.pageIndex=1;
				this.g=[]
				this.init()
			},
			lower(e) {
			  if (this.msg.pageIndex < this.page_count) {
				this.msg.pageIndex++;
				this.status = "loading";
				this.init();
			  } else {
				this.status = "nomore";
			  }
			},
			
		}
	}
</script>

<style>
.cteamStyle{
	background: #f3f4f6;
	
}
.cteamStyle .loading{
		width: 200rpx;
		height: 200rpx;
		background: #000000;
		opacity: 0.7;
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		position: fixed;
		left: 50%;
		top:30%;
		margin-left: -100rpx;
		z-index: 999;
	}
	.cteamStyle .listbox{
		width: 100%;
		background: #fff;
		padding: 0 15px;
		margin-bottom: 15px;
		display: flex;
		flex-direction: column;
		align-items: center;
		
	}
	.cteamStyle .box_top{
		width:100% ;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		padding: 10px 0 ;
		border-bottom: 1px solid #f5f5f5;
		
	}
	.cteamStyle .box_r{
		width: calc(100vw - 30px - 55px - 20px);
		height: 55px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
	.box_r .l_name{
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
	}
	.cteamStyle .box_b{
		width: 100%;
		padding: 15px 0;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}
</style>
