<template>
	<view class="flex_cloumn">
		<!-- 标题 -->
		<view class="top">
			<view class="title" style="color: #4169E1;">感谢您的使用</view>
			<view class="subtitle">醍摩豆家长助您孩子成长</view>
		</view>
		<view class="detail_image" :style="{backgroundImage:`url(${image})`}"></view>
		<button class="btn" plain="true" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取您的孩子信息</button>
		<!-- 动画 -->
		<view class="ocean"></view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	//引入解密工具
	import WXBizDataCrypt from "@/utils/WXBizDataCrypt.js";
	export default {
		computed: {
			...mapState('m_parent', ['token', 'parentInfo'])
		},
		data() {
			return {
				image: 'https://image.meiye.art/pic_1631411821366jJzYRG2jdJOxwXZk_jz7o'
			}
		},
		methods: {
			//获取用户手机号
			async getPhoneNumber(e) {
				if (e.detail.errMsg !== "getPhoneNumber:ok") {
					return uni.showToast({
						title: '您已拒绝授权',
						icon: 'error'
					});
				} else {
					try{
						if (this.token) {
							let proof = await new WXBizDataCrypt('wx5705da8747c77cfe', this.token.session_key)
							let numData = await proof.decryptData(e.detail.encryptedData, e.detail.iv)
							this.$store.commit('m_parent/updatePhoneNumber', numData.phoneNumber);
							//初始化App
							await this.$initStart(numData.phoneNumber)
							uni.navigateTo({
								url: '/subpkg/startup/options'
							})
						}else{
							this.updateToken()
							this.updateParentInfo()
							this.updatePhoneNumber()
							this.updateChildrenData()
							this.updateUserData()
							this.updateChildInfo()
							uni.reLaunch({
								url: '/subpkg/startup/login'
							})
							return uni.showToast({
								title: '获取不到您的信息请重新登录',
								icon: 'error'
							});
						}
					}catch(e){
						this.updateToken()
						this.updateParentInfo()
						this.updatePhoneNumber()
						this.updateChildrenData()
						this.updateUserData()
						this.updateChildInfo()
						uni.reLaunch({
							url: '/subpkg/startup/login'
						})
						return uni.showToast({
							title: '身份验证已过期请重新登录',
							icon: 'error'
						});
					}

				}
			},
		},
	}
</script>

<style lang="scss">
	@import 'startup_pages.scss';

	.detail_image {
		height: 600rpx;
		margin: 400rpx 0 0 0;
		background-size: 100% 100%;
	}
</style>
