<template>
	<view class="content">
		<!-- <view class="status_bar"></view> -->
		<view class="top-wrap flex">
			<view class="item">
				<view class="">
					下级人数
				</view>
				<view class="val">
					{{info.area_taem_count}}
				</view>
			</view>
			<view class="item">
				<view class="">
					团队业绩
				</view>
				<view class="val">
					￥{{info.area_taem_cashback_money || '0.00'}}
				</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> -->
		<view v-for="(item, index) in info.area_taem_lst" :key="index" class="order-item">
			<view class="top flex">
				<view class="name clamp">
					{{item.agent_user.nickname}}
				</view>
				<!-- <view class="name clamp">
					{{item.agent_user.phone}}
				</view> -->
				<!-- <image src="https://stx2.qiniu1314.com/static/img/level0.png" mode="" class="gp"></image> -->
				<view class="tc">
					{{item.name}}
				</view>
				<image src="../../static/icon/call.png" mode="" class="call" @click="makeCall(item.agent_user.phone)" v-if="item.agent_user.phone"></image>
			</view>
			<view class="info">
				<view class="info-item flex">
					<view class="">
						待处理单数：<text>{{item.sub_not_count + item.wy_not_count}}</text>
					</view>
					<view class="">
						完成单数：<text>{{item.wy_ok_count + item.sub_ok_count}}</text>
					</view>
					<view class="">
						<!-- 待处理单数：<text>5</text> -->
					</view>
				</view>
				<view class="info-val flex">
					<view class="">
						累计金额：<text>￥{{item.wy_cashback_money + item.wy_cashback_money}}</text>
					</view>
					<!-- <view class="more">
						查看明细<image src="../../static/index/in-go.png" mode=""></image>
					</view> -->
				</view>
			</view>
			
		</view>
	</view>
</template>
<script>
	import {
		myspread,
		agentInfo,
		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
		},
		
		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: [],
				info: {
					area_taem_lst: [],
					area_taem_count: 0,
					area_taem_cashback_money: 0
				}
			};
		},
		computed: {
			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin']),
			...mapState(['baseURL'])
		},
		onLoad(options) {},
		onShow() {
			this.agentInfo()
			// this.loadData();
			// getLevelList().then(res => {
			// 	console.log(res);
			// 	this.listList = res.data.list
			// })
		},
		methods: {
			makeCall(phone) {
				uni.makePhoneCall({
					phoneNumber: phone + ''
				})
			},
			agentInfo() {
				agentInfo().then(res => {
					console.log(res.data);
					this.info = res.data
				})
			},
			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>
