<template>
  <div>
    <!--        <img :src="bcg" alt="" class="pos">-->
    <div class="container" @keypress="keypress">
      <div class="bigTitle">业委会管理系统登录</div>

    <div class="module" v-if="step == 0" style="margin-top: 50px;width: 100%; display: flex;flex-direction:column;align-items: center ;">
      <div class="floor">

        <el-button style="width: 240px; height: 50px;border:1px solid rgb(64,158,225);color: rgb(64,158,225)" @click="changeType('1')">密码登录</el-button>
      </div>

      <div class="floor">
        <el-button style="width: 240px; height: 50px;border:1px solid rgb(64,158,225);color: rgb(64,158,225)" @click="changeType('2')">验证码登录</el-button>
      </div>
    </div>

    <div v-if="step == 1" class="module">
      <div class="floor">
        <div class="title">手机号</div>
        <el-input class="input" type="text" v-model="loginForm.mobile"/>
      </div>

      <div class="floor" v-if="loginForm.type == 1">
        <div class="title">密码</div>
        <el-input class="input" show-password type="text" v-model="loginForm.securityCode"/>
      </div>

      <div class="floor" v-if="loginForm.type == 2">
        <div class="title">验证码</div>

        <el-input class="codeInput" type="text" v-model="loginForm.securityCode"/>
        <el-button type="success" @click="getSecurityCode" style="width: 100px;display: flex;justify-content: center;">获取验证码</el-button>
      </div>
      <div class="floor">
        <el-button style="width: 100%" @click="handleLogin" type="success">登录</el-button>
      </div>
    </div>

    </div>
  </div>
</template>

<script>
import {Loading} from 'element-ui';

export default {
  name: "index",
  data: () => {
    return {
      step:0,
      loginForm: {

        securityCode: "",
        mobile: '',
        type:""
      },
      codeSrc: ""
    }
  },
  created() {
    this.captchaImage();
  },
  methods: {

    changeType(type){
        this.loginForm.type = type;
        this.step = 1;


    },
    getSecurityCode(){
      let mobile = this.loginForm.mobile;

      if(mobile == ""){
        this.$message.warning("请先输入手机号码")
        return false;
      }
        this.$api.verificationCode({
          mobile
        }).then(res => {
          console.log(res)
          this.loginForm.securityCode = res.content.verificationCode;

        })
    },
    keypress(e){
      if(e.keyCode == 13){
        this.handleLogin();
      }
    },

    handleLogin() {
       this.$api.login(this.loginForm).then(res => {
         // console.log(res)
         this.$router.push("home")
       })
    }
  }
}
</script>

<style scoped>
.code {
  height: 50px;
  width: 100px;
  cursor: pointer;
  padding-left: 10px;
  box-sizing: border-box;
}

.floor {
  display: flex;
  margin-top: 20px;
  align-items: center;
}

.floor .title {
  flex-grow: 1;
}

.input {
  width: 240px;
}

.codeInput {
  width: 140px;
}

.container {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%); /* 50%为自身尺寸的一半 */
  z-index: 4;
  background-color: #fff;
  width: 360px;
  height: 300px;
  padding: 30px;
  border-radius: 20px;
}

.pos {
  position: fixed;
  height: 100vh;
  width: 100vw;
  z-index: 3;
}

.bigTitle {
  font-weight: bold;
  font-size: 24px;
  text-align: center;
}
</style>
