<template>
	<view>
		<view class="content">
			<view class="title">账号密码登录</view>
			<view class="ip-div">
				<input v-model="form.tel" type="number" placeholder="请输入账号" />
			</view>
			<view class="ip-div">
				<input v-model="form.password" type="password" placeholder="请输入密码" />
			</view>
			<view class="btn-div">
				<button @tap="submit" :disabled="form.tel&&form.password?false:true" type="primary">登录</button>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		login
	} from "../../api/user.js";
	import {
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				form: {
					tel: '',
					password: ''
				}
			};
		},
		methods: {
			...mapMutations(['setToken', 'setUserInfo']),
			submit() {
				if(this.form.tel==""){
					this.$functions.error("请输入账号");
					return false;
				}
				if(this.form.password==""){
					this.$functions.error("请输入密码");
					return false;
				}
				
				login(this.form).then(res=>{
					this.setToken(res.token.token);
					this.setUserInfo(res);
					uni.switchTab({
						url:"../index/index"
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "./index.scss"
</style>
