<template>
	<view class="login">
		<view class="login-box">
			<view class="login-box-title">
				<text>智慧停车<br />运营数据系统</text>
			</view>
			<view class="login-box-form">
				<view class="login-box-form-title">
					<text>账号密码登录</text>
				</view>
				<view class="login-box-form-box">
					<u--form :model="form" :rules="rules" ref="uForm">
						<u-form-item label="" prop="phoneNumber">
							<u-input v-model="form.phoneNumber" placeholder="请输入手机号" :maxlength="11" type="number"/>
						</u-form-item>
						<u-form-item label="" prop="password">
							<u-input v-model="form.password" placeholder="请输入密码" :password="true"/>
						</u-form-item>
					</u--form>
				</view>
				<view class="login-box-form-btn">
					<u-button type="primary" text="登录" :loading="loading" @click="submitLogin"></u-button>
				</view>
				<!-- <view class="login-box-form-forget">
					<text>忘记密码？</text>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					phoneNumber: '',
					password: ''
				},
				loading: false,
				rules: {
					phoneNumber: [
						{
							required: true,
							message: '请输入手机号',
							trigger: ['change', 'blur']
						},
						{
							validator: (rule, value, callback) => {
								return uni.$u.test.mobile(value);
							},
							message: '手机号不正确',
							trigger: ['change', 'blur'],
						}
					],
					password: {
						required: true,
						message: '请输入密码',
						trigger: ['change', 'blur']
					}
				}
			}
		},
		methods: {
			/**
			 * 登录提交
			 */
			submitLogin() {
				this.$refs.uForm.validate().then(res => {
					this.loading = true
					// uni.$u.api.loginApi(this.form).then(res => {
					// 	console.log(res)
					// 	uni.$u.route({
					// 		url: 'pages/index/index'
					// 	})
					// }).catch(err => {
					// 	this.loading = false
					// })
					uni.$u.route({
						url: 'pages/index/index'
					})
				}).catch(errors => {
					uni.$u.toast(errors[0].message || '必填项不能为空!')
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import './login.scss';
</style>
