<template>
  <div class="login">
    <div class="login-box">
      <div class="login-box-content">
        <div> <span>邮箱</span> <input v-model="email" type="text" placeholder="请输入邮箱"> </div>
        <div> <span>密码</span> <input v-model="password" type="password" placeholder="请输入密码"></div>
        <img @click="login" src="@/assets/images/login/login.png">
      </div>
      <div class="login-box-btn">
        <img src="@/assets/images/login/forget.png">
        <img @click="gotoRegister()" src="@/assets/images/login/gotoregister.png">
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'LoginPage',
  data() {
    return {
      email: '',
      password: ''
    };
  },
  methods: {
    gotoRegister() {
      this.$router.push('/register')
    },
    login() {
      if (this.email === '' || this.password === '') return this.$toast('请输入内容')
      try {
        const payload = {
          email: this.email,
          password: this.password,
        }
        this.$store.dispatch("user/Login", payload)
        setTimeout(() => {
          this.getInfo();
          this.$router.push('/')
        }, 1000)
      } catch (err) {
        this.$toast(err);
      }
    },
    getInfo() {
      try {
        this.$store.dispatch("user/GetInfo")
      } catch (err) {
        this.$toast(err);
      }
    },
  }
}
</script>

<style  lang="scss" scoped>
.login {
  background: url("@/assets/images/login/bg.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  width: 100%;
  height: 100%;
  min-height: 100vh;

  &-box {
    position: relative;
    background: url("@/assets/images/login/box_1.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    width: 375px;
    height: 470px;
    margin: 0 auto;
    top: calc(50vh - 300px);
    padding-top: 152px;

    &-content {
      width: 260px;
      height: 245px;
      margin: 0 auto;
      text-align: center;
      padding-top: 50px;

      div {
        margin-bottom: 15px;
        display: flex;
        align-items: center;
        justify-content: center;

        span {
          font-family: "modeng";
          color: white;
          -webkit-text-stroke: 1px #1B5AA7FF;
          font-size: 20px;
          width: 65px;
          text-align: start;
        }

        input {
          padding: 10px;
          width: 170px;
          background: #1C62B8FF;
          border: 1.5px solid #7FD7EB;
          border-radius: 54px;
          color: white;

          &::placeholder {
            color: #B5E1F2FF;
            font-size: 15px;
          }
        }
      }

      img {
        height: 60px;
      }
    }

    &-btn {
      display: flex;
      justify-content: center;
      margin-top: 80px;

      img {
        height: 60px;
        margin: 0 10px;
      }
    }
  }
}
</style>
