<template>
	<view class="login">
		<view class="content">
			<!-- 返回 -->
			<tm-nav-bar left-icon="arrow-left" title="登陆账号" @clickLeft="back" />
			<!-- 头部logo -->
			<view class="header">
				<image src="../../static/a-ziyuan85.png"></image>
			</view>
			<!-- 主体表单 -->
			<view class="main">
				<wInput
					v-model="phoneData"
					type="text"
					maxlength="11"
					placeholder="用户名/电话"
					:focus="isFocus"
				></wInput>
				<wInput
					v-model="passData"
					type="password"
					maxlength="9999"
					placeholder="密码"
				></wInput>
			</view>
			<wButton 
				class="wbutton"
				text="登 录"
				:rotate="isRotate" 
				@click="startLogin"
			></wButton>
			
			<!-- 底部信息 -->
			<view class="footer">
				<navigator url="forget" open-type="navigate">找回密码</navigator>
				<text>|</text>
				<navigator url="register" open-type="navigate">注册账号</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	let _this;
	import store from "@/store/index.js";
	import wInput from '../../components/watch-login/watch-input.vue' //input
	import wButton from '../../components/watch-login/watch-button.vue' //button
	
	export default {
		data() {
			return {
				phoneData:'', //用户/电话
				passData:'', //密码
				isRotate: false, //是否加载旋转
				isFocus: true // 是否聚焦
			};
		},
		components:{
			wInput,
			wButton,
		},
		mounted() {
			_this= this;
		},
		methods: {
			back() {
				uni.navigateTo({
					url: '/pages/index/index'
				})
			},
		    startLogin(e){
				//登录
				if(this.isRotate){
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if (this.phoneData == "") {
				     uni.showToast({
				        icon: 'none',
						position: 'bottom',
				        title: '账号不能为空'
				    });
				    return;
				}
		        if (this.passData == "") {
		            uni.showToast({
		                icon: 'none',
						position: 'bottom',
		                title: '密码不能为空'
		            });
		            return;
		        }
				
				
				uni.showLoading({
					title: '登录中'
				});
				this.$store.dispatch('api/dologin', { mobile: this.phoneData, password: this. passData }).then(res => {
					if (res.token) {
						this.$store.commit('api/setApiToken',res.token)
						console.log('123')
						uni.reLaunch({
							url: '/pages/index/index'
						})
					}
				})
		    }
		}
	}
</script>

<style lang="scss" scoped>
	@import url("../../components/watch-login/css/icon.css");
	@import url("./css/main.css");
</style>
