<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>
	//#ifdef APP-PLUS
	var device = uni.requireNativePlugin("DeviceInfo")
	//#endif
	export default {
		data() {
			return {
				pic:'https://uviewui.com/common/logo.png',
				userInfo:[],
				form:{
					name:'',
					password:'',
					passCheck:false,
					deviceNo: ''
				},
				
				
				
			}
		},
		onLoad() {
			uni.getStorage({
				key:'loginData',
				success: (res) => {
					this.form.name = res.data.name;
					this.form.password = res.data.password;
					this.form.passCheck = res.data.passCheck?res.data.passCheck:false
					// console.log('passWord',res.data)
				},
				fail: (err) => {
					// console.log('passWord err',err)
				}
			})
		
		},
		onBackPress(options) {
			 if (options.from === 'backbutton') {  
				// uni.showModal({  
				//   title: '温馨提示',  
				//   content: '已经到头了',  
				//   showCancel: false,
				//   success: (res) => { }  
				// })  
				// 禁止默认返回  
				return true  
			  } 
		},
		methods: {

			handleLogin(){
				
				//#ifdef APP-PLUS
				this.form.deviceNo = device?.getDeviceInfo()?.deviceId;
				//#endif
				//#ifdef H5
				 this.form.deviceNo = '123456789';
				//#endif
				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);
					uni.setStorageSync('payee_roadinfo', JSON.stringify(res.data?.roadList?.[0] || []));
					if(this.form.passCheck){
						uni.setStorage({
							key:'loginData',
							data:{name:this.form.name,password:this.form.password,passCheck:this.form.passCheck }							
						});
					}else{
						uni.setStorage({
							key:'loginData',
							data:{name:this.form.name}							
						});
					};
					uni.removeStorageSync('pushreg_switch');//删除推送开关，登录成功后允许处理推送
					// this.$u.route('pages/index/index', {});
					uni.redirectTo({
						url:'../index/index'
					});
				}).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>
