<template>
	<view class="register">
	
		<view class="content">
			<!-- 头部logo -->
			<view class="header" v-if="system_logo">
				<image :src="system_logo" @click="Dever.viewPic([system_logo], system_logo)"></image>
			</view>
			<!-- 主体 -->
			<view class="main">
				<wInput
					v-model="phoneData"
					type="text"
					maxlength="11"
					placeholder="手机号"
				></wInput>
				<wInput
					v-model="passData"
					type="password"
					maxlength="11"
					placeholder="登录密码"
					isShowPass
					style="display: none;"
				></wInput>
				<wInput
					v-model="verCode"
					type="number"
					maxlength="6"
					placeholder="验证码"
					
					isShowCode
					ref="runCode"
					@setCode="getVerCode()"
				></wInput>
					
			</view>
				
			<wButton 
				class="wbutton"
				text="登 录"
				:rotate="isRotate" 
				@click.native="startLogin()"
			></wButton>
			
			<view class="other_agree">
				<text
					@tap="isShowAgree" 
					class="cuIcon"
					:class="showAgree?'cuIcon-radiobox':'cuIcon-round'"
				> 同意</text>
				<!-- 协议地址 -->
				<navigator url="" open-type="navigate">《{{Dever.config.system_name}}入境协议》</navigator>
			</view>
			
			<!-- 其他登录 -->
			<view class="other_login cuIcon">
				<view class="login_icon">
					<view class="cuIcon-weixin" @tap="login_weixin"></view>
				</view>
			</view>
			
			<!-- 底部信息 -->
			<view class="footer" style="display: none;">
				<navigator url="forget" open-type="navigate">找回密码</navigator>
				<text>|</text>
				<navigator url="register" open-type="navigate">注册账号</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	var self;
	import wInput from '@/lib/watch-login/watch-input.vue' //input
	import wButton from '@/lib/watch-login/watch-button.vue' //button
	
	export default {
		data() {
			return {
				system_logo : '',
				phoneData:'', // 用户/电话
				passData:'', //密码
				verCode:"", //验证码
				showAgree:true, //协议是否选择
				isRotate: false, //是否加载旋转
			}
		},
		components:{
			wInput,
			wButton,
		},
		mounted() {
			self = this;
			this.system_logo = this.Dever.config.system_logo;
		},
		methods: {
			isShowAgree(){
				//是否选择协议
				self.showAgree = !self.showAgree;
			},
			getVerCode(){
				//获取验证码
				if (self.phoneData.length != 11) {
					self.Dever.alert('手机号不正确');
				    return false;
				}
				self.$refs.runCode.$emit('runCode');
				self.Dever.post('package/passport/?l=reg.getMCode', {noloading:1, mobile: self.phoneData}, function(t) {
					self.Dever.alert(t);
				});
			},
		    startLogin() {
				if(self.isRotate){
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if (self.showAgree == false) {
					self.Dever.alert('请先同意《协议》');
				    return false;
				}
				if (self.phoneData.length !=11) {
					self.Dever.alert('手机号不正确');
				    return false;
				}
				/*
		        if (self.passData.length < 6) {
					self.Dever.alert('密码不正确');
		            return false;
		        }
				*/
				if (self.verCode.length != 6) {
					self.Dever.alert('验证码不正确');
				    return false;
				}
				
				self.isRotate = true;
				self.Dever.post('package/passport/?l=app.login', {noloading:1, mobile: self.phoneData, mcode: self.verCode, source_type: self.Dever.source, system:1}, function(t) {
					self.isRotate = false;
					self.Dever.setToken(t.signature);
					self.Dever.jump();
				}, function(t) {
					self.Dever.alert(t.msg);
					self.isRotate = false;
				});
		    }
		}
	}
</script>

<style>
	@import url("@/lib/watch-login/css/icon.css");
	@import url("@/lib/watch-login/css/main.css");
	.other_agree {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		margin-top: 50rpx;
		text-align: center;
	}
	.other_login {
		margin-top: 130rpx;
	}
</style>