<template>
	<view class="content">
		<view class="content-money">
			<view class="status_bar">
				<!-- 这里是状态栏 -->
			</view>
			<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="http://ygs.hqgjsmc.com/baseimg/zhihuanjuan.png" mode=""></image>
			</view>
			<view class="money-box">
				<view class="">
					<view class="money">{{ userInfo.spread_total }}</view>
					<view>我的推广人数</view>
				</view>
				<!-- 			<view class="" style="width: 50%;">
					<view class="money">{{ order_count || '0' }}</view>
					<view>团队业绩</view>
				</view> -->
			</view>
		</view>
		<view class="navbar">
			<view class="nav-item" :class="{ current: grade === 0 }" @click="setType(0)">一级</view>
			<view class="nav-item" :class="{ current: grade == 1 }" @click="setType(1)">二级</view>
		</view>


		<scroll-view class="list-scroll-content" scroll-y @scrolltolower="userSpreadNewList">
			<!-- 空白页 -->
			<!-- <empty v-if="recordList.length === 0"></empty> -->

			<!-- 订单列表 -->
			<view v-for="(item, index) in recordList" :key="index" class="order-item flex">
				<view class="title-box flex_item">
					<view class="title-avatar">
						<image :src="item.avatar|| '../../../static/error/missing-face.png'" style="width: 100rpx;height: 100rpx;"></image>
					</view>
					<view class="list_tpl">
						<view class="title">
							<text>{{ item.nickname || '' }}</text>
						</view>
						<view class="time">
							<text>{{ item.spread_time }}</text>
						</view>
					</view>
				</view>
			</view>
			<!-- <uni-load-more :status="tabItem.loadingType"></uni-load-more> -->
			<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
		</scroll-view>


	</view>
</template>
<!-- <template>
	<view :style="viewColor">
		<view class="promoter-list">
			<view class='promoterHeader'>
				<view class='headerCon acea-row row-between-wrapper'>
					<view>
						<view class='name'>推广人数</view>
						<view><text class='num'>{{userInfo.spread_total}}</text>人</view>
					</view>
					<view class='iconfont icon-tuandui'></view>
				</view>
			</view>
			<view class='nav acea-row row-around'>
				<view :class="grade == 0 ? 'item on' : 'item'" @click='setType(0)'>一级({{userInfo.one_level_count}})</view>
				<view :class="grade == 1 ? 'item on' : 'item'" @click='setType(1)'>二级({{userInfo.two_level_count}})</view>
			</view>
			<view class='search acea-row row-between-wrapper'>
				<view class='input'><input placeholder='点击搜索会员名称' placeholder-class='placeholder' v-model="keyword" @confirm="submitForm" confirm-type='search' name="search"></input></view>
				<button class='iconfont icon-sousuo2' @click="submitForm"></button>
			</view>
			<view class='list'>
				<view class="sortNav acea-row row-middle">	
					<view class="sortItem" @click='setSort("spread_count ASC")' v-if="sort == 'spread_count DESC'">团队排序
						<image :src="domain+'/static/diy/sort1'+keyColor+'.png'"></image>
					</view>
					<view class="sortItem" @click='setSort("")' v-else-if="sort == 'spread_count ASC'">团队排序
						<image :src="domain+'/static/diy/sort3'+keyColor+'.png'"></image>
					</view>
					<view class="sortItem" @click='setSort("spread_count DESC")' v-else>团队排序
						<image src="/static/images/sort2.png"></image>
					</view>
					<view class="sortItem" @click='setSort("pay_price ASC")' v-if="sort == 'pay_price DESC'">金额排序
						<image :src="domain+'/static/diy/sort1'+keyColor+'.png'"></image>
					</view>
					<view class="sortItem" @click='setSort("")' v-else-if="sort == 'pay_price ASC'">金额排序
						<image :src="domain+'/static/diy/sort3'+keyColor+'.png'"></image>
					</view>
					<view class="sortItem" @click='setSort("pay_price DESC")' v-else>金额排序
						<image src="/static/images/sort2.png"></image>
					</view>
					<view class="sortItem" @click='setSort("pay_count ASC")' v-if="sort == 'pay_count DESC'">订单排序
						<image :src="domain+'/static/diy/sort1'+keyColor+'.png'"></image>
					</view>
					<view class="sortItem" @click='setSort("")' v-else-if="sort == 'pay_count ASC'">订单排序
						<image :src="domain+'/static/diy/sort3'+keyColor+'.png'"></image>
					</view>
					<view class="sortItem" @click='setSort("pay_count DESC")' v-else>订单排序
						<image src="/static/images/sort2.png"></image>
					</view>
				</view>
				<block v-for="(item,index) in recordList" :key="index">
					<view class='item acea-row row-between-wrapper'>
						<view class="picTxt acea-row row-between-wrapper">
							<view class='pictrue'>
								<image :src='item.avatar ? item.avatar : "/static/images/f.png"'></image>
							</view>
							<view class='text'>
								<view class='name line1'>{{item.nickname}}</view>
								<view>加入时间: {{item.spread_time}}</view>
							</view>
						</view>
						<view class="right">
							<view><text class='num t-color'>{{item.spread_count ? item.spread_count : 0}}</text>人</view>
							<view><text class="num">{{item.pay_count ? item.pay_count : 0}}</text>单</view>
							<view><text class="num">{{item.pay_price ? item.pay_price : 0}}</text>元</view>
						</view>
					</view>
				</block>
			</view>
		</view>
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
	</view>
