<template>
	<view class="content">
		<view class="logo">
			<image :src="imgSrc" alt="logo" srcset="" class="iconBox" mode="widthFix"></image>
			<view>欢迎使用{{areaName}}</view>
		</view>
		<view class="content-login">
			<!-- <view class="login_title">
				{{liginName}}
			</view> -->
			<view class="login-text">
				<text class="text">{{form.name}}</text>
			</view>
			<view class="login-text">
				<text class="text">{{form.mobile}}</text>
			</view>
			<view class="login-code">
				<!-- <view class="text" style="display: flex;justify-content: space-between;"> -->
					<input style="font-size: 28rpx;" name="form.code" placeholder="输入验证码" v-model="form.code" type="number" maxlength="6"/>
					<text @click="sendMessage()" style="width: 180rpx;text-align: right;font-size: 28rpx;" :class="{'grey':disabledSendBtn}">{{sendCodeHtml}}</text>
				<!-- </view> -->
					
			</view>
			<view class="agree">
				<label class="radio" style="padding-right: 10rpx;">
					<radio :checked="agreeFlag" @click="agreeFlag=!agreeFlag"/></label>
			<text>已阅读并同意</text>
			<text class="file" @click="getFile(1)">服务协议</text>
			<text>和</text>
			<text class="file" @click="getFile(2)">隐私政策</text>
			</view>
			<view class="footer" @click="nextstep()">
				<text>登录 / 注册</text>
			</view>
		</view>

	</view>
</template>

<script>
	import api from '../../api/api';
	import common from '../../common/common';
	import {companyInfo} from "@/environments/environment";
	export default {
		data() {
			return {
				companyType:'',
				areaName: companyInfo.companyName,
				imgSrc:'../../static/logo2.png',
				//imgSrc: '../../static/cffp_logo.png',
				liginName: '登录',
				disabledSendBtn:false,
				agreeFlag:false,
				remainTimes:60,
				sendCodeHtml:'获取验证码',
				userId: '',
				form:{
					name: '',
					mobile: '',
					code: null
				}
			}
		},
		onLoad(options) {
			this.form.name = options.name?options.name:''
			this.form.mobile = options.mobile? options.mobile: ''
			this.form.id = options.shareId?options.shareId:''
			this.form.areaName = options.areaName
			this.form.areaId = options.areaId
			this.form.invitationCode = options.invitationCode
			this.form.partnerLevel = options.partnerLevel
			this.companyType = options.companyType;
			if(this.companyType == '1'){
				this.imgSrc = '../../static/cffp_logo.png';
				this.areaName = '赢盾财务顾问';
			}
			// this.form =JSON.parse( options.form)
		},
		methods:{
			sendMessage(){
				const params = {
					mobileNo:this.form.mobile,
					type:"1",
					source: "cffp"
				}
				if(common.mobileNoValid(this.form.mobile)){
					if(!this.disabledSendBtn){
						api.verificationCode(params).then((res)=>{
							if(res['success']){
								this.delayTime()
							}else{
								common.errorDialog(2,res['message'])
							}
						})
					}
				}else{
					common.errorDialog(2,'手机号校验错误')
				}
			},
			getFile(type){
				uni.navigateTo({
					url:`/components/clause/clause?type=${type}`
				})
			},
			delayTime() {
				this.disabledSendBtn = true;
				this.timer = setInterval(() => {
				  this.remainTimes--;
				  this.sendCodeHtml = `${this.remainTimes}(S)`;
				  if (this.remainTimes <= 0) {
				    this.sendCodeHtml = '获取验证码';
				    this.remainTimes = 60;
				    this.disabledSendBtn = false;
				    clearInterval(this.timer);
				  }
				}, 1000);
			  },
			nextstep(){
				if(this.form.code =='' ||this.form.code == null ){
					uni.showToast({
						title: '请输入验证码',
						duration: 2000,
						icon: 'none'
					});
					return false
				}
				if(this.agreeFlag == false) {
					uni.showToast({
						title: '请阅读并勾选'+`${companyInfo.companyFullName}`+'服务协议和隐私条款',
						duration: 2000,
						icon: 'none'
					});
					return false
				}
				const params = {
					loginType:'3',
					...this.form
				}
				api.loginVerification(params).then((res)=>{
					if(res['success']){
						this.userId = String(res['data']['userId']);
						uni.setStorageSync('isLogin','1');
						uni.setStorageSync('cffp_userId', this.userId);
						uni.setStorageSync('isH5', 1);
						uni.setStorageSync('uni-token', res.data['token']);
						uni.setStorageSync('loginType', 'codelogin');
						uni.navigateTo({
							url:'/pages/application-process/basic-info?userId=' + this.userId  + '&shareId=' + this.form.id
						})
					}else{
						uni.showToast({
							title: res['message'],
							duration: 2000,
							icon: 'none'
						})
					}
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		height: 100vh;
		background: #20279B;
		border-radius: 0px 0px 0px 0px;

		.logo {
			text-align: center;
			color: #fff;
			padding: 60rpx 0;

			view {
				margin-top: 40rpx;
				font-size: 40rpx;
			}

			.iconBox {
				border-radius: 15rpx;
				width: 20% !important;
			}
		}

		.content-login {
			background-color: #fff;
			margin: 0 20rpx;
			border-radius: 30rpx;
			padding: 40rpx 60rpx;
			overflow: hidden;
			margin-bottom: 30rpx;
			// min-height: 65%;
			.login_title{
				text-align: center;
				font-size: 40rpx;
				margin-bottom: 60rpx;
			}
			.login-text{
				width: 100%;
				border-bottom: 1px solid  #CECECE;
				padding: 20rpx 0;
				font-size: 28rpx;
				.text{
					padding: 20rpx;
				}
			}
			.login-code{
				display: flex;
				justify-content: space-between;
				border-bottom: 1px solid  #CECECE;
				padding: 20rpx;
				.grey{
					min-width: 100rpx;
					font-size: 22rpx;
					color: #CECECE;
				}
			}
			
		}
		.agree{
			font-size: 28rpx;
			color:#666;
			text-align: center;
			margin-top: 40rpx;
			a{
				color: #20279B;
				text-decoration: none;
			}
		}
		.file{
			color: #20279B;
			text-decoration: none;
		}
		.footer{
			background: #20279B;
			color: #fff;
			width: 550rpx;
			height: 100rpx;
			background: #20279B;
			border-radius: 80rpx;
			margin: 60rpx auto;
			text-align: center;
			opacity: 1;
			text{
				font-size: 36rpx;
				line-height: 100rpx;
			}
		}
	}
</style>
