<template>
	<view class="content">
		<u-list @scrolltolower="scrolltolower">
			<view class="myBalance">
				<view class="myBalanceTopModel">
					<view class="myBalanceNum">
						{{directAmount}}
					</view>
					<view class="myBalanceTitle">
						直推总积分
					</view>
				</view>
				<view class="myBalanceTopModel">
					<view class="myBalanceNum">
						{{indirectAmount}}
					</view>
					<view class="myBalanceTitle">
						间推总积分
					</view>
				</view>
			</view>
			<view class="productInfoTab">
				<u-tabs :list="tabList" :scrollable="false" lineColor="#D32063" :activeStyle="{color: '#D32063'}"
					:inactiveStyle="{color: '#666666'}" @click="click"></u-tabs>
			</view>
			<view class="pageList">

				<u-list-item v-for="(item, index) in pageList" :key="index">
					<view class="myUserInit">
						<view class="myUserImg">
							<image class="init_image" :src="item.avatar" mode=""></image>
						</view>
						<view class="myUserInitInfo">
							<view class="myUserInitInfoTop">
								<view class="myUserInitInfoTop-name">
									{{item.name}}
								</view>
								<view class="myUserInitInfoTop-num">
									<span class="initDataActive">{{item.divide_price}}</span>所得积分总额:
								</view>
							</view>
							<view class="myUserInitInfoBottom">
								{{item.addtime}}
							</view>
						</view>
					</view>
				</u-list-item>
				<u-empty :show="pageList.length == 0" mode="history"
					icon="http://cdn.uviewui.com/uview/empty/history.png"></u-empty>

			</view>
			<u-toast ref="uToast"></u-toast>
		</u-list>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: [{
					name: '直推',
				}, {
					name: '间推',
				}],
				pageList: [],
				directAmount: 0,
				indirectAmount: 0,
				divide_price: 0,
				pageNum: 1,
				itmenName: null
			}
		},
		onLoad() {
			this.pageList = [];
			this.pageNum = 1;
			this.itmenName = '直推'
			this.getMyshareList(1);
		},
		methods: {
			click(item) {
				this.pageList = [];
				this.pageNum = 1;
				this.itmenName = item.name;
				if (item.name == '直推') {
					this.getMyshareList(1)
				} else {
					this.getMyshareList(2)
				}
			},
			scrolltolower() {
				this.pageNum += 1;
				if (this.itmenName == '直推') {
					this.getMyshareList(1)
				} else {
					this.getMyshareList(2)
				}
			},
			//获取我的邀请
			getMyshareList(type) {
				this.$request('/my-friend', 'GET', {
					type,
					page: this.pageNum
				}).then(res => {
					console.log(res.data)
					this.directAmount = res.data.directAmount
					this.indirectAmount = res.data.indirectAmount
					this.pageList = [...this.pageList, ...res.data.list];
				}).catch(err => {
					uni.showToast({
						icon: 'error',
						title: '' + err.message
					})
				})
			},
		}
	}
</script>

<style lang="scss">
	.content {
		width: 100vw;
		height: 100vh;
		background: linear-gradient(to bottom, #f3d4d7, #f8f8f8, #f8f8f8);
	}

	.myUser {
		width: 100%;
		height: 126rpx;
		padding: 78rpx 0;
		text-align: center;

		.myUserNum {
			line-height: 88rpx;
			font-size: 64rpx;
			color: #D3195E;
			font-weight: 500;
			font-style: normal;
		}

		.myUserTitle {
			line-height: 38rpx;
			font-size: 24rpx;
			color: #666666;
		}
	}

	.pageList {
		width: calc(100% - 60rpx);
		margin: 0 30rpx;
		height: auto;
		overflow-y: scroll;
	}

	.myUserInit {
		width: calc(100% - 60rpx);
		padding: 30rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		background-color: #ffffff;
		border-radius: 24rpx;
		margin-bottom: 20rpx;

		.myUserImg {
			height: 92rpx;
			width: 92rpx;
			border-radius: 92rpx;
			overflow: hidden;
		}

		.myUserInitInfo {
			flex: 1;
			margin-left: 10rpx;
			height: 92rpx;

			.myUserInitInfoTop {
				height: 54rpx;
				line-height: 54rpx;
				display: flex;
				flex-direction: row;
				align-items: center;

				.myUserInitInfoTop-name {
					width: 40%;
					font-size: 28rpx;
					color: #333333;
					font-weight: 600;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.myUserInitInfoTop-num {
					width: 60%;
					font-size: 24rpx;
					color: #666666;
					font-weight: 600;
					display: flex;
					flex-direction: row-reverse;
				}
			}

			.myUserInitInfoBottom {
				height: 38rpx;
				line-height: 38rpx;
				width: 100%;
				font-size: 24rpx;
				color: #666666;
			}
		}
	}

	.initDataActive {
		color: #F6588D;
	}

	.myBalance {
		width: 100%;
		height: 126rpx;
		padding-top: 78rpx;
		text-align: center;
		display: flex;
		flex-direction: row;
		justify-content: space-around;

		.myBalanceTopModel {
			width: calc(100% / 3);

			.myBalanceNum {
				line-height: 88rpx;
				font-size: 56rpx;
				color: #D3195E;
				font-weight: 500;
				font-style: normal;
			}

			.myBalanceTitle {
				line-height: 38rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}

	}
</style>