<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>{{ count }}</text>
					人
				</view>
				<view class="renshu">我的互助团队人数</view>
			</view>
		</view>
		<view class="message">
			<view class="yeji">
				<view class="yeji-a">
					<view class="yeji-buttom">{{ shouru * 1 || 0 }}</view>
					<view class="yeji-top">收益</view>
				</view>
				<view class="border"></view>
				<view class="yeji-a">
					<view class="yeji-buttom">{{ zhichu * 1 || 0 }}</view>
					<view class="yeji-top">支出</view>
				</view>
			</view>
			<view class="back" @click="navBack()" v-if="fatherList.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 flex">
					<view class="subordinate-box" v-for="(item, index) in childList" @click="findChildren(item)">
						<view class="head1"><image :src="item.avatar || '/static/error/missing-face.png'" mode=""></image></view>
						<view class="name clamp">{{ item.nickname }}</view>
						<view class="phone clamp">{{ item.mobile }}</view>
					</view>
					<template v-if="childList.length < 3">
						<view class="subordinate-box" v-for="item in 3 - childList.length">
							<view class="head1"></view>
							<view class="name clamp"></view>
							<view class="phone clamp"></view>
						</view>
					</template>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { myActivity, activityDetail } from '@/api/market.js';
import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		return {
			count: '', //互助人数
			shouru: '', //我的收入
			zhichu: '', //我的支持
			name: '', //当前节点姓名
			phone: '', //当前节点手机号
			avatar: '', //当前节点头像
			id: '',
			childList: [], //当前节点的下级
			fatherList: []
		};
	},
	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;
		activityDetail({}, 1).then(({ data }) => {
			if (data.expend.length != 0) {
				this.zhichu = data.expend[0].money;
			} else {
				this.zhichu = 0;
			}
			if (data.income.length != 0) {
				this.shouru = data.income[0].money;
			} else {
				this.shouru = 0;
			}
		});
		this.loadData();
	},

	methods: {
		// 点击返回 我的页面
		toBack() {
			uni.navigateBack({});
		},
		async findChildren(item) {
			//存father
			this.fatherList.push({
				name: this.name,
				phone: this.phone,
				avatar: this.avatar,
				id: this.id
			});
			//设置新father

			this.id = item.id;
			await this.loadData();
			this.name = item.nickname;
			this.phone = item.mobile;
			this.avatar = item.avatar;
		},
		back() {
			let father = this.fatherList.pop();
			this.name = father.name;
			this.phone = father.phone;
			this.avatar = father.avatar;
			this.id = father.id;
			this.loadData();
		},
		loadData() {
			const obj = this;
			uni.showLoading({
				title: '加载中。。。',
				mask: true
			});
			myActivity({ uid: obj.id }, 1)
				.then(({ data }) => {
					obj.count = data.count;
					console.log(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();
				});
		}
	}
};
</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: flex-start;
			align-items: flex-start;
	
			.subordinate-box {
				flex: 1;
				display: flex;
				flex-direction: column;
				align-items: center;
	
				.head1 {
					position: relative;
					border-radius: 50%;
					background: #f1f1f1;
					width: 120rpx;
					height: 120rpx;
					.vip {
						position: absolute;
						bottom: 0;
						left: 10%;
						width: 94rpx;
						height: 32rpx;
						image {
							width: 100%;
							height: 100%;
							border-radius: 0;
						}
					}
					image {
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}
				}
	
				.name {
					max-width: 120rpx;
					margin-top: 10rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #ffffff;
				}
	
				.phone {
					max-width: 120rpx;
					margin-top: 10rpx;
					font-size: 22rpx;
					font-family: PingFang SC;
					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>
