<template>
	<view class="content">
		<!-- <view class="bg">
			<image src="../../static/img/jiedianBg.png" mode=""></image>
		</view> -->
		<!-- <view class="box">
			<view class="box-left">
				<view class="top">
					{{childrenNum}}
				</view>
				<view class="bottom">
					总人数
				</view>
			</view>
			<view class="box-left">
				<view class="top">
					{{money}}
				</view>
				<view class="bottom">
					收益
				</view>
			</view>
		</view> -->
		<view class="box-1">
			<view class="tuandui-box" v-for="item in childrenList" @click="next(item.info)">
				<view class="box-img" v-if="item.info">
					<image :src="item.info.avatar" mode=""></image>
				</view>
				<view class="box-content">
					<view class="content-top" v-if="item.info">
						<view class="content-top-left">
							<view class="name clamp">
								{{item.info.nickname}}
							</view>
							<!-- <view class="time">
								{{item.add_time | getTime}}加入
							</view> -->
						</view>
						<!-- <view class="content-top-right">
							收益：{{item.name == 'A'?A_achievement:item.name == 'B'?B_achievement:C_achievement}}
						</view> -->
					</view>
					<view class="content-top" v-else>
						暂无
					</view>
					<view class="content-bottom">
						<view class="xianlu">
							线路：{{item.name}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="btn" v-if="parentList.length != 0" @click="back()">
			返回上一层
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import {
		lookSubpoints,
		lookOneself
	} from '@/api/user.js'
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				dtailId: '',
				parentList: [], //父亲节点
				childrenList: [],
				jieList: [],
				childrenNum: '',
				limit: 10,
				page: 1,
				loadingType: 'more',
				money: '',
				A_achievement: '',
				B_achievement: '',
				C_achievement: ''
			};
		},
		filters: {
			getTime(val) {
				let str = ''
				if (val) {
					const date = new Date(val * 1000);
					const year = date.getFullYear();
					const mon = date.getMonth() + 1;
					const day = date.getDate();
					const hours = date.getHours();
					const minu = date.getMinutes();
					const sec = date.getSeconds();
					str = year + '-' + mon + '-' + day + ' ' + hours + ':' + minu + ':' + sec;
				}
				return str
			}
		},
		computed: {
			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
		},
		onLoad(option) {
			this.detailId = option.id
			this.A_achievement = this.userInfo.A_achievement
			this.B_achievement = this.userInfo.B_achievement
			this.C_achievement = this.userInfo.C_achievement
			this.lookDetail()
		},
		methods: {
			lookMyjiedian() {
				let obj = this
				lookOneself().then(res => {
					console.log(res);
					obj.jieList = res.data.points;
					console.log(obj.jieList, '11');
					obj.childrenNum = obj.jieList[0].children_num
					obj.money = obj.jieList[0].get
					console.log(obj.childrenNum, obj.money);
				})
			},
			lookDetail() {
				let obj = this
				if (obj.loadingType == 'loading' || obj.loadingType == 'noMore') {

					return
				}
				obj.loadingType = 'loading'
				lookSubpoints({
					uid: obj.detailId
				}).then(res => {
					let arr = Object.keys(res.data)
					arr.forEach(e => {
						let info = {
							name: '',
							info: ''
						};
						info.name = e;
						if (res.data[e]) {
							info.info = res.data[e]
						}
						obj.childrenList.push(info)
					})
					console.log(obj.childrenList);
				})
			},
			next(id) {
				console.log(id, "id");
				if (!id) {
					return
				}
				if (this.parentList.length == 11) {
					return
				}
				this.parentList.push(this.detailId)
				this.detailId = id.uid
				this.A_achievement = id.A_achievement
				this.B_achievement = id.B_achievement
				this.C_achievement = id.C_achievement
				this.loadingType = 'more'
				this.childrenList = []
				this.lookDetail()
			},
			back() {
				this.detailId = this.parentList.pop();
				this.loadingType = 'more'
				this.childrenList = [],
					this.lookDetail()
			}
		}
	}
</script>

<style lang="scss">
	page,
	.content {
		padding: 0;
		margin: 0;
		height: 100%;
		width: 100%;
		background: #F3F3F3;
	}

	.box-1 {
		// margin: 0 auto;
		background: #FFFFFF;
		margin-top: 40rpx;
	}

	.bg {
		position: relative;
		width: 750rpx;
		height: 360rpx;

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

	.box {

		position: relative;
		display: flex;
		justify-content: space-around;
		margin-top: -180rpx;

		.box-left {
			z-index: 99;
			width: 280rpx;
			height: 160rpx;
			display: flex;
			flex-direction: column;
			text-align: center;
			justify-content: center;
			background-color: #FFFFFF;
			border-radius: 10rpx;
		}

		.top {
			font-size: 36rpx;
			font-weight: bold;
		}

		.bottom {
			font-size: 24rpx;
			color: #999999;
			margin-top: 10rpx;
			font-weight: bold;

		}
	}

	.tuandui-box {
		margin: 0 auto;
		width: 690rpx;

		display: flex;

		padding: 20rpx;
		border-bottom: 2rpx solid #F3F3F3;
		;

		.box-img {
			border-radius: 50%;
			width: 80rpx;
			height: 80rpx;

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

		.box-content {
			margin-left: 15rpx;
			width: 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-between;


			.content-top {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.content-top-left {
					display: flex;
					justify-content: space-between;
					line-height: 40rpx;

					.name {
						width: 120rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						font-size: 30rpx;
						font-weight: bold;
					}

					.time {
						color: #999999;
						margin-left: 15rpx;
						font-size: 22rpx;
					}
				}

				.content-top-right {
					color: #303133;
					font-size: 26rpx;
				}
			}

			.content-bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.xianlu {
					color: #999999;
					font-size: 22rpx;
				}

				.number {
					color: #303133;
					font-size: 26rpx;
				}
			}
		}
	}

	.btn {
		position: fixed;
		bottom: 30rpx;
		left: 0;
		right: 0;
		margin: 0 auto;
		width: 604rpx;
		height: 90rpx;
		border: 2px solid #F21F5D;
		border-radius: 45rpx;
		font-size: 34rpx;
		font-family: SourceHanSansCN;
		font-weight: 400;
		color: #EF0E74;
		line-height: 90rpx;
		text-align: center;
	}
</style>