<template>
	<view class="loginBox">
		<view class="title">设置登录密码</view>
		<view class="desc">设置密码后，您可以使用密码登录</view>
		
		<view class="twoBox">
			<view class="row">
				<up-input v-model="password" placeholder="请输入6-16位密码，支持数字及符号" clearable :type="Type1 ? 'password' : 'text'">
					<template #suffix>
						<view @click="Type1 = !Type1">
							<up-icon v-if="Type1" name="eye-off" color="#666" size="20"></up-icon>
							<up-icon v-else name="eye-fill" color="#666" size="20"></up-icon>
						</view>
					</template>
				</up-input>
			</view>
			<view class="row">
				<up-input v-model="password_again" placeholder="请再一次输入密码" clearable :type="Type2 ? 'password' : 'text'">
					<template #suffix>
						<view @click="Type2 = !Type2">
							<up-icon v-if="Type2" name="eye-off" color="#666" size="20"></up-icon>
							<up-icon v-else name="eye-fill" color="#666" size="20"></up-icon>
						</view>
					</template>
				</up-input>
			</view>
			<view class="btn" @click="toCommit">确认</view>
		</view>
	</view>
	
</template>

<script>
	import { ref, reactive, toRefs } from 'vue'
	import { post } from '@/Api/request.js'
	import { showToast } from '@/components/common.js'
	
	export default {
		setup() {
			const data = reactive({
				Color: uni.getStorageSync('theme_color'),
				password: '',
				password_again: '',
				Type1: true,
				Type2: true
			})
			
			function toCommit() {
				if(!data.password) {
					return showToast('请输入密码')
				} else if(!data.password_again) {
					return showToast('请输入确认密码')
				} else if(data.password != data.password_again) {
					return showToast('两次密码输入不一致')
				}
				uni.showLoading({
					title: '加载中...',
					mask: true
				})
				let params = {
					password: data.password,
					confirm_password: data.password_again
				}
				post('/api/app/login/mobile/setPassword', params).then(async(res) => {
					showToast('设置成功', 'success')
					setTimeout(() => {
						uni.navigateBack({delta:1})
					}, 1000)
				})
			}
			
			return {
				...toRefs(data),
				toCommit
			}
		},
		async onLoad(options) {
			
		}
	}
</script>

<style lang="scss" scoped>
	.loginBox{
		padding: 80rpx 30px 0;
		width: 100%;
		height: 100vh;
		overflow: hidden;
		box-sizing: border-box;
		background-color: #fff;
		.title{
			font-size: 50rpx;
			color: #333;
			font-weight: 600;
		}
		.desc{
			font-size: 28rpx;
			color: #888;
			margin: 20rpx 0 100rpx;
		}
		.twoBox{
			.row{
				margin-bottom: 15px;
				
			}
			.btn{
				width: 100%;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background-color: v-bind('Color');
				color: #fff;
				border-radius: 80rpx;
				margin: 80rpx auto 0;
				
			}
		}
	}
</style>
