<template>
	<view class="app">
		<view class="top-view">
			<image class="bg" src="/static/img/login-bg.png"></image>
			<view class="inner">
				<view class="statusBar" :style="'height:'  + statusBarHeight + 'px'"></view>
				<view class="inner-body fx-h fx-bc fx-ac">
					<view class="prv" @tap="utils.navigateBack()">
						<image src="/static/img/ic_back_white.png" class="icon-back"></image>
					</view>
					<view class="logo">
						<image src="/static/img/cbb_white.png"></image>
					</view>
					<view class="label-text">欢迎登录长城易趣拍</view>
				</view>
				
			</view>
		</view>
		<view class="body">
			<view class="h120"></view>
			<view class="input-view">
				<view class="login-input fx-r">
					<view class="left fx-r fx-bc ">
						<view class="label">+86</view>
						<image class="loginv" src="/static/img/login-v.png"></image>
					</view>
					<input type="number" v-model="form.mobile" placeholder="请输入手机号" />
				</view>
				
				
				<view class="login-input fx-r">
					<view class="left fx-h fx-ac">
						<image class="icon" style="margin-left: 20rpx;" src="/static/img/login-password.png"></image>
					</view>
					<input  type="text" v-model="form.password" password="*"  placeholder="请输入密码" />
				</view>
				
				<view class="btn ihover" @tap="tapSubmit">登  录</view>
				
				<view class="mb-view fx-r" >
					<view class="link" @tap="tapReg">注册新用户</view>
					<view class="fx-g1"></view>
					<view class="link" @tap="tapPassword">忘记密码</view>
				</view>
				
				<view class="agament fx-r fx-bc fx-ac">
					<view @tap="isRead = !isRead" class="fx-r fx-ac fx-bc">
						<image  v-if="!isRead" src="/static/img/radio_buttons.png"></image>
						<image  v-else src="/static/img/radio_buttons_btn.png"></image>
						注册及同意
					</view>
					
					
					<text  @tap="tapOpen" data-url="/pages/operation/user">《用户协议》</text>
					，认真阅读<text  @tap="tapOpen" data-url="/pages/operation/package">《长城易趣拍产品购买协议》</text>
				</view>
				
			</view>
		</view>
		
		
	</view>
</template>
<style lang="scss">
	page{background: #fff;}
	.top-view{
		position: relative;
		width: 100vw;
		height: 62vw;
		.bg{width: 100vw;height: 62vw;}
		.inner{
			position: absolute;
			width: 100%;
			height: 100%;
			top: 0;
			left: 0;
			.inner-body{
				position:relative;
				.prv{
					position: absolute;
					left: 20rpx;
					top: 20rpx;
					.icon-back{
						width: 60rpx;
						height: 60rpx;
					}
				}
				.logo{
					width: 200rpx;
					height: 119rpx;
					margin-bottom: 40rpx;
					margin-top: 60rpx;
					image{width: 100%;height: 100%;}
				}
				.label-text{
					font-size: 42rpx;
					color: #FFFFFF;
				}
			}
			
			
		}
	}
	
	.body{
		position: relative;
		background: #fff;
		border-radius: 80rpx 80rpx 0px 0px;
		top: -120rpx;
		z-index: 9;
		height: 500px;
		.h120{height: 100rpx;}
		
		.input-view{
			padding: 0px 60rpx;
			.login-input{
				border-radius: 70rpx;
				border: 1px solid #E0E0E0;
				padding: 30rpx 46rpx;
				margin-bottom: 50rpx;
				.left{
					.label{
						font-size: 28rpx;
						color: #DB292B;
						font-weight: bold;
					}
					.loginv{width: 15rpx;height: 12rpx;margin-left: 14rpx;}
					.icon{width: 30rpx;height: 33rpx;}
					width: 90rpx;
				}
				input{
					width: calc(100% - 90rpx);
				}
			}
		}
		
		.btn{
			background: #DB292B;
			border-radius: 60rpx;
			text-align: center;
			font-weight: bold;
			font-size: 28rpx;
			padding: 30rpx 0;
			color: #FAFAFA;
		}
		
		.agament{
			margin-top: 40rpx;
			image{width: 36rpx;height: 36rpx;margin-right: 20rpx;}
			color: #999999;
			font-size:24rpx;
			text{color: #DB292B;}
		}
		
	}
	
	.mb-view{font-size: 14px; margin-top: 30px;padding: 0px 5px;}
	.mb-view .link{color: #DB292B;}
	
</style>

<script>
	import maoScroll from '@/components/mao-scroll/mao-scroll.vue';
	import customerWiget from '@/components/ui-public/customer-wiget.vue';
	import { mapMutations } from 'vuex';
	import Request from '@/library/Request';
	export default {
		components: {
			maoScroll,
			customerWiget
		},
		computed: {
			getWebSocket(){
				// #ifdef APP-PLUS
				const webSocket = getApp().globalData.webSocket
				// #endif
				// #ifndef APP-PLUS
				const webSocket = this.webSocket
				// #endif
				return webSocket
			}
		},
		data() {
			return {
				statusBarHeight: 20,
				form:{
					mobile 	 : "",
					password : ""
				},
				isRead : false
			}
		},
		onLoad() {
			this.initView();
		},
		onReachBottom() {
			if(this.page.isFoot || this.page.isLoad) {
				return;
			}
			this.page.page ++;
			this.getData();		
		},
		methods: {
			...mapMutations(['setSys','setUser']),
			initView: function() {
				
				uni.getSystemInfo({
					success: (res) => {
						this.statusBarHeight = res.statusBarHeight;
					}
				});	
			
			},
			
			/**
			 * 注册
			 */
			tapReg:function(){
				uni.navigateTo({ url:"./register" });
			},
			
			tapPassword:function(){
				uni.navigateTo({
					url:'/pages/login/forgotPassword'
				})
			},
			
			/**
			 * 提交数据
			 */
			tapSubmit:function(){
				//手机号码
				if(this.form.mobile == ""){
					uni.showToast({
						title:"请输入手机号码",icon:"none",mask:true
					})
					return;
				}
				//手机验证号码
				//this.form.mobile
				if(!this.utils.isPoneAvailable(this.form.mobile) ){
					uni.showToast({
						title:"请输入正确的手机号码",icon:"none",mask:true
					})
					return;
				}
				
				if(!this.isRead){
					uni.showToast({
						title:"请阅读并同意相关政策",icon:"none",mask:true
					})
					return;
				}
				
				uni.showLoading({ title: '登录中..' });
				Request
				.post("userLogin",this.form)
				.then(res=>{
					uni.hideLoading();
					if(res.code == 200) {
						this.setUser(res.data);
						this.getWebSocket.connect();
						uni.reLaunch({ url:"../index/index"});
					} else {
						uni.showToast({ title:res.msg,icon:"none",mask:true});
					}
				})
				.catch(res=>{
					console.log(res);
					uni.hideLoading();
					uni.showModal({title: '系统提示',content: '加载失败，重新点击尝试！',showCancel: false});
				});
				
			},
			/**
			 * 打开Open
			 * @param {Object} ev
			 */
			tapOpen: function(ev) {
				let url = ev.currentTarget.dataset.url;
				this.utils.navigateTo(url);
			},
			
		}
	}
</script>


