<template>
	<view class="children-container">
		<!-- 标题 -->
		<view class="tips">
			<view class="title">选择您的孩子</view>
			<button class="detail" plain="true" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" v-show="!show">点击获取您的孩子信息</button>
		</view>
		
		<!-- 孩子选择界面 -->
		<view class="children-item" v-show="show">
			<view class="com-box">
				<view class="item" v-for="(item,index) in parentdetail.childrenList" :key="index" @click="chooseChildren(item)">
					<view class="item-text">{{item.name}}</view>
					<view class="avatar-box">
						<u-avatar size="120" class="item-avatar" :src="item.avatar" mode="aspectFill"></u-avatar>
					</view>
				</view>
			</view>
		</view>
		<!-- 动画 -->
		<view class="ocean"></view>
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex'
	//引入解密工具
	import WXBizDataCrypt from "@/utils/WXBizDataCrypt.js";
	
	export default {
		data() {
			return {
				show: false
			};
		},
		computed:{
			...mapState('m_parent',['parentdetail','token'])
		},
		onLoad(){
			//判断用户信息
			this.hasParentDetail()
		},
		methods:{
			...mapMutations('m_children',['updateChildrenInfo']),
			...mapMutations('m_parent',['updateParentInfo']),
			
			//选择孩子并跳转首页传入id查询显示孩子信息
			chooseChildren(item){
				console.log(item.tmdid);
				this.updateChildrenInfo(item)
				uni.switchTab({
					url:'/pages/home/home'
				})
			},
			
			//判断用户基本信息是否存在
			hasParentDetail(){
				if(uni.getStorageSync('parentdetail'))
					this.show = true
				else
					this.show = false
			},
			
			//获取用户手机号
			async getPhoneNumber(e) {
				if (e.detail.errMsg !== "getPhoneNumber:ok") {
					//用户决绝授权  
					return uni.$showMsg('拒绝授权获取不到您的孩子信息!')
				} else {
					if (this.token) {
						let proof = await new WXBizDataCrypt('wx5705da8747c77cfe', this.token.session_key)
						let numData = await proof.decryptData(e.detail.encryptedData, e.detail.iv)
						console.log(numData.phoneNumber)
						// const parentDetailData = await uni.$http.post('',numData.phoneNumber)
						// this.updateParentDetail(parentDetailData)
						this.show = true
					}
				}
			},
			
			
		}
	}
</script>

<style lang="scss">
	.children-container{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		
		.tips {
			width: 100%;
			display: flex;
			flex-direction: column;
			z-index: 99;
		
			.title {
				padding-top: 180rpx;
				padding-left: 40rpx;
				line-height: 70rpx;
				margin-bottom: 60rpx;
				font-weight: bold;
				font-size: 60rpx;
				color: #4169E1;
				background-image: linear-gradient(to right, #506AE7, #87CEFA);
				background-clip: text;//裁剪成文字的前景色
				color: transparent;//文字颜色变成透明
				text-shadow: 0 6rpx 12rpx rgba(0, 0, 0, 0.05);
			}
			.detail{
				line-height: 100rpx;
				font-weight: bold;
				font-size: 45rpx;
				border-radius: 200rpx;
				position: relative;
				margin: 180rpx auto;//relative相对定位居中
				border: none;
				color: #FFFFFF;
				background: linear-gradient(to right, #506AE7, #87CEFA);
				box-shadow: 0 6rpx 12rpx rgba(0, 0, 0, 0.2);
			}
		}
		.children-item{
			.com-box{
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
				flex-wrap: wrap;//元素换行

				
				.item{
					margin: 10rpx 20rpx 20rpx 20rpx;
					padding: 20rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					background-color: #FFFFFF;
					border-radius: 20rpx;
					width: 280rpx;
					height: 320rpx;
					z-index: 99;
					
					.item-text{
						margin: -7rpx 0 20rpx 20rpx;
						width: 100%;
						line-height: 40rpx;
						font-weight: bold;
						font-size: 35rpx;
						color: #696969;
						
					}
					.avatar-box{
						.item-avatar{
							width: 220rpx;
							height: 220rpx;
						}
					}
				}
			}
		}
	}
	.ocean {
	    display: flex;
		margin-top: -600rpx;
	    width: 1800rpx;
	    height: 1800rpx;
	    background-color: #4169E1;
	    border-radius: 50%;
	
	    &::before,
	    &::after {
	        content: "";
	        position: absolute;
					margin-top: 870rpx;
	        width: 1600rpx;
	        height: 1600rpx;
	        top: 0;
	        left: 50%;
					border-radius: 43%;
	        background-color: #fafafa;
	        transform: translate(-50%, -70%) rotate(0);
	        animation: rotate 6s linear infinite;
	        z-index: 2;
	    }
	
	    &::after {
					border-radius: 46%;
	        background-color: #fafafa;
					opacity: 0.7;
	        transform: translate(-50%, -70%) rotate(0);
	        animation: rotate 10s linear -5s infinite;
	        z-index: 3;
	    }
			&::after {
					border-radius: 40%;
			    background-color: #fafafa;
					opacity: 0.5;
			    transform: translate(-50%, -70%) rotate(0);
			    animation: rotate 10s linear -5s infinite;
			    z-index: 3;
			}
			
	}
	
	@keyframes rotate {
	    50% {
	        transform: translate(-50%, -73%) rotate(180deg);
	    } 100% {
	        transform: translate(-50%, -70%) rotate(360deg);
	    }
	}
</style>
