<template>
	<view class="pages">
		<view class="wrap">
			<view class="title">城市智慧停车场管理<br>PDA登录</view>
			<u-form class="login-form" :model="form" ref="uForm">
				<u-form-item class="u-p-r-40" label="账号：" :border-bottom="false" label-width="100rpx">
					<u-input v-model="form.name" placeholder="请输入您的工号" type="number" maxlength="11" placeholder-style="color:rgba(255,255,255,.5)" />
				</u-form-item>
				<u-form-item class="u-p-r-40" label="密码：" :border-bottom="false" label-width="100rpx">
					<u-input class="password" v-model="form.password" type="password" placeholder="请输入您的密码" placeholder-style="color:rgba(255,255,255,.5)" />
				</u-form-item>				
			</u-form>
			<view class="pass-tool">
				<u-checkbox v-model="form.passCheck" active-color="transparent">记住密码</u-checkbox>
				<!-- <view class="" @click="$refs.uToast.show({title: '请联系管理员修改'})">忘记密码？</view> -->
			</view>
			<view class="login-btn" @click="handleLogin">立即登录</view>
		</view>
		
		<u-toast ref="uToast" />
		<u-bottom ></u-bottom>
	</view>
</template>

<script>
	var device = uni.requireNativePlugin("DeviceInfo")
	export default {
		data() {
			return {
				pic:'https://uviewui.com/common/logo.png',
				userInfo:[],
				form:{
					name:'9345',
					password:'000000',
					passCheck:false,
					deviceNo: ''
				},
				
				
				
			}
		},
		onLoad() {
			uni.getStorage({
				key:'loginData',
				success: (res) => {
					this.form.name = res.data.name;
					this.form.password = res.data.password;
					console.log('passWord',res.data)
				},
				fail: (err) => {
					console.log('passWord err',err)
				}
			})
		
		},
		methods: {
			openPage(path) {
				console.log('path',path);
				this.$u.route({ 
					url: path
				})
			},
			//登录判断
			// login(status){
			// 	if(!status){
			// 		console.log('config',this.config);
			// 		window.location.replace(this.config.loginUrl)
			// 	}
			// },
			handleLogin(){
				this.form.deviceNo = '1122334455';
				// this.form.deviceNo = device?.getDeviceInfo()?.deviceId;
				this.$u.api.login(this.form)
				.then(res=>{
					this.$refs.uToast.show({
						title: res.msg,
						type: 'success',
					});
					this.$u.vuex('vuex_token', res.data.accessToken);
					this.$u.vuex('vuex_user', res.data);
					this.$u.vuex('vuex_hasLogin', true);
					if(this.form.passCheck){
						uni.setStorage({
							key:'loginData',
							data:{name:this.form.name,password:this.form.password}							
						});
					}else{
						uni.removeStorage({
							key:'loginData'
						})
					};
					this.$u.route('pages/index/index', {});
					console.log('login',res)
				}).catch(err=>{
					if(err.errMsg){
						this.$refs.uToast.show({
							title: '请检查网络',
							type: 'error',
						});
						return false;
					};
					err.msg&&this.$refs.uToast.show({
						title: err.msg,
						type: 'error',
					});
					console.log('login ',err)
				});
			}

		}
	}
</script>

<style lang="scss" scoped>

@import  './login.scss'
</style>
