<template>
	<view class="content">
		<view class="status_bar"><!-- 这里是状态栏 --></view>
		<!-- 头部 -->
		<view class="container">
			<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="jiedianbackground"><image src="../../static/img/myJ-bg.png" mode=""></image></view>
			<view class="number-box">
				<view class="number">
					<text>{{ 100 }}</text>
					人
				</view>
				<view class="renshu">我的互助团队人数</view>
			</view>
		</view>
		<view class="message">
			<view class="yeji">
				<view class="yeji-a">
					<view class="yeji-buttom">8000</view>
					<view class="yeji-top">收益</view>
				</view>
				<view class="border"></view>
				<view class="yeji-a">
					<view class="yeji-buttom">8000</view>
					<view class="yeji-top">支出</view>
				</view>
			</view>
			<view class="back" @click="navBack()" v-if="parentList.length > 0">
				<image src="../../static/img/zhengyi10.png" mode=""></image>
				返回
			</view>
			<view class="relation-box">
				<view class="relation">
					<view class="headbox">
						<view class="head">
							<view class="photo"><image v-if="avatar" :src="avatar"></image></view>
						</view>
					</view>
					<view class="information">
						<view class="name clamp">{{ name }}</view>
						<view class="cell clamp">{{ phone }}</view>
					</view>
				</view>
				<view class="sanchaji"><image src="../../static/img/sanchaji.png" mode=""></image></view>
				<view class="subordinate">
					<view class="headbox" v-if="listA" @click="nav('a')">
						<view class="head">
							<view class="photo"><image v-if="listA.avatar" :src="listA.avatar" mode="scaleToFill"></image></view>
						</view>
						<view class="head-name">{{ listA.nickname }}</view>
						<view class="head-phone">{{ listA.phone }}</view>
					</view>
					<view class="zhuce" v-else @click="open('A')"><view class="jia"></view></view>
					<view class="headbox" v-if="listB" @click="nav('b')">
						<view class="head">
							<view class="photo"><image :key="listB.id" :src="listB.avatar" mode="scaleToFill"></image></view>
						</view>
						<view class="head-name">{{ listB.nickname }}</view>
						<view class="head-phone">{{ listB.phone }}</view>
					</view>
					<view class="zhuce" v-else @click="open('B')"><view class="jia"></view></view>

					<view class="headbox" v-if="listC" @click="nav('c')">
						<view class="head">
							<view class="photo"><image v-if="listC.avatar" :src="listC.avatar" mode="scaleToFill"></image></view>
						</view>
						<view class="head-name">{{ listC.nickname }}</view>
						<view class="head-phone">{{ listC.phone }}</view>
					</view>
					<view class="zhuce" v-else @click="open('C')"><view class="jia"></view></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { getjiedian, getReferralList, addJiedian } from '@/api/user.js';
import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		return {
			bianhao: '1',
			a: 1,
			b: 2,
			c: 3,
			listA: '', //节点A
			listB: '', //节点B
			listC: '', //节点C
			name: '', //当前节点姓名
			phone: '', //当前节点手机号
			avatar: '', //当前节点头像
			id: '',
			uid: '',
			jiedianList: [],
			parentList: [], //保存打开层级用户数据
			parent_area: ''
		};
	},
	computed: {
		...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
	},
	onLoad() {
		this.name = this.userInfo.nickname;
		this.phone = this.userInfo.phone;
		this.avatar = this.userInfo.avatar;
		this.id = this.userInfo.uid;
		// this.loadData();
	},

	methods: {
		// 点击返回 我的页面
		toBack() {
			uni.navigateBack({
				
			})
		},
		//切换按钮
		radio(e) {
			this.bianhao = e;
		},
		//返回
		navBack() {
			const obj = this;
			// 删除
			let parent = obj.parentList.pop();
			console.log(parent);
			console.log(obj.parentList, 'navBack');
			// 保存回退后数据对象
			obj.name = parent.name;

			obj.avatar = parent.avatar;
			obj.id = parent.id;
			obj.listA = obj.listB = obj.listC = '';
			console.log(parent, '对象');
			obj.loadData();
		},
		loadData() {
			const obj = this;
			uni.showLoading({
				title: '加载中。。。',
				mask: true
			});
			getjiedian({}, this.id)
				.then(({ data }) => {
					uni.hideLoading();
					if (data.list.length != 0) {
						data.list.forEach(e => {
							console.log('e', e);
							let item = '';
							if (e.parent_area == 'A') {
								item = 'listA';
							} else if (e.parent_area == 'B') {
								item = 'listB';
							} else if (e.parent_area == 'C') {
								item = 'listC';
							}
							obj[item] = e;
							console.log(obj, '当前数据');
						});
					} else {
						return;
					}
				})
				.catch(e => {
					uni.hideLoading();
				});
		},
		nav(type) {
			const obj = this;
			// 保存当前选中的对象
			let item = '';
			if (type == 'a') {
				item = 'listA';
			} else {
				if (type == 'b') {
					item = 'listB';
				} else if (type == 'c') {
					item = 'listC';
				}
			}
			obj.parentList.push({
				name: obj.name,
				phone: obj.phone,
				avatar: obj.avatar,
				id: obj.id
			});
			console.log(obj.parentList, 's');
			obj.name = obj[item].nickname;
			obj.phone = obj[item].phone;
			obj.avatar = '';
			obj.$nextTick(function() {
				obj.avatar = obj[item].avatar;
				obj.id = obj[item].uid;
				obj.listA = '';
				obj.listB = '';
				obj.listC = '';
				obj.loadData();
			});
		}
	}
};
</script>

