<template>
  <div class="login">
    <div class="login-box">
      <div class="login-box-content">
        <div> <span>邮箱</span> <input v-model="email" type="text" class="email" placeholder="请输入邮箱">
          <div @click="getEmailCode" class="login-box-send">发送</div>
        </div>
        <div> <span>验证码</span> <input v-model="verifyCode" type="text" placeholder="请输入邮箱验证码"></div>
        <div> <span>密码</span> <input v-model="password" type="password" placeholder="请输入密码"></div>
        <img @click="register" src="@/assets/images/login/register.png">
      </div>
      <div class="login-box-btn">
        <img @click="backLogin()" src="@/assets/images/login/backlogin.png">
      </div>
    </div>
  </div>
</template>

<script>
import { sendEmail, register } from '~/api/user.js'
export default {
  name: 'RegisterPage',
  data() {
    return {
      email: '',
      verifyCode: '',
      password: ''
    };
  },
  created() {
  },
  methods: {
    backLogin() {
      this.$router.push('/login')
    },
    async getEmailCode() {
      if (this.email === '') return this.$toast('请输入邮箱')
      try {
        const res = await sendEmail(this.email)
        this.$toast(res.data)
      } catch (err) {
        this.$toast(err)
      }
    },
    async register() {
      if (this.verifyCode === '' || this.email === '' || this.password === '') return this.$toast('请输入内容')
      try {
        const payload = {
          code: this.verifyCode,
          email: this.email,
          password: this.password,
        }
        const res = await register(payload)
        this.$toast(res.data)
        setTimeout(() => {
          this.$router.push('/login')
        }, 1000);
      } 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_2.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    width: 375px;
    height: 548px;
    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;
          }
        }

        .email {
          padding-right: 60px;
        }
      }

      .login-box-send {
        position: absolute;
        color: #B5E1F2FF;
        font-size: 15px;
        margin-bottom: 0;
        margin-left: 170px;
        border-left: 1px solid #B5E1F2FF;
        padding-left: 10px;

      }

      img {
        height: 60px;
      }
    }



    &-btn {
      display: flex;
      justify-content: flex-end;
      margin-top: 145px;

      img {
        height: 60px;
        margin-right: 15%;
      }
    }
  }
}
</style>
