<template>
	<view class="page">
		<uni-nav-bar @clickLeft="goto(1, 1)" left-icon="back"  :border="false" :shadow="false" :fixed="true"
		:title="$t('login.title')" backgroundColor="#fff" :statusBar="true"></uni-nav-bar>
		<view style="width: 92%; margin: 20rpx auto; padding: 30rpx 20rpx;">
			<view>
				<image src="/static/images/logo2.png" style="width: 50rpx; height: 50rpx; float: left;" fit="cover"></image>
				<span style="font-size: 40rpx; font-weight: 700; float: left; color: #3d3d3d; margin-left: 20rpx;">{{$t('login.text1')}}</span>
				<view style="clear: both;"></view>
			</view>
			<view style="font-size: 64rpx; color: #333; font-weight: 700; margin-top: 40rpx;">{{$t('login.text2')}}</view>
			<view style="color: #6C7278; font-weight: 500; font-size: 28rpx; margin-bottom: 40rpx;">{{$t('login.text3')}}</view>
			<uni-forms label-position="top" label-width="180rpx" :model="loginModel" :rules="rules" ref="loginModel">
				<uni-forms-item label="Email" name="username">
					<uni-easyinput type="text" v-model="loginModel.username" :placeholder="$t('login.text4')"></uni-easyinput>
				</uni-forms-item>
				<uni-forms-item :label="$t('forgot.text11')" name="password">
					<uni-easyinput type="password" :passwordIcon="true" v-model="loginModel.password" :placeholder="$t('login.text5')" />
				</uni-forms-item>
			</uni-forms>
			<view style="font-size: 24rpx; color:#4D81E7; font-weight: 500; text-align: right; margin-bottom: 40rpx;" @click="onPageJump('/pages/mine/forgotpassword')">{{$t('login.text6')}}</view>
			<button type="primary" round style="width: 100%;" @click="login()">{{$t('login.title')}}</button>
		</view>
		<view style="bottom: 0rpx; position: absolute; width:100vw; height: 100rpx;">
			<view style="font-size: 32rpx; color: #6C7278; font-weight: 500; text-align: center;">
				{{$t('login.text7')}}
				<span style="color: #4D81E7; margin-left: 20rpx;" @click="onPageJump('/pages/mine/signup')">{{$t('login.text8')}}</span>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				loginModel: {
				    username: '',
				    password: ''
				},
				rules: {
				    username: {rules:[{required: true,errorMessage: this.$t('login.text9')}]},
				    password: {rules:[{required: true,errorMessage: this.$t('login.text10')}]},
				}
			};
		},
		computed: {
			...mapState(['userInfo'])
		},
		//第一次加载
		onLoad(e) {
			
		},
		//页面显示
		onShow() {},
		//方法
		methods: {
			...mapMutations(['setUserInfo']),
			onPageJump(url) {
				uni.navigateTo({
					url: url
				});
			},
			goto(url, type) {
			    if (type == 2) {
			        return uni.switchTab({ url: url })
			    }
			    if (type == 1) {
			        return uni.navigateBack({ delta: url });
			    }
			    uni.navigateTo({
			        url: url
			    })
			},
			login(){
				this.$refs.loginModel.validate().then(res=>{
				    if (!this.$base.mailRegular.test(this.loginModel.username)) {
						uni.showToast({title: this.$t('setPasswork.text13'), icon:'error'});
						return;
					}
				    this.$http.post('/api/common/login', this.loginModel).then(res => {
						if(res.code == 0){
							this.setUserInfo(res.data);
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/mine/index'
								});
							}, 1000);		
						}
					});
				});
			}
		},
		//页面隐藏
		onHide() {},
		//页面卸载
		onUnload() {},
		//页面下来刷新
		onPullDownRefresh() {},
		//页面上拉触底
		onReachBottom() {},
		//用户点击分享
		onShareAppMessage(e) {
			return this.wxShare();
		}
	};
</script>
<style lang="scss" scoped>
	@import '@/style/mixin.scss';
	body{background-color: #fff;}
	.page{min-height: 100vh;position: relative;}
	.rechargeTitle{
		font-weight: 400;font-size: 32rpx;color: #999999;line-height: 46rpx; text-align: center; margin-top: 60rpx;
	}
	.rechargeNet{
		font-weight: 600;font-size: 40rpx;color: #333;line-height: 46rpx; text-align: center; margin-top: 40rpx;
	}
	.txt{
		font-size: 28rpx; color:#999; font-weight: 500;
	}
	.cell_right{
		font-size: 28rpx; color:#333; font-weight: 500;
	}
</style>