<template>
	<view class="content">
		<img class="loginBack" src="https://douhuo-storage.oss-cn-beijing.aliyuncs.com/images/2023/06/06/5682d339246af0f44b4984c849288aa5.png">
		<img class="loginBottom" src="https://douhuo-storage.oss-cn-beijing.aliyuncs.com/images/2023/06/06/caa46039d88517ee8ba22b6c32dd47a1.png">
		<view class="title">
			<view class="title-name">
				用户登录
			</view>
			<view class="title-tips">
				密码登录仅适用于已注册用户
			</view>
		</view>
		<view class="info">
			<view class="info-cont">
				<!-- 输入手机号相关 -->
				<view class="inputs">
					<input type="number" placeholder="请输入手机号" maxlength="11" v-model="phone" />
				</view>
				<!-- 输入密码 -->
				<view class="inputs">
					<input type="text" :password="passwordState" placeholder="请输入密码" v-model="password" />
					<image class="inputs-see" @click="seeClick" :src="seeState ? '../../static/icon/see_active.png' : '../../static/icon/see.png'" mode="aspectFill"></image>
				</view>
				<button class="btn" type="default" @click="LoginSms" :disabled="phone == '' || password == ''">立即登录</button>
				<view class="forget-label forget-after" style="width: 100%; text-align: center; padding-top: 15rpx; font-size: 28rpx; color: #7f8391;" @click="$Router.push({name: 'Forget'})">忘记密码?</view>
				<view class="forget">
					<view class="forget-label" @click="$Router.push({name: 'Register'})">我要注册</view>
					<view class="forget-label forget-after" @click="$Router.push({name: 'Login'})">验证码登录</view>
					
				</view>
				
			</view>
			<!-- 用户登录注册协议 -->
			<view class="agreement">
			    <checkbox-group @change="radioChange">
			        <checkbox color="#da2b56" :checked="checked" style="transform: scale(.55)" class="radioGroup" />
			    </checkbox-group>
				<view class="agreement-text">
				    我已阅读并同意抖火法律<view @click="$Router.push({name: 'Agreement', params: {page : 3}})">《隐私协议》</view>和<view @click="$Router.push({name: 'Agreement', params: {page : 4}})">《服务协议》</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { Login } from '@/apis/interfaces/auth'
	export default {
		data() {
			return {
				phone	: '',    // 手机号码
				password: '',    // 登录密码
				checked : false, // 勾选协议
				seeState    : false,  //小眼睛
				passwordState: true,
			}
		},
		
		methods: {
			// 用户登录
			LoginSms() {
				if(this.checked) {
					Login({
						username : this.phone,
						password : this.password
					}).then(res => {
						// 存储用户token
						this.$store.commit('setToken', res.token_type + ' ' + res.access_token)
						
						// 回到首页
						this.$Router.replaceAll({name: 'Index'})
						// this.$Router.back()
					}).catch(err => {
						uni.showToast({
							title: err.message,
							icon: "none"
						})
					})
				} else {
				    uni.showToast({
				    	title: '请勾选用户隐私和服务协议',
				    	icon: "none"
				    })
				}
			},
			
			// 勾选协议
			radioChange() {
			    this.checked = !this.checked
			},
			
			// 查看密码
			seeClick() {
				this.seeState      = !this.seeState
				this.passwordState = !this.passwordState
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.loginBack {
		width: 35%;
		position: fixed;
		top: 0;
		right: 0;
	}
	.loginBottom {
		width: 60%;
		position: fixed;
		bottom: 0;
		left: 0;
	}
	
	.agreement {
		padding: $padding 0 $padding - 20 $padding - 10;
		box-sizing: border-box;
		display: flex;
		font-size: $title-size-sm;
		width: 100%;
		line-height: 60rpx;
		color: #979797;
		.radioGroup {
			font-size: $title-size-sm;
		}
		.agreement-text {
			display: flex;
			width: 100%;
			view {
				color: $mian-color;
				padding: 0 5rpx;
			}
		}
	}
	
	.title {
		padding: $padding*4 $padding * 3 $padding*2;
		box-sizing: border-box;
		.title-name {
			font-size: $title-size + 10;
			margin-bottom: $margin - 10;
		}
		.title-tips {
			color: #8e8e8e;
			font-size: $title-size-m;
		}
	}
	
	.info {
		padding: $padding * 3 0;
		box-sizing: border-box;
		position: absolute;
		z-index: 6;
		width: 100%;
		.info-cont {
			padding: 0 $padding * 3;
			box-sizing: border-box;
		}
		.inputs {
			background-color: #f7f8fa;
			height: 100rpx;
			line-height: 100rpx;
			margin-bottom: $margin + 20;
			box-sizing: border-box;
			color: #868686;
			font-size: $title-size-m;
			padding: 0 $padding + 10;
			border-radius: $radius-m;
			box-sizing: border-box;
			position: relative;
			.inputs-see {
				position: absolute;
				right: $padding;
				top: $padding;
				width: 38rpx;
				height: 38rpx;
			}
			input {
				font-weight: normal;
				height: 100%;
			}
		}
		.btn {
			background-image: linear-gradient(to right, #da2b56, #FBAF3B);
			color: #ffffff;
			border-radius: $radius-m;
			font-size: $title-size;
			height: 100rpx;
			line-height: 100rpx;
			padding: 0;
			margin: $margin * 3 0 0;
			&[disabled] {
				background-image: linear-gradient(to right, #ff8da9, #ffd0a2);
			}
		}
		.forget {
			display: flex;
			line-height: 120rpx;
			font-size: $title-size-m;
			.forget-label {
				flex: 2;
				text-align: center;
				color: #000000;
			}
			.forget-after {
				position: relative;
				&::after {
					position: absolute;
					content: '';
					left: 0;
					bottom: calc(50% - 15rpx);
					width: 2rpx;
					height: 30rpx;
					background-color: #f6f6f6;
				}
			}
		}
	}
</style>
