<template>
	<div class="login">
		<div style="position: absolute;top: 50%;left: 50%;transform: translateX(-50%) translateY(-60%);">
			<div class="login-box"> 
				<img src="../assets/images/zc.png" style="width: 360px;" alt="" />
				<div style="background-color: #fff;border-radius: 0 8px 8px 0;height:360px ;display: flex;flex-direction: column;justify-content: space-between;height: 418px;">
					<div style="display: flex;justify-content: flex-end;align-items: center;">
						<div class="dhk" style="font-size: 12px;">
							{{type == 'zh'?'微信扫码登录':'账号密码登录'}}
							<i class="el-icon-caret-right" style="position: absolute;right: -12px;font-size: 20px;color: #f0f6ff;top: 3px;z-index: 99;"></i>
						</div>
						<div class="saoma" style="padding: 6px;background-color: #f0f6ff;position: relative;cursor: pointer;" >
							<img src="../assets/images/saoma.png" style="width: 34px;" alt="" v-if="type == 'zh'"  />
							<img src="../assets/images/phone.png" style="width: 34px;" alt="" v-if="type == 'wx'"  />
							<div style="width: 0;height: 0;border-bottom: 50px solid #fff;border-right: 47px solid transparent;position: absolute;bottom: 0;left: 0;" @click="type=='wx'?type='zh':type='wx'">
								
							</div>
						</div>
					</div>
					<el-form ref="form" :model="form" :rules="loginRules" class="login-form" v-if="type == 'zh'">
						<h3 class="title"><span style="color: #2052f4;">账号密码</span>登录</h3>
						<el-form-item prop="username">
							<el-input v-model="form.username" type="text" auto-complete="off" placeholder="账号">
								<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
							</el-input>
						</el-form-item>
						<el-form-item prop="password">
							<el-input v-model="form.password" type="password" auto-complete="off" placeholder="密码"
								@keyup.enter.native="handleLogin">
								<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
							</el-input>
						</el-form-item>
						<el-form-item prop="code" >
							<el-input v-model="form.code" auto-complete="off" placeholder="验证码" style="width: 63%"
								@keyup.enter.native="handleLogin">
								<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
							</el-input>
							<div class="login-code">
								<img :src="codeUrl" @click="getCode" class="login-code-img" />
							</div>
						</el-form-item>
						<el-form-item style="width:100%;">
							<el-button :loading="loading" size="medium" type="danger" style="width:100%;background-color: #2254f4;border-color: #2254f4;"
								@click.native.prevent="handleLogin">
								<span v-if="!loading">登 录</span>
								<span v-else>登 录 中...</span>
							</el-button>
						</el-form-item>
					</el-form>
					<div v-else-if="type == 'wx'" class="login-form">
							<h3 class="title"><span style="color: #2052f4;">微信扫码</span>登录</h3>
							<div style="text-align: center;color:#aab0b5 ;font-size: 14px;">
								未注册的微信号将自动创建稿定账号
							</div>
							<div style="text-align: center;">
								<img src="../assets/images/weweima.png" style="width: 180px;margin-top: 10px;margin-bottom: 20px;" alt="" />
							</div>
					</div>
					<div style="background-color: #f5f7fb; padding: 10px 0;text-align: center;color: #bbbcbe;font-size: 14px;font-weight: bold;">
						主办单位:中国铁道工程建设协会建设监理专业委员会
					</div>
				</div>
				
			</div>
			
		</div>
		
		<!--  底部  -->
		<div class="el-login-footer">
			<!-- <span>Copyright © 2018-2023 ruoyi.vip All Rights Reserved.</span> -->
		</div>
	</div>
</template>

<script>
	import {
		getCodeImg
	} from "@/api/login";
	import Cookies from "js-cookie";
	import {
		encrypt,
		decrypt
	} from '@/utils/jsencrypt'

	export default {
		name: "LoginQy",
		data() {
			return {
				type:'zh',
				codeUrl: "",
				form: {
					username: "",
					password: "",
					rememberMe: false,
					code: "",
					uuid: "",
					type: null,
					cardName: "",
					cardNo: "",
				},
				loginRules: {
				  username: [
				    {
				      required: true,
				      trigger: "blur",
				      message: "请输入用户名",
				    },
				  ],
				  password: [
				    {
				      required: true,
				      trigger: "blur",
				      message: "请输入密码",
				    },
				  ],
				  code: [
				    {
				      required: true,
				      trigger: "blur",
				      message: "请输入验证码",
				    },
				  ],
				},
				loading: false,
				// 注册开关
				register: false,
				redirect: undefined
			};
		},
		watch: {
			$route: {
				handler: function(route) {
					this.redirect = route.query && route.query.redirect;
				},
				immediate: true
			}
		},
		created() {
			this.getCode();
		},
		methods: {
			getCode() {
				getCodeImg().then(res => {
					this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
					if (this.captchaEnabled) {
						this.codeUrl = "data:image/gif;base64," + res.img;
						this.form.uuid = res.uuid;
					}
				});
			},
			handleLogin() {
				this.$refs.form.validate((valid) => {
				  if (valid) {
				    this.loading = true;
				    this.form.type = "0";
				    this.$store.commit("setType", "0");
				    this.$store
				      .dispatch("Login", this.form)
				      .then(() => {
				        this.$router
				          .push({
				            path: this.redirect || "/index",
				          })
				          .catch(() => { });
				      })
				      .catch((error) => {
							this.loading = false;
							if (this.captchaEnabled) {
							  this.getCode();
							}
				      });
				  }
				});
			}
		}
	};
</script>

<style rel="stylesheet/scss" lang="scss">
	.login {
		height: 100%;
		position: relative;
		background-image: url("../assets/images/beijing.jpg");
		// background-size: cover;
	}

	.login-box {
		// background: url("../assets/images/box.png") no-repeat;
		display: flex;
		justify-content: flex-end;
		// background-color: #fff;
		border-radius: 10px;
		
	}

	.title {
		margin: 0px auto 30px auto;
		text-align: center;
		// color: #F56C6C;
		font-weight: bold;
		font-size: 20px;
		letter-spacing: 4px;
	}

	.login-form {
		// height: 100%;
		border-radius: 6px;
		// background: #ffffff;
		width: 480px;
		padding: 25px 60px 5px 60px;

		.el-input {
			height: 38px;

			input {
				height: 38px;
			}
		}

		.input-icon {
			height: 39px;
			width: 14px;
			margin-left: 2px;
		}
	}

	.login-tip {
		font-size: 13px;
		text-align: center;
		color: #bfbfbf;
	}

	.login-code {
		width: 33%;
		height: 38px;
		float: right;

		img {
			cursor: pointer;
			vertical-align: middle;
		}
	}

	.el-login-footer {
		height: 40px;
		line-height: 40px;
		position: fixed;
		bottom: 0;
		width: 100%;
		text-align: center;
		color: #fff;
		font-family: Arial;
		font-size: 12px;
		letter-spacing: 1px;
	}

	.login-code-img {
		height: 38px;
	}
	.dhk{ 
		padding: 5px 10px;
		position: relative;
		background-color: #f0f6ff;
		color: #587df6;
		border-radius: 4px;
		// box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
	}
	
</style>