<template>
	<view class="container login">
		<view class="login-main">
			<image class="logo" src="https://static.caimei365.com/app/img/icon/logo@2x.png" mode=""></image>
		</view>
		<view class="login-form">
			<view class="login-input">
				<input type="text" 
					   v-model="params.mobileOrEmail"  
					   maxlength="30" 
					   class="input" 
					   placeholder="请输入邮箱/手机号"
				/>
			</view>
			<view class="login-input">
				<input v-show="isShowEye" type="text" v-model="params.password"  maxlength="18" class="input" placeholder="请输入密码" autocomplete="new-password"/>
				<input v-show="!isShowEye" type="password" v-model="params.password"  :password="true" maxlength="18" class="input" placeholder="请输入密码" autocomplete="new-password"/>
				<view class="iconfont" :class="isShowEye ? iconEyen : iconEyes"  @click="passwordClick"></view>
			</view>
			<view class="login-input link">
				<view class="login-reg" @click.stop="navigatorRegirst('/pages/login/register-select')">免费注册</view>
				<view class="login-pwd" @click.stop="this.$api.navigateTo('/pages/login/password')">忘记密码?</view>
			</view>
		</view>
		<view class="login-btn"  @click="confirmLogin">账号登录</view>
		<view class="login-btn-last" @click.stop="this.$api.navigateTo(`/pages/login/logincode?data=${getOption}`)">邀请码登录></view>
	</view>
</template>

<script>
	import { mapState,mapMutations } from 'vuex'
	import authorize from '@/common/config/authorize.js' 
	import wxLogin from '@/common/config/wxLogin.js'
	export default{
		data() {
			return{
				isShowEye:false,
				iconEyes:'icon-yanjing_yincang_o',
				iconEyen:'icon-yanjing_xianshi_o',
				getOption:'',	//页面传递参数
				params:{
					mobileOrEmail:'',//用户登录账号
					password:'',//用户登录密码	
					unionId:''
				}
			}
		},
		onLoad(option) {
			this.getOption = JSON.stringify(option)
		},
		computed: {
			...mapState(['hasLogin','isWxAuthorize','isLoginType'])
		},
		methods:{
			...mapMutations(['login']),
			async confirmLogin(){
				if( this.params.mobileOrEmail == ''){
					this.$util.msg('请输入账户名',2000)
					return
				}
				if( this.params.password == ''){
					this.$util.msg('请输入密码',2000)
					return
				}
				this.AorganizationLogin()
			},
			AorganizationLogin(){
				this.UserService.AorganizationLogin(this.params)
					.then(response =>{
						if(response.code === 0){
							this.storeUpdataeStatus(response.data)
							this.$api.navigateTo(`/pages/login/bindwechat?data=${JSON.stringify(this.getOption)}&codeType=${response.code}`)
						}else if(response.code === -3){
							this.$util.modal('','您的企业账号审核未通过，请修改资料','前往修改','',false,() =>{
								this.$store.commit('updateStatus',response.data)
								this.$api.navigateTo('/pages/login/apply-supplier')
							})
						}else{
							this.$util.msg(response.msg,2000)
						}
					})
			},
			storeUpdataeStatus(data){
				uni.setStorageSync('token',data.token)
				this.$store.commit('updateStatus',data)
				this.login(data)
			},
			navigatorRegirst(url){
				// 友盟埋点注册入口点击事件
				if(process.env.NODE_ENV != 'development'){
					this.$uma.trackEvent('Um_Event_Regiest', {
						Um_Key_PageName: '立即注册',
						Um_Key_SourcePage: '登录页面',
					})
				}
				this.$api.navigateTo(url)
			},
			passwordClick() { //密码显隐操作
				this.isShowEye = !this.isShowEye
			},
			async InitAuthorize(){ //是否已授权 0:为取消授权 1:为已授权 2:为未操作
				wxLogin.wxLoginQuick()	
			}
		},
		onShow() {
			this.$api.getStorage().then((resolve) =>{
				this.params.unionId = resolve.unionId ?  resolve.unionId : 0
			})
			this.InitAuthorize()
		}
	}
</script>

<style lang="scss">
	.login{
		width: 100%;
		height: auto;
		.model-warp.none{
			display: none;			
		}
		.model-warp.show{
			display: block;
		}
		.login-main{
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			height: 189rpx;
			padding:60rpx 0 40rpx 0;
			margin-bottom: 70rpx;
			.logo{
				width:467rpx;
				height: 189rpx;
				display: block;
			}
		}
		.login-input{
			width: 600rpx;
			height: 88rpx;
			padding: 24rpx 0;
			margin: 0 auto;
			margin-bottom: 30rpx;
			background: #FFFFFF;
			position: relative;
			box-sizing: border-box;
			border-bottom: 1px solid #e1e1e1;
			.input{
				width: 100%;
				height: 100%;
				background: #FFFFFF;
				font-size: $font-size-28;
				line-height: 88rpx;
				color: #333333;
			}
			.iconfont{
				position: absolute;
				right: 0;
				top: 0;
				font-size: 44rpx;
				color: #999999;
				font-weight: bold;
				z-index: 99;
				width: 96rpx;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
			}
			&.link{
				background: #FFFFFF;
				margin-bottom: 40rpx;
				padding: 0 0;
				line-height: 40rpx;
				font-size: $font-size-28;
				border-bottom: none;
				.login-reg{
					float: left;
					color: $color-system;
				}
				.login-pwd{
					float: right;
					color: $text-color;
				}
			}
		}
		.login-btn{
			width: 600rpx;
			height: 88rpx;
			border-radius: 44rpx;
			font-size: $font-size-28;
			line-height: 88rpx;
			color: #FFFFFF;
			margin: 0 auto;
			text-align: center;
			background: $btn-confirm;
		}
		.login-btn-last{
			width: 600rpx;
			height: 86rpx;
			font-size: $font-size-28;
			line-height: 88rpx;
			color: $color-system;
			margin: 0 auto;
			text-align: center;
			margin-top: 100rpx;
		}
		.login-tel{
			width: 702rpx;
			font-size: $font-size-28;
			line-height: 80rpx;
			margin: 0 auto;
			color: $text-color;
			text-align: center;
			margin-top: 150rpx;
		}
		.model-authorization{
			width: 100%;
			height: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 999;
			.authorization{
				width: 518rpx;
				height: 320rpx;
				position: absolute;
				background: rgba(255,255,255,.7);
				left: 0;
				right: 0;
				bottom: 0;
				top: 0;
				margin: auto;
				.to-btn{
					position: absolute;
					top: 0;
					left: 0;
					right: 0;
					bottom: 0;
					margin: auto;
					width: 70%;
					height: 88rpx;
					font-size: $font-size-28;
					line-height: 88rpx;
					color: #FFFFFF;
					text-align: center;
					border-radius: 44rpx;
				}
			}
		}
	}
</style>
