<template>
	<view class="zai-box">
		<view class="zai-title2">
			<image mode="aspectFit" src="/static/img/logo2.png" class="zai-title"></image>
			<form class="zai-form">
				<view class="title1">登录</view>
				<view class="formg">
					<image class="formimg" src="@/static/img/zhanghao-.png"></image>
					<input class="formgin" placeholder="请输入账号" v-model="account" name="input"></input>
				</view>
				<view class="formg">
					<image class="formimg" src="@/static/img/mima.png"></image>
					<input class="formgin" placeholder="请输入密码" type="password" displayable  v-model="password" name="input"></input>
				</view>
				<view class="formg">
					<image class="formimg" src="@/static/img/yanzhengma.png"></image>
					<input class="formgin" placeholder="请输入验证码" v-model="code" name="input"></input>
					<image  @click="getCaptcha" style="height: 50rpx;width: 160rpx;" :src="captchaImg"  mode="aspectFill"></image>
				</view>
			</form>
			<!-- <view class="zai-label" @click="gotoNewPass">忘记密码？</view> -->
			<button style="margin-left: 69upx;margin-top: 100upx;margin-right: 69upx;"   @click="bindLogin" class="bg-gradual-blue shadow-blur round cu-btn block lg " >立即登录</button>
		</view>
	</view>
</template>

<script>
	import * as $auth from "@/common/auth.js"
	import loginService from "@/api/auth/loginService"
	import {mapActions} from 'vuex'

	export default {
		data() {
			return {
				captchaImg: '',
				account: '',
				password: '',
				code: '',
				uuid: ''
			}
		},
		created() {
			this.getCaptcha()
		},
		methods: {
			...mapActions(['refreshUserInfo']),
			
			gotoNewPass() {
				uni.navigateTo({
					url: '/pages/newPass/newPass'
				})
			},
			
		  // 登录
		  bindLogin() {
				/**
				 * 客户端对账号信息进行一些必要的校验。
				 * 实际开发中，根据业务需要进行处理，这里仅做示例。
				 */
				if (this.account.length < 1) {
					uni.showToast({
						icon: 'none',
						title: '账号不能为空'
					});
					return;
				}
				if (this.password.length < 1) {
					uni.showToast({
						icon: 'none',
						title: '密码不能为空'
					});
					return;
				}
				const inputForm ={
					'username': this.account,
					'password': this.password,
					'code': this.code,
					'uuid': this.uuid
				  }
				loginService.login(inputForm).then(({data}) => {
				  this.$store.commit('SET_TOKEN',data.token);
				  this.refreshUserInfo();
				  setTimeout(function() {
					  uni.reLaunch({
					  	url: '../factoryBuildings/factoryBuildingsList',
					  });
				  },1000)
				  
				}).catch(e => {
				  this.getCaptcha()
				  console.error(e)
				})
			},
		// 获取验证码
		  getCaptcha () {
			  loginService.getCode().then(({data}) => {
					this.captchaImg = 'data:image/gif;base64,' + data.codeImg
					this.uuid = data.uuid
			   })
		  }
		}
	}
</script>

<style>

	.zai-box{
		  background-size: cover;
		  background-position: center;
		  background-repeat: no-repeat;
		  height: 100vh; /* 设置高度，确保背景图片显示完整 */
		  display: flex;
		  justify-content: center;
		  background-image: url('~@/static/img/login1.jpg');
		  background-size: cover; /* 调整图片大小以覆盖整个屏幕 */
		  background-position: center; /* 图片居中 */
		  background-repeat: no-repeat; /* 防止图片重复 */
	}
	.zai-title2{
		display: flex;
		flex-direction: column;
		align-items: center; /* 水平居中 */
	}
	.zai-title{
		
		margin-top: 260upx;
		color: #fff;
		width: 100%; /* 可选：确保图片适应容器宽度 */
		max-width: 610rpx;
		height: 100rpx;
	}
	.title1{
		font-size: 32upx;
		font-weight: 600;
		color: #000;
	}
	
	.zai-form{
		margin-top: 120upx;
		border-radius: 20upx;
		height: 400upx;
		background: #fff;
		padding: 45upx;
		margin-left: 80upx;
		margin-right: 80upx;
	}
	
	.formg{
		display: flex;
		padding-bottom: 43upx;
		padding-top: 43upx;
		border-bottom: 1px solid  #dcdcdc;
	}
	
	.formimg{
		width: 42upx;
		height: 42upx;
	}
	.formgin{
		margin-left: 32upx;
		width: 250upx;
	}
	.zai-input{
		
		background: #e2f5fc;
		margin-top: 30upx;
		border-radius: 100upx;
		padding: 20upx 40upx;
		font-size: 36upx;
	}
	.input-placeholder, .zai-input{
		color: #94afce;
	}
	.zai-label{
		padding: 60upx 0;
		text-align: center;
		font-size: 30upx;
		color: #a7b6d0;
	}
	.zai-btn{
		background: #ff65a3;
		color: #fff;
		border: 0;
		border-radius: 100upx;
		font-size: 36upx;
	}
	.zai-btn:after{
		border: 0;
	}
	/*按钮点击效果*/
	.zai-btn.button-hover{
		transform: translate(1upx, 1upx);
	}
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
</style>
