<template>
	<view class="content">
		<!-- 头部 -->

		<view class="container">
			<view class="jiedianbackground">
				<image src="../../static/image/jiedian.png" mode=""></image>
			</view>
			<view class="number-box">
				<view class="number">
					<text>{{ userInfo.A_count + userInfo.B_count + userInfo.C_count }}</text>
					人
				</view>
				<view class="renshu">我的接点人数</view>
			</view>
		</view>
		<view class="message">
			<view class="yeji">
				<view class="yeji-a">
					<view class="yeji-top">A区业绩</view>
					<view class="yeji-buttom">￥{{ userInfo.A_achievement }}</view>
				</view>
				<view class="border"></view>
				<view class="yeji-a">
					<view class="yeji-top">B区业绩</view>
					<view class="yeji-buttom">￥{{ userInfo.B_achievement }}</view>
				</view>
				<view class="border"></view>
				<view class="yeji-a">
					<view class="yeji-top">C区业绩</view>
					<view class="yeji-buttom">￥{{ userInfo.C_achievement }}</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 class="head-title">
							<image src="../../static/image/jiedian1.png" mode=""></image>
						</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/image/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-title">
							<image src="../../static/image/jiedian1.png" mode="scaleToFill"></image>
						</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 class="jia_photo">
								+
								<!-- <image v-if='!listA.avatar' class="imgbox" src="../../static/img/jiedian07.png" mode="scaleToFill"></image> -->
							</view>
							<view class="font">
								点击添加
							</view>
						</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-title">
							<image src="../../static/image/jiedian1.png" mode="scaleToFill"></image>
						</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 class="jia_photo">
								+
								<!-- <image v-if='!listB.avatar' class="imgbox" src="../../static/img/jiedian07.png" mode="scaleToFill"></image> -->
							</view>
							<view class="font">
								点击添加
							</view>
						</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-title">
							<image src="../../static/image/jiedian1.png" mode="scaleToFill"></image>
						</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 class="jia_photo">
								+
								<!-- <image v-if='!listC.avatar' class="imgbox" src="../../static/img/jiedian07.png" mode="scaleToFill"></image> -->
							</view>
							<view class="font">
								点击添加
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="popup-box">
				<view class="backgroundimg">
					<image src="../../static/image/popup01.png" mode=""></image>
				</view>
				<view class="text">
					<view class="text-one">
						添加类型
					</view>
					<view class="text-two">
						请选择接点人添加类型
					</view>
				</view>
				<view class="box-choose">
					<view class="choose">
						<view class="zhuce">
							<view class="zhuce-img">
								<image src="../../static/image/popup03.png" mode="scaleToFill"></image>
							</view>
							<text>注册接点人</text>
						</view>
						<view class="radio">
							<radio value="2" :checked="bianhao==='3'" @click="radio('3')" color="#6EAB4E"></radio>
						</view>
					</view>
					<view class="choose">
						<view class="zhuce">
							<view class="zhuce-img">
								<image src="../../static/image/popup02.png" mode=""></image>
							</view>
							<text>选择接点人</text>
						</view>
						<view class="radio">
							<radio value="1" :checked="bianhao==='1'" color="#6EAB4E" @click="radio('1')">
							</radio>
						</view>
					</view>
					<view class="button" @click="navJiedian()">
						确认
					</view>
				</view>
			</view>
		</uni-popup>

	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import {
		getjiedian,
		getReferralList,
		addJiedian
	} from '@/api/user.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			uniPopup
		},
		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: {
			navJiedian() {
				this.$refs.popup.close();
				console.log(this.bianhao, 'bianhao')
				if (this.bianhao === '3') {
					uni.navigateTo({
						url: '/pages/public/register'
					})
				} else if (this.bianhao === '1') {
					uni.navigateTo({
						url: '/pages/user/selectList?patent=' + this.id + '&parent_area=' + this.parent_area
					})
				}
			},
			//切换按钮
			radio(e) {
				this.bianhao = e
			},
			//打开选择项
			open(are) {
				console.log(this.id)
				console.log('点击出现弹窗')
				this.$refs.popup.open();
				this.parent_area = are;
				console.log(this.parent_area);
			},
			//返回
			navBack() {
				const obj = this;
				// 删除
				let parent = obj.parentList.pop();
				console.log(parent);
				console.log(obj.parentList, 'navBack')
				// 保存回退后数据对象
				obj.name = parent.name;
				obj.phone = parent.phone;
				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();
				})
			},
			navto(type) {
				if (type == 'a') {
					uni.navigateTo({
						url: '/pages/public/register?id=' + this.id + '&area=A'
					});
				} else if (type == 'b') {
					uni.navigateTo({
						url: '/pages/public/register?id=' + this.id + '&area=B'
					});
				} else if (type == 'c') {
					if (this.listA == '' || this.listB == '') {
						this.$api.msg('请先注册完接点A和接点B');
					} else {
						uni.navigateTo({
							url: '/pages/public/register?id=' + this.id + '&area=C'
						});
					}
				}
			}
		}
	};
</script>

<style lang="scss">
	page {
		padding: 0;
		margin: 0;
		height: 100%;
		background-color: #ffffff;
	}

	.popup-box {
		width: 542rpx;
		height: 575rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		position: relative;
		margin: 0 auto;

		.backgroundimg {
			width: 542rpx;
			height: 138rpx;
			position: absolute;

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

		.text {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-top: 80rpx;
			margin-bottom: 50rpx;

			.text-one {
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
				margin-bottom: 10rpx;
			}

			.text-two {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #808080;
			}
		}

		.box-choose {
			margin: 0 40rpx;
			display: flex;
			flex-direction: column;

			.choose {
				display: flex;
				justify-content: space-between;
				margin: 25rpx 0;


				.zhuce {
					display: flex;

					.zhuce-img {
						width: 42rpx;
						height: 43rpx;

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

				text {
					margin-left: 10rpx;
					font-size: 28rpx;
					font-weight: 500;
					color: #333333;
				}

				.radio {}
			}

			.button {
				margin-top: 60rpx;
				width: 460rpx;
				text-align: center;
				line-height: 70rpx;
				height: 70rpx;
				background: #6EAB4E;
				border-radius: 10rpx;
				font-size: 28rpx;
				font-weight: 500;
				color: #FFFFFF;


			}
		}

	}

	.container {
		width: 750rpx;
		height: 400rpx;
		position: relative;

		.jiedianbackground {
			position: absolute;
			width: 750rpx;
			height: 400rpx;

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


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

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

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

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

	.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: #ef9e20;
						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 #6eab4e;
					border-radius: 10rpx;

					.name {
						text-align: left;
						margin-left: 70rpx;
						font-size: 32rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #3f7c1f;
					}

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

			.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: #ef9e20;
						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;
			justify-content: space-around;
			align-items: center;

			.yeji-a {
				display: flex;
				flex-direction: column;
				justify-content: space-around;
				align-items: center;

				.yeji-top {
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
					line-height: 35px;
				}

				.yeji-buttom {
					font-size: 34rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
					line-height: 35px;
				}
			}

			.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>