</template> -->

<script>
	// +----------------------------------------------------------------------
	// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
	// +----------------------------------------------------------------------
	// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
	// +----------------------------------------------------------------------
	// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
	// +----------------------------------------------------------------------
	// | Author: CRMEB Team <admin@crmeb.com>
	// +----------------------------------------------------------------------
	import {
		spreadPeople,
		getUserInfo,
		spreadInfo
	} from '@/api/user.js';
	import {
		mapGetters
	} from "vuex";
	import authorize from '@/components/Authorize';
	import {
		HTTP_REQUEST_URL
	} from '@/config/app';
	export default {
		components: {
			authorize
		},
		data() {
			return {
				domain: HTTP_REQUEST_URL,
				total: 0,
				totalLevel: 0,
				teamCount: 0,
				page: 1,
				limit: 20,
				keyword: '',
				sort: '',
				grade: 0,
				status: false,
				recordList: [],
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false, //是否隐藏授权
				userInfo: {}
			};
		},
		computed: mapGetters(['isLogin', 'viewColor', 'keyColor']),
		onLoad() {
			if (this.isLogin) {
				this.userSpreadNewList();
				this.getUserInfo()
			} else {
				this.isAuto = true;
				this.isShowAuth = true
			}
		},
		onShow: function() {
			if (this.is_show) {
				this.userSpreadNewList();
				this.getUserInfo();
			}
		},
		onHide: function() {
			this.is_show = true;
		},
		methods: {
			toBack() {
				uni.switchTab({
					url: '/pages/user/index'
				})
			},
			getUserInfo() {
				spreadInfo().then(res => {
					this.userInfo = res.data
				});
			},
			onLoadFun: function(e) {
				this.isShowAuth = false;
				this.userSpreadNewList();
				this.getUserInfo()
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
			setSort: function(sort) {
				let that = this;
				that.sort = sort;
				that.page = 1;
				that.limit = 20;
				that.status = false;
				that.$set(that, 'recordList', []);
				that.userSpreadNewList();
			},
			// setKeyword: function(e) {
			// 	this.keyword = e.detail.value;
			// },
			submitForm: function() {
				this.page = 1;
				this.limit = 20;
				this.status = false;
				this.$set(this, 'recordList', []);
				this.userSpreadNewList();
			},

			setType: function(grade) {
				if (this.grade != grade) {
					this.grade = grade;
					this.page = 1;
					this.limit = 20;
					this.keyword = '';
					this.sort = '';
					this.status = false;
					this.$set(this, 'recordList', []);
					this.userSpreadNewList();
				}
			},
			userSpreadNewList: function() {
				let that = this;
				let page = that.page;
				let limit = that.limit;
				let status = that.status;
				let keyword = that.keyword;
				let sort = that.sort;
				let grade = that.grade;
				let recordList = that.recordList;
				let recordListNew = [];
				if (status == true) return;
				spreadPeople({
					page: page,
					limit: limit,
					keyword: keyword,
					level: grade + 1,
					sort: sort,
				}).then(res => {
					let len = res.data.list.length;
					let recordListData = res.data.list;
					recordListNew = recordList.concat(recordListData);
					that.total = res.data.total;
					that.totalLevel = res.data.totalLevel;
					that.teamCount = that.$util.$h.Add(Number(res.data.total), Number(res.data.totalLevel));
					that.status = limit > len;
					that.page = page + 1;
					that.$set(that, 'recordList', recordListNew);
				});
			}
		},
		// onReachBottom: function() {
		// 	this.userSpreadNewList();
		// }
	}
</script>

<!-- <style scoped lang="scss">
	.promoterHeader {
		background-image: linear-gradient(to right, var(--view-bntColor21) 0%, var(--view-bntColor22) 100%);
	}
	.t-color {
		color: var(--view-theme);
	}
	.promoter-list .nav {
		background-color: #fff;
		height: 86rpx;
		line-height: 86rpx;
		font-size: 28rpx;
		color: #282828;
		border-bottom: 1rpx solid #eee;
	}

	.promoter-list .nav .item.on {
		border-bottom: 5rpx solid var(--view-theme);
		color: var(--view-theme);
	}

	.promoter-list .search {
		width: 100%;
		background-color: #fff;
		height: 86rpx;
		padding-left: 30rpx;
		box-sizing: border-box;
	}

	.promoter-list .search .input {
		width: 610rpx;
		height: 60rpx;
		border-radius: 50rpx;
		background-color: #f5f5f5;
		text-align: center;
		position: relative;
	}

	.promoter-list .search .input input {
		height: 100%;
		font-size: 26rpx;
		width: 610rpx;
		text-align: center;
	}

	.promoter-list .search .input .placeholder {
		color: #bbb;
	}

	.promoter-list .search .input .iconfont {
		position: absolute;
		right: 28rpx;
		color: #999;
		font-size: 28rpx;
		top: 50%;
		transform: translateY(-50%);
	}

	.promoter-list .search .iconfont {
		font-size: 45rpx;
		color: #515151;
		width: 110rpx;
		height: 60rpx;
		line-height: 60rpx;
	}

	.promoter-list .list {
		margin-top: 12rpx;
	}

	.promoter-list .list .sortNav {
		background-color: #fff;
		height: 76rpx;
		border-bottom: 1rpx solid #eee;
		color: #333;
		font-size: 28rpx;
	}

	.promoter-list .list .sortNav .sortItem {
		text-align: center;
		flex: 1;
	}

	.promoter-list .list .sortNav .sortItem image {
		width: 24rpx;
		height: 24rpx;
		margin-left: 6rpx;
		vertical-align: -3rpx;
	}

	.promoter-list .list .item {
		background-color: #fff;
		border-bottom: 1rpx solid #eee;
		height: 152rpx;
		padding: 0 30rpx 0 20rpx;
		font-size: 24rpx;
		color: #666;
	}

	.promoter-list .list .item .picTxt {
		width: 440rpx;
	}

	.promoter-list .list .item .picTxt .pictrue {
		width: 106rpx;
		height: 106rpx;
		border-radius: 50%;
	}

	.promoter-list .list .item .picTxt .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 50%;
		border: 3rpx solid #fff;
		box-shadow: 0 0 10rpx #aaa;
		box-sizing: border-box;
	}

	.promoter-list .list .item .picTxt .text {
		width: 304rpx;
		font-size: 24rpx;
		color: #666;
	}

	.promoter-list .list .item .picTxt .text .name {
		font-size: 28rpx;
		color: #333;
		margin-bottom: 13rpx;
	}

	.promoter-list .list .item .right {
		width: 240rpx;
		text-align: right;
		font-size: 22rpx;
		color: #333;
	}

	.promoter-list .list .item .right .num{
		margin-right: 7rpx;
	}
