<template>
	<view class="qingshaonian">
		<view class="bd">
			<image src="@/static/qingshaonian-san.png"></image>
			<view class="title" v-if="userInfo.teenageMode == 1">青少年模式已开启</view>
			<view class="title" v-else>青少年模式未开启</view>
			<view class="desc" v-if="userInfo.teenageMode == 1">关闭后，所有行为将不受限制</view>
			<view class="desc" v-else>开启时，以下行为会收到限制：</view>
			<view class="item" v-if="userInfo.teenageMode == 0">
				<image src="@/static/qingshaonian-yuan.png"></image>无法进行充值
			</view>
			<view class="item" v-if="userInfo.teenageMode == 0">
				<image src="@/static/qingshaonian-yuan.png"></image>部分功能无法使用
			</view>
		</view>
		<view class="fd">
			<view class="btn" @click="openPage()" v-if="userInfo.teenageMode == 0">开启青少年模式</view>
			<view class="btn" @click="isPopup = true" v-else>关闭</view>
		</view>
		<u-popup v-model="isPopup" mode="center" border-radius="20" :mask-close-able="false">
			<view class="qingshaonians">
				<view class="titles">输入密码<image @click="isPopup = false" src="@/static/cha.png"></image></view>
				<view class="contents">
					<view class="p">解除青少年模式密码</view>
					<view class="box">
						<u-icon name="lock-fill"></u-icon>
						<input v-model="teenagePsw" type="password" placeholder="输入密码" />
					</view>
				</view>
				<view class="fds">
					<view class="btns" @click="toReg">确定关闭</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isPopup: false,
				userInfo: {},
				teenagePsw: ""
			}
		},
		onShow() {
			this.userInfo = uni.getStorageSync("userInfo")
		},
		methods: {
			async toReg() {
				if(!this.teenagePsw){
					uni.showToast({
						title: "密码不能为空！",
						position: "bottom",
						icon: "none",
					})
					return ;
				}
				this.isPopup = false
				const { code, data , msg } = await this.$api.closeTeenageMode({teenagePsw: this.teenagePsw,userId: uni.getStorageSync("userInfo").id});
				if(code == 200){
					uni.showToast({
						title: "提交成功",
					})
					setTimeout(()=>{
						uni.navigateBack({
							delta: 1
						})
					},2000)
				}else{
					uni.showToast({
						title: mgs,
						position: "bottom",
						icon: "none",
					})
				}
			},
			openPage() {
				uni.navigateTo({
					url: "/pages/users/qingshaonian/detail"
				})
			},
		}
	}
</script>

<style scoped lang="scss">
.qingshaonian{
	background-color: #fff;
	min-height: 100vh;
	padding: 0 25rpx;
	overflow: hidden;
	.qingshaonians{
		overflow: hidden;
		width: 670rpx;
		height: 520rpx;
		background: #FFFFFF;
		box-sizing: border-box;
		.titles{
			text-align: center;
			font-weight: 500;
			font-size: 36rpx;
			color: #222222;
			padding: 40rpx 0;
			border-bottom: 1px solid #EAEAEA;
			image{
				width: 45rpx;
				height: 45rpx;
				float: right;
				margin-right: 20rpx;
			}
		}
		.contents{
			padding: 30rpx;
			.p{
				font-weight: 500;
				font-size: 30rpx;
				color: #222222;
			}
			.box{
				font-weight: 500;
				display: flex;
				padding: 30rpx 0;
				align-items: center;
				border-bottom: 1px solid #EAEAEA;
				margin-top: 20rpx;
				input{
					flex: 1;
					margin-left: 30rpx;
					font-size: 30rpx;
					color: #222222;
				}
			}
		}
		.btns{
			width: 400rpx;
			line-height: 80rpx;
			background: linear-gradient(0deg, #000000, #3D3B38);
			box-shadow: 0px 4rpx 18rpx 0px rgba(42,41,39,0.34);
			border-radius: 80rpx;
			text-align: center;
			font-weight: 500;
			font-size: 26rpx;
			color: #FFFFFF;
			margin: 0 auto;
			margin-top: 50rpx;
		}
	}
	.fd{
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		padding: 25rpx;
		overflow: hidden;
		z-index: 22;
		box-sizing: border-box;
		.btn{
			width: 100%;
			line-height: 98rpx;
			background: linear-gradient(0deg, #000000, #3D3B38);
			box-shadow: 0px 4rpx 18rpx 0px rgba(42,41,39,0.34);
			border-radius: 98rpx;
			font-weight: 400;
			font-size: 30rpx;
			color: #FFFFFF;
			text-align: center;
		}
	}
	.bd{
		text-align: center;
		margin-top: 130rpx;
		image{
			width: 170rpx;
			height: 170rpx;
		}
		.title{
			font-weight: 500;
			font-size: 36rpx;
			color: #222222;
			margin-top: 43rpx;
		}
		.desc{
			margin-top: 100rpx;
			font-weight: 500;
			font-size: 30rpx;
			color: #222222;
			margin-bottom: 20rpx;
		}
		.item{
			display: flex;
			align-items: center;
			width: 300rpx;
			font-weight: 500;
			font-size: 30rpx;
			color: #666666;
			margin: 0 auto;
			margin-top: 20rpx;
			image{
				width: 27rpx;
				height: 27rpx;
				margin-right: 10rpx;
			}
		}
	}
}
</style>