<style lang="scss">
page {
	padding: 0;
	margin: 0;
	height: 100%;
	background-color: #ffffff;
}
.status_bar {
	height: var(--status-bar-height);
	width: 100%;
}
.container {
	width: 750rpx;
	height: 460rpx;
	position: relative;
	.jiedianbackground {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		width: 750rpx;
		height: 460rpx;
		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;
		}
	}

	.number-box {
		margin-top: 100rpx;
		width: 750rpx;
		height: 400rpx;
		position: absolute;
		display: flex;
		flex-direction: column;
		align-items: center;

		.number {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;

			text {
				font-size: 72rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ffffff;
				line-height: 86rpx;
			}
		}

		.renshu {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
		}
	}
}

.message {
	padding: 0 30rpx;

	.relation-box {
		margin-top: 100rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		.relation {
			position: relative;
			display: flex;
			align-items: center;

			.headbox {
				position: absolute;
				// width: 154rpx;
				// height: 154rpx;

				.head {
					width: 154rpx;
					height: 154rpx;
					background: #2e58ff;
					box-shadow: 5rpx 0rpx 5rpx 0rpx rgba(110, 171, 78, 0.26);
					border-radius: 50%;
					overflow: hidden;

					.photo {
						width: 154rpx;
						height: 154rpx;

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

				.head-title {
					margin: -30rpx 30rpx 0 30rpx;
					width: 94rpx;
					height: 32rpx;

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

				// .head-name{
				// 	max-width: 100%;
				// 	font-size: 32rpx;
				// 	font-weight: bold;
				// 	color: #333333;
				// }
				// .head-phone{
				// 	font-size: 26rpx;
				// 	font-weight: 500;
				// 	color: #999999;
				// }
			}

			.information {
				margin-left: 77rpx;
				display: flex;
				padding: 20rpx 10rpx;
				flex-direction: column;
				width: 297rpx;
				height: 137rpx;
				background: #ffffff;
				border: 4rpx solid #2e58ff;
				border-radius: 10rpx;

				.name {
					text-align: left;
					margin-left: 80rpx;
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #2e58ff;
				}

				.cell {
					text-align: left;
					margin-left: 80rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #2e58ff;
				}
			}
		}

		.sanchaji {
			margin: 30rpx 0;
			width: 530rpx;
			height: 91rpx;

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

		.subordinate {
			width: 750rpx;
			display: flex;
			justify-content: space-around;

			.zhuce {
				width: 154rpx;
				height: 154rpx;

				.jia {
					width: 154rpx;
					height: 154rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;

					background: #e8e8e8;
					box-shadow: 5rpx 0rpx 5rpx 0rpx rgba(110, 171, 78, 0.26);
					border-radius: 50%;
					overflow: hidden;

					.jia_photo {
						font-size: 80rpx;
						line-height: 1;
						color: #a3a3a3;
					}

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

			.headbox {
				width: 33.3%;
				// height: 154rpx;
				display: flex;
				flex-direction: column;
				// flex-wrap: nowrap;
				align-items: center;
				padding: 0 10rpx;

				.head {
					width: 154rpx;
					height: 154rpx;
					background: #2e58ff;
					box-shadow: 5rpx 0rpx 5rpx 0rpx rgba(110, 171, 78, 0.26);
					border-radius: 50%;
					overflow: hidden;

					.photo {
						width: 154rpx;
						height: 154rpx;

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

				.head-title {
					margin: -30rpx 30rpx 0 30rpx;
					width: 94rpx;
					height: 32rpx;

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

				.head-name {
					margin-top: 20rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					width: 150rpx;
					padding-top: 10rpx;
					text-align: center;
					// margin: 30rpx 0 0 0;
					font-size: 32rpx;
					font-weight: bold;
					color: #333333;
				}

				.head-phone {
					margin: 15rpx 0 0 0;
					font-size: 26rpx;
					font-weight: 500;
					color: #999999;
				}
			}
		}
	}

	.yeji {
		position: relative;
		margin-top: -72rpx;
		width: 690rpx;
		height: 143rpx;
		background: #ffffff;
		box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
		border-radius: 10rpx;
		display: flex;
		align-items: center;

		.yeji-a {
			width: 50%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.yeji-top {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}

			.yeji-buttom {
				font-size: 42rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}
		}

		.border {
			width: 1rpx;
			height: 51rpx;
			background: #dddddd;
		}
	}

	.back {
		float: right;
		margin-top: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;

		image {
			width: 24rpx;
			height: 23rpx;
		}

		width: 104rpx;
		height: 39rpx;
		border: 2rpx solid #6eab4e;
		border-radius: 7rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #6eab4e;
	}
}
</style>
