<template>
	<view class="children-container">
		<!-- 标题 -->
		<view class="tips">
			<view class="title" v-show="!show">欢迎您的使用</view>
			<view style="font-weight: bold;font-size: 36rpx;color: #b0b0b1;margin-left: 40rpx;margin-top: 20rpx;"
				v-show="!show">醍摩豆家长助您孩子成长</view>
			<view class="title" v-show="show">选择您的孩子</view>

			<view class="detail-image" v-show="!show"></view>
			<button class="detail-button" 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']),
			...mapState('m_children', ['semesterList'])
		},
		onLoad() {
			//判断用户信息
			this.hasParentDetail()
		},
		methods: {
			...mapMutations('m_children', ['updateChildrenInfo', 'updateChildrenSemester']),
			...mapMutations('m_parent', ['updateParentInfo', 'updateParentDetail']),

			//选择孩子并跳转首页传入id查询显示孩子信息
			chooseChildren(item) {
				console.log(item.tmdid);
				this.updateChildrenInfo(item)
				//默认学期
				this.updateChildrenSemester(this.semesterList[0][0])
				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({
							phoneNumber: '17882237075',
							name: '家长姓名',
							childrenList: [{
								avatar: '/static/default-icons/boy.png',
								name: '张三',
								classid: '0301',
								class: '三年级一班',
								tmdid: 'tmdid01',
								schoolname: '研发学校'
							}, {
								avatar: '/static/default-icons/girl.png',
								name: '张梅',
								classid: '0504',
								class: '五年级四班',
								tmdid: 'tmdid03',
								schoolname: '研发学校'
							}, ]
						})
						this.show = true
					}
				}
			},


		}
	}
</script>

<style lang="scss">
	@import '@/subpkg/common/ocean.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: 200rpx;
				padding-left: 40rpx;
				line-height: 70rpx;
				font-weight: bold;
				font-size: 50rpx;
				color: #4169E1;
				// background-clip: text; //裁剪成文字的前景色
				// color: transparent; //文字颜色变成透明
			}

			.detail-image {
				margin-top: 80rpx;
				margin-bottom: 20rpx;
				width: 100%;
				height: 500rpx;
				background: $guide-back-base64;
				background-size: cover; //背景图片自适应
			}

			.detail-button {
				line-height: 80rpx;
				height: 80rpx;
				width: 80%;
				font-weight: bold;
				font-size: 36rpx;
				border-radius: 80rpx;
				position: relative;
				margin: 100rpx auto; //relative相对定位居中
				border: none;
				color: #FFFFFF;
				background: linear-gradient(to right, #506AE7, #87CEFA);

			}
		}

		.children-item {
			.com-box {
				display: flex;
				flex-direction: row;
				justify-content: center;
				align-items: center;
				flex-wrap: wrap; //元素换行
				margin-top: 60rpx;

				.item {
					margin: 10rpx 20rpx 10rpx 20rpx;
					padding: 20rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					box-shadow: $box-shadow-stereo-white;
					background-color: #FFFFFF;
					border-radius: 20rpx;
					width: 280rpx;
					height: 300rpx;
					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;
						}
					}
				}
			}
		}
	}
</style>