</style>
 -->
<style lang="scss">
	page {
		background: #ffffff;
		height: 100%;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.content-money {
		position: relative;
		height: 480rpx;

		.content-bg {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			width: 750rpx;
			height: 480rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.body-title {
			height: 80rpx;
			text-align: center;
			font-size: 35rpx;
			position: relative;

			.header {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #fffeff;
				height: 80rpx;
				font-size: 36rpx;
				font-weight: 700;
				z-index: 9;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.goback-box {
				position: absolute;
				left: 18rpx;
				top: 0;
				height: 80rpx;
				display: flex;
				align-items: center;
			}

			.goback {
				z-index: 100;
				width: 34rpx;
				height: 34rpx;
			}
		}
	}

	.money-box {
		position: relative;
		z-index: 2;

		/* #ifdef H5 */
		padding-top: 80rpx;
		/* #endif */
		color: #ffffff;
		text-align: center;
		/* #ifdef APP-PLUS */
		height: 250rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		/* #endif */
		display: flex;
		justify-content: center;

		.money {
			font-size: 72rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #ffffff;
		}

		.text {
			font-size: 30rpx;
		}
	}

	// 列表

	.swiper-box {
		padding-top: 10rpx;

		
	}
	.order-item {
		padding: 20rpx 30rpx;
		line-height: 1.5;
	
		.title-box {
			width: 100%;
	
			.title-avatar {
				width: 100rpx;
				height: 100rpx;
				margin-right: 25rpx;
	
				// image {
				// 	width: 100rpx;
				// 	height: 100rpx;
				// 	border-radius: 50%;
				// }
			}
	
			.list_tpl {
				width: 85%;
	
				.title {
					font-size: $font-lg;
					color: $font-color-base;
					overflow: hidden; //超出的文本隐藏
					text-overflow: ellipsis; //溢出用省略号显示
					white-space: nowrap;
				}
	
				.time {
					margin-top: 15rpx;
					font-size: 22rpx;
					color: $font-color-light;
				}
			}
		}
	
		.money {
			color: #DB1935;
			font-size: $font-lg;
		}
	}

	.list-scroll-content {
		height: 100%;
	}

	.content {
		height: 100%;

		.empty-content {
			background-color: #ffffff;
		}
	}

	.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;
				}
			}
		}
	}
</style>
