<template>
  <!-- <div class="tw-flex tw-flex-col tw-items-center">
    <img class="tw-w-30 tw-mt-20" src="images/img1.png" alt=""/>
    <h1 style="font-size: 50px; font-weight: bolder">费县时空大数据平台</h1>
  </div>
  <el-form
      ref="loginForm"
      :model="loginForm"
      :rules="rules"
      label-width="80px"
      class="login"
      @keyup.enter.native="submitForm('loginForm')"
  >
  
    <el-form-item label="帐号" prop="email">
      <el-input v-model="loginForm.email"></el-input>
    </el-form-item>

    <el-form-item label="密码" prop="password">
      <el-input v-model="loginForm.password" show-password></el-input>
    </el-form-item>

    <el-form-item>
      <router-link :to="{path:'/register'}">
        <el-link type="primary" :underline="false" style="float:left;">没有账号？去注册</el-link>
      </router-link>
      <el-button @click="submitForm('loginForm')">登录</el-button>
      <el-button @click="resetForm('loginForm')">重置</el-button>
    </el-form-item>

  </el-form> -->
    <div class="main-container">
    <div class="title-container">
      
    </div>
    <div class="title">
      <p style="font-size:24px;letter-spacing: 0.6ch;margin-bottom:32px;">农业农村时空大数据平台底座</p>
      <!-- <p style="font-size:14px;margin-top:22px;font-family:'Poppins',sans-serif;margin-bottom:32px;">Welcome to Fei Xian spatiotemporal big data platform</p> -->
    
        <!-- <span style="padding:8px 32px;border:1px solid #fff;margin-top:48px;border-radius:8px;" @click="$router.push({'path':'/'})" >
          <img src="/public/images/home.png" style="width:20px;position:relative;top:3px;left:-6px;" alt="">
          首页
        </span> -->
    </div>
    <div class="login-form">
      <p style="text-align:center;font-size:18px;color:#666;font-weight:bold;line-height:50px;margin-bottom:42px;">
        <el-button type="primary" icon="Iphone" style="position:relative;top:-3px;left:-12px;" circle></el-button>
        手机号码登录
      </p>
      <el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="100px" class="demo-ruleForm" label-position="top">
        <el-form-item label=""  prop="email">
          <el-input v-model="loginForm.email" placeholder="手机号码"  >
            <i slot="prefix" class="el-input__icon el-icon-mobile-phone"></i>
          </el-input>
        </el-form-item>
      
        <el-form-item label="" prop="password">
          <el-input v-model="loginForm.password" type="password" placeholder="登录密码" show-password>
            <i slot="prefix" class="el-input__icon el-icon-lock"></i>
          </el-input>
        </el-form-item>
      
        <el-form-item label="" prop="agreement">
          <el-checkbox v-model="rememberPassword" >
            记住密码
              <!-- 我已阅读并同意<el-link  type="primary" :underline="false">服务协议</el-link>&nbsp;和&nbsp;<el-link  type="primary" :underline="false">隐私声明</el-link> -->
          </el-checkbox>
          <router-link :to="{path:'/register'}">
            <el-link style="float:right;" type="primary" :underline="false">立即注册>></el-link>
          </router-link>
        
        </el-form-item>
        <el-form-item>
          <el-button type="primary"  style="width:100%;" @click="submitForm('loginForm')">立 即 登 录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import {login} from '../../api/login'
export default {
  data() {
    return {
      loginForm: {
        email: "",
        password: "",
      },
      rules: {
        email: [
          {
            required: true,
            message: "请输入账号",
            trigger: "blur",
          }
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          }
        ],
      },
      rememberPassword:false
    };
  },
  watch:{
    rememberPassword:function(e){
      if(e == false){
        localStorage.setItem("remember",false);
        localStorage.setItem("loginInfo","");
      }
    }
  },
  created(){
    this.checkIsRememberPassword();
  },
  methods: {
    submitForm(formName) {
      axios.post(
        "http://60.213.14.14:6050/api/Check/Login",
        {
          account: "System",
          appKey: "openauth",
          password: "HopetryA1406"
        },

      ).then(res=>{
        if(res.data.code == 200){
          let XToken = res.data.token;
          localStorage.setItem("XToken",XToken)
        }
      })

      this.$refs[formName].validate((valid) => {
        if (valid) {
           login(this.loginForm.email,this.loginForm.password).then(res=>{
              if(res.code == 200 && res.token != ""){
                localStorage.setItem("Token",res.token);
                localStorage.setItem("username",this.loginForm.email);
                this.$message.success("登录成功！");
                this.$router.push("/cim?type=shangyezhen&id=1718896072287322112&title=上冶镇农业数字底座");
                this.rememberPasswordFun();
              }else{
                  this.$message.error("账号或密码错误！");
              }
            }).catch(error=>{
              this.$message.error("账号或密码错误！");
            })
        } else {
        
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    rememberPasswordFun(){
      if(this.rememberPassword == true){
        localStorage.setItem("remember",true);
        localStorage.setItem("loginInfo",JSON.stringify(this.loginForm));
      }else{
        localStorage.setItem("remember",false);
        localStorage.setItem("loginInfo","");
      }
    },
    checkIsRememberPassword(){
      if(localStorage.getItem("remember") =='true'){
        this.rememberPassword = true
        this.loginForm = JSON.parse(localStorage.getItem("loginInfo"));
      }
      
    },
    
  },
};
</script>

<style scoped>
.main-container{
  width:100vw;
  height:100vh;
  background:#fff;
}
.title-container{
  content: "";
  position: absolute;
  height: 2000px;
  width: 2000px;
  top: -10%;
  right: 48%;
  transform: translateY(-50%);
  background-image: linear-gradient(-45deg,#4481eb 0,#04befe 100%);
  transition: 1.8s ease-in-out;
  border-radius: 50%;
  z-index: 6;
  color:#fff;
}
.title{
  width:50vw;
  text-align: center;
  z-index:999;
  position:absolute;
  top:30%;
  left:0px;
  color:#fff;
}
.login-form{
  width:400px;
  height:400px;
  position:absolute;
  top: calc(50vh - 220px);
  z-index:9999999;
  left: calc(50vw + 190px);
}
::v-deep .el-input__inner{
  border:0px;
  border-radius: 16px;
  box-shadow: none;
}
::v-deep .el-form-item__content{
  text-align: left;
}
::v-deep .el-input__wrapper{
  background: #E8F0FE !important;
  padding: 0 11px !important;
  border-radius: 16px !important;
}
</style>
