<template>
	<view class="content">
		<view class="top hflex acenter jbetween">
			<text>邀请人</text>
			<view class="name" v-if="user.invite_code">{{user.parent_username}}</view>
			<text @click="tobind" v-else>绑定邀请人</text>
		</view>
		<view class="list">
			<view class="title">我的邀请</view>
			<view class="list-item hflex acenter jbetween" v-for="(item,index) in invite_list" :key="index">
				<view class="hflex acenter user">
					<image :src="item.avatar" mode="aspectFill"></image>
					<text>{{item.username}}</text>
				</view>
				<view class="time">{{item.created_at}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				user: {},
				invite_list: [],
				page: 1,
				last_page: 1,
			}
		},
		onLoad() {
			that = this
			
		},
		onShow() {
			this.getuser()
			this.page = 1
			this.invite_list = []
			this.getlist()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.getlist()
			} else {
				uni.$u.toast('已经到底了')
				return
			}
		},
		methods: {
			tobind() {
				uni.navigateTo({
					url: '/pageC/invite-bind'
				})
			},
			getuser() {
				$api.req({
					url: 'user/info',
					method: 'GET'
				}, function(res) {
					if (res.code == 10000) {
						that.user = res.data
					}
				})
			},
			getlist() {
				$api.req({
					url: 'user/children',
					method: 'get',
					data: {
						is_page: 1,
						page: that.page,
						limit: 10
					}
				}, function(res) {
					that.invite_list = that.invite_list.concat(res.data.list)
					that.last_page = res.data.last_page
				})
			}

		}
	}
</script>

<style lang="scss">
	.content {
		background: #F5F5F5;

		.top {
			height: 124rpx;
			box-sizing: border-box;
			padding: 40rpx 28rpx;
			background: #FFFFFF;
			border-top: 1px solid #F5F5F5;

			.name {
				flex: 1;
				font-size: 32rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #333333;
			}

			text:first-child {
				padding-right: 16rpx;
				font-size: 32rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #333333;
			}

			text:last-child {
				font-size: 28rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #00B0B0;
			}
		}

		.list {
			margin-top: 20rpx;
			min-height: calc(100vh - 144rpx);
			background: #FFFFFF;
			padding: 40rpx 28rpx;
			box-sizing: border-box;

			.title {
				font-size: 32rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #333333;
				padding: 0 0 10rpx;
			}

			.list-item {
				padding: 32rpx 0;
				border-bottom: 1px solid #F5F5F5;

				.user {
					image {
						width: 80rpx;
						height: 80rpx;
						border-radius: 50%;
						margin: 0 28rpx 0 0;
					}

					text {
						font-size: 32rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: #333333;
					}
				}

				.time {
					font-size: 28rpx;
					font-family: SFPro, SFPro;
					font-weight: 400;
					color: #666666;
				}
			}

			.list-item:last-child {
				border: none
			}
		}
	}
</style>