<template>
	<view class="login-page">
		<view class="title">
			<view>欢迎使用WORKARK</view>
		</view>
		<view class="form-box">
			<view class="form-tab">
				<view :class="loginType == 1 ? 'tab-item select type1' : 'tab-item type1'" @click="loginType=1">
					验证码登录
				</view>
				<view :class="loginType == 2 ? 'tab-item select type2' : 'tab-item type2'" @click="loginType=2">
					账号密码登陆
				</view>
			</view>
			<view class="form-input">
				<view class="input-box">
					<view class="account">
						<input class="input-inner" type="number" v-model="account" :adjust-position="false"
							placeholder="手机号" />
					</view>
					<view class="password" v-if="loginType==2">
						<input class="input-inner" :type="pwdShow? 'text' : 'password'" v-model="password"
							:adjust-position="false" placeholder="密码" />
						<uv-icon :name="pwdShow? 'eye-fill' : 'eye-off'" size="50rpx" color="#cccccc"
							@click="pwdShow=!pwdShow">
						</uv-icon>
					</view>
					<view class="vcode" v-if="loginType==1">
						<input class="input-inner" type="number" v-model="vcode" :adjust-position="false"
							placeholder="验证码" />
						<uv-button type="primary" :text="codeTips" @click="getCode" size="small"
							:disabled="codeDisabled">
						</uv-button>
					</view>
				</view>
				<view class="button">
					<view class="button-item" @click="login">
						登录
					</view>
				</view>
				<uv-code ref="code" :seconds="seconds" @end="codeDisabled = false" @start="codeDisabled = true"
					@change="text => codeTips = text">
				</uv-code>
			</view>
		</view>
		<view class="pact">
			<uv-checkbox-group v-model="pactChecked" shape="circle" placement="column" customStyle="maxWidth:208rpx;"
				labelSize="24rpx">
				<uv-checkbox name="apple" label="我已阅读并同意"></uv-checkbox>
			</uv-checkbox-group>
			<uv-text text="《用户协议》" size="24rpx" type="primary" @click="toPact"></uv-text>
			<uv-text text="和" size="24rpx"></uv-text>
			<uv-text text="《隐私协议》" size="24rpx" type="primary" @click="toPact"></uv-text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account: "",
				password: "",
				vcode: "",
				loginType: 1,
				pwdShow: false,
				pactChecked: false,
				vcodeTime: 0,
				vcodeTimer: null,
				codeTips: '',
				seconds: 60,
				codeDisabled: false
			}
		},
		onLoad() {

		},
		methods: {
			getCode() {
				if (this.$refs.code.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						this.$toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.code.start();
					}, 2000);
				}
			},
			login() {
				uni.showToast({
					title: "登录方式" + this.loginType,
					icon: 'none'
				})
			},
			getVcode() {},
			pactChange() {
				this.pactChecked = !this.pactChecked
			},
			toPact() {
				uni.showToast({
					title: "协议",
					icon: 'none'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login-page {
		min-height: 100vh;
		background: url("https://images.unsplash.com/photo-1519751138087-5bf79df62d5b?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3wyMDUzMDJ8MHwxfHNlYXJjaHwyMHx8YmFja2dyb3VuZHxlbnwxfHx8fDE3MjExOTc4NjJ8MA&ixlib=rb-4.0.3&q=80&w=1080") no-repeat top center;
		background-size: 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.form-box {
		flex: 1;
		margin: 0 30rpx;
		border-radius: 40rpx;
		background-color: #fff;
		overflow: hidden;
	}

	.form-input {
		background-color: #fff;
	}

	.input-box {
		padding: 150rpx 32rpx 0;
		margin-bottom: 80rpx;
	}

	.account,
	.password,
	.vcode {
		height: 96rpx;
		border-radius: 20rpx;
		padding: 0 48rpx;
		display: flex;
		align-items: center;
		background-color: #f7fafc;

		.input-inner {
			flex: 1;
		}
	}

	.account {
		margin-bottom: 48rpx;
	}

	.vcode-text {
		text-wrap: nowrap;
		font-size: 26rpx;
		background-color: #fff;
		padding: 14rpx 30rpx;
		border-radius: 12rpx;
	}

	.button {
		padding: 0 32rpx;

		.button-item {
			line-height: 96rpx;
			border-radius: 20rpx;
			text-align: center;
			font-size: 32rpx;
			background-color: $uv-primary;
			color: #fff;
		}
	}

	.pact {
		display: flex;
		align-items: center;
		justify-content: center;
		padding-top: 20rpx;
		padding-bottom: 120rpx;
		font-size: 24rpx;
		height: 40rpx;

		::v-deep .uv-text {
			width: auto;
			flex: inherit;
		}
	}

	.title {
		padding-top: 180rpx;
		padding-bottom: 40rpx;
		padding-left: 64rpx;
		font-size: 48rpx;
		font-weight: 700;
		color: #383838;
	}

	.form-tab {
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: #ecf1fb;
		height: 100rpx;
		background: linear-gradient(180deg, #e3ebf9 0%, #ffffff 100%);

		.tab-item {
			width: 340rpx;
			line-height: 100rpx;
			text-align: center;
			color: #9e9e9e;
			position: relative;

			&::after {
				content: '';
				width: 50rpx;
				height: 8rpx;
				display: block;
				background-color: $uv-primary;
				border-radius: 4rpx;
				position: absolute;
				left: 50%;
				bottom: 14rpx;
				transform: translateX(-50%);
				opacity: 0;
			}

			&.select {
				background-color: #fff;
				color: $uv-primary;
			}

			&.type1.select {
				border-radius: 0 40rpx 0 0;
			}

			&.type2.select {
				border-radius: 40rpx 0 0;
			}

			&.select::after {
				opacity: 1;
			}
		}
	}
</style>