<template>
	<div
		class="login_container"
		:style="{ backgroundImage: 'url(' + $imghost + bjImage + ')' }"
	>
		<div class="login_box">
			<div class="tit-box">
				<div class="tit-con">
					<p class="txt">
						欢迎来到
						<span class="arrow">
							<i class="el-icon-arrow-right"></i>
						</span>
					</p>
					<p class="tit">智慧农业大数据平台</p>
				</div>
			</div>
			<div class="f-box">
				<ul class="loginItems">
					<li>
						<i class="iconfont icon-yonghu1"></i>
						<input
							type="text"
							@keyup="fillPass()"
							id="username"
							v-model="username"
							placeholder="请输入用户名"
						/>
					</li>
					<li>
						<i class="iconfont icon-mima1"></i>
						<input
							type="password"
							id="password"
							@keyup.enter="submit()"
							v-model="pass"
							placeholder="请输入密码"
						/>
					</li>
					<li>
						<div class="pass">
							<input type="checkbox" id="brand" v-model="cState" />
							<label for="brand">
								<span>
									<i class="el-icon-check"></i>
								</span>
								记住密码
							</label>
							<!-- <a>忘记密码？</a> -->
						</div>
					</li>
					<li>
						<button class="logon-btn" @click="submit()">登录</button>
					</li>
				</ul>
			</div>
		</div>
	</div>
</template>

<script>
export default {
	data() {
		return {
			bjImage: '/static/images/login/login_bg.jpg',
			username: '',
			pass: '',
			cState: false
		}
	},
	methods: {
		submit() {
			if (this.username == '' || this.pass == '') {
				this.$message.error('请输入用户名和密码！')
				return
			}
			this.$axios({
				method: 'POST',
				url: '/api/api_gateway?method=user.login.login_user',
				data: this.qs.stringify({
					username: this.username,
					password: this.pass
				})
			}).then((res) => {
				if (res.data.message == '') {
					if (this.cState == true) {
						//是否记住密码
						localStorage.setItem('username', this.username)
						localStorage.setItem('password', this.pass)
					} else {
						localStorage.removeItem(username, password)
					}
					localStorage.setItem('isLogin', true)
					let selHome = sessionStorage.getItem('selHome')
					if (selHome) {
						this.$router.push(selHome) //登录后默认选择首页
					} else {
						this.$router.push('/plantGuard')
					}
					localStorage.setItem('cUsername',res.data.params.username)
				} else {
					this.$message.error(res.data.message)
				}
			})
		},
		fillPass() {
			let username = localStorage.getItem('username')
			if (username == this.username) {
				this.pass = localStorage.getItem('password')
			}
		}
	},

}
</script>

<style lang='less' scoped>
.login_container {
	height: 100%;

	background-repeat: no-repeat;
	background-position: center;
	// background: url(../../static/images/login/1.gif) no-repeat center;
	background-size: 100% 100%;
	.login_box {
		width: 900px;
		height: 450px;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		display: flex;
		.tit-box {
			position: relative;
			flex: 1;
			background: rgba(0, 0, 0, 0.6);
			color: #fff;
			letter-spacing: 5px;
			.tit-con {
				display: block;
				padding: 180px 50px;
				.txt {
					font-size: 24px;
					padding-bottom: 15px;
					border-bottom: 1px solid #fff;
					position: relative;
					.arrow {
						position: absolute;
						top: 4px;
						margin-left: 10px;
						background: #fff;
						width: 25px;
						height: 25px;
						border-radius: 50%;
						i {
							color: #000;
							font-size: 18px;
							position: absolute;
							left: 4px;
							top: 4px;
						}
						i:before {
							font-weight: 800;
						}
					}
				}
				.tit {
					font-size: 32px;
					padding-top: 10px;
				}
			}
		}
		.f-box {
			flex: 1;
			background: #fff;
			.loginItems {
				padding: 80px 50px 0 50px;
				li {
					width: 100%;
					margin-bottom: 45px;
					position: relative;
					i.iconfont {
						position: absolute;
						font-size: 22px;
						left: 0;
						top: 5px;
						color: #b5b5b5;
					}
				}
				input::-webkit-input-placeholder {
					/* WebKit browsers 适配谷歌 */
					color: #b5b5b5;
				}
				input:-moz-placeholder {
					/* Mozilla Firefox 4 to 18 适配火狐 */
					color: #b5b5b5;
				}
				input::-moz-placeholder {
					/* Mozilla Firefox 19+ 适配火狐 */
					color: #b5b5b5;
				}
				input:-ms-input-placeholder {
					/* Internet Explorer 10+  适配ie*/
					color: #b5b5b5;
				}
				input[type='text'],
				input[type='password'] {
					border: none;
					padding: 10px 20px 10px 30px;
					box-sizing: border-box;
					border-bottom: 1px solid #b5b5b5;
					width: 100%;
					font-size: 15px;
					outline: none;
					box-shadow: 0 0 0px 1000px white inset !important;
					-webkit-box-shadow: 0 0 0px 1000px white inset !important;
				}
				input[type='checkbox'] {
					display: none;
				}
				input[type='checkbox'] + label span {
					display: inline-block;
					width: 16px;
					height: 16px;
					border-radius: 3px;
					border: 1px solid #b5b5b5;
					float: left;
					margin-right: 10px;
					i {
						display: none;
					}
				}
				input[type='checkbox']:checked + label span {
					background: #2f3945;
					i {
						display: block;
						font-size: 15px;
						color: #fff;
					}
					i:before {
						font-weight: 800;
					}
				}
				.pass {
					display: flex;
					justify-content: space-between;
					font-size: 14px;
					label {
						color: #b5b5b5;
					}
					a {
						color: red;
					}
				}
				button {
					width: 100%;
					border: none;
					background: #3d4c5a;
					border-radius: 30px;
					color: #fff;
					line-height: 40px;
					height: 40px;
					cursor: pointer;
					outline: none;
				}
				button:hover {
					background: #4b647b;
				}
			}
		}
	}
}
</style>