<template>
  <div class="login-other">
    <div class="left"></div>
    <div class="right">
      <div class="content">
        <p class="title"><img src="../assets/image/logo.svg" alt="">云鹊医工作站</p>
        <div class="input-info" v-if="loginFlag">
          <div class="title-div">
            <p class="title-input">账号登录</p>
            <img src="../assets/image/underline.svg" alt="">
          </div>
          <el-form ref="loginForm" :model="loginData" >
            <el-form-item label="">
              <el-input v-model="loginData.mobile" placeholder="手机号">
                <i slot="prefix" class="el-input__icon my-icon mobile-icon"></i>
              </el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input v-model="loginData.password" placeholder="密码" type="password" v-if="!showPSW">
                <i slot="prefix" class="el-input__icon my-icon password-icon"></i>
                <i @click="showPWSBtn"  slot="suffix" class="el-input__icon my-icon open-eyes-icon"></i>
              </el-input>
              <el-input v-model="loginData.password" placeholder="密码" v-else>
                <i slot="prefix" class="el-input__icon my-icon password-icon"></i>
                <i @click="hidePWSBtn" slot="suffix" class="el-input__icon my-icon close-eyes-icon"></i>
              </el-input>
            </el-form-item>
          </el-form>
          <div class="button-div">
            <div class="forget-password">
              <p @click="goToResetPassword">忘记密码？</p>
            </div>
            <button @click="login">登 录</button>
          </div>
        </div>

        <div class="input-info" v-else>
          <div class="title-div">
            <p class="title-input">重设密码</p>
            <img src="../assets/image/underline.svg" alt="">
          </div>
          <el-form ref="loginForm" :model="resetPassword" >
            <el-form-item label="">
              <el-input v-model="resetPassword.mobile" placeholder="手机号">
                <i slot="prefix" class="el-input__icon my-icon mobile-icon"></i>
              </el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input v-model="resetPassword.authCode" placeholder="短信验证码">
                <i slot="prefix" class="el-input__icon my-icon auth-code-icon"></i>
                <i v-if="countDown == 0" @click="getAuthCode" slot="suffix" class="el-input__icon get-auth-code">获取验证码</i>
                <i v-else slot="suffix" class="el-input__icon get-auth-warning">{{countDown}}s后重发</i>
              </el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input v-model="resetPassword.password" placeholder="新密码" type="password" v-if="!showPSW">
                <i slot="prefix" class="el-input__icon my-icon password-icon"></i>
                <i @click="showPWSBtn"  slot="suffix" class="el-input__icon my-icon open-eyes-icon"></i>
              </el-input>
              <el-input v-model="resetPassword.password" placeholder="新密码" v-else>
                <i slot="prefix" class="el-input__icon my-icon password-icon"></i>
                <i @click="hidePWSBtn" slot="suffix" class="el-input__icon my-icon close-eyes-icon"></i>
              </el-input>
            </el-form-item>
          </el-form>
          <div class="button-div">
            <!--<div class="forget-password">
              <p>忘记密码？</p>
            </div>-->
            <button>重设密码</button>
            <div class="login-now">
              <p @click="goToLogin">立即登录</p>
            </div>
          </div>
        </div>

      </div>
      <div class="vrcode">
        <img v-show="showVRCode" src="../assets/image/VR-code.svg" alt="">
        <p slot="reference" @mouseenter="showVR"  @mouseleave="closeVR"><img src="../assets/image/VR-mobile.svg" alt="">下载云鹊医app</p>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "login",
    data() {
      return {
        loginFlag: true,
        loginData: {},
        resetPassword: {},
        showVRCode: false,
        showPSW: false,
        countDown: 0,
        timer: null
      }
    },
    methods: {
      goToLogin() {
        this.loginFlag = true
      },
      goToResetPassword() {
        this.loginFlag = false
      },
      showVR() {
        this.showVRCode = true;
      },
      closeVR() {
        this.showVRCode = false;
      },
      showPWSBtn() {
        this.showPSW = true
      },
      hidePWSBtn() {
        this.showPSW = false
      },
      getAuthCode() {
        const TIME_COUNT = 60;
        if (!this.timer) {
          this.countDown = TIME_COUNT;
          this.timer = setInterval(() => {
            if (this.countDown > 0 && this.countDown <= TIME_COUNT) {
              this.countDown--;
            } else {
              this.countDown = 0;
              clearInterval(this.timer);
              this.timer = null;
            }
          }, 1000)
        }
      },
      login() {
        let params = {
          mobile: $scope.mobile,
          OS: localStorage.getItem("OS"),
          browser: localStorage.getItem("browser"),
          terminalType: localStorage.getItem("terminalType"),
          ipAddress: localStorage.getItem("ipAddress"),
          password: hex_md5($scope.password).toUpperCase()
        }
      }
    }
  }
</script>

<style  lang="scss">
  .my-icon {
    display: inline-block;
    height: 20px;
    margin-top: 9px;
  }
  .mobile-icon {
    background: url("../assets/image/mobile.svg") no-repeat;
  }
  .password-icon {
    background: url("../assets/image/password.svg") no-repeat;
  }
  .auth-code-icon {
    background: url("../assets/image/auth-code.svg") no-repeat;
  }
  .open-eyes-icon {
    background: url("../assets/image/open-eyes.svg") no-repeat;
    cursor: pointer;
  }
  .close-eyes-icon {
    background: url("../assets/image/close-eyes.svg") no-repeat;
    cursor: pointer;
  }
  .login-other {
    display: flex;
    height: 100%;
    flex-direction: row;
    .left {
      flex-grow: 1;
      /*大于1441*/
      @media only screen and (min-width: 1441px) {
        background: url("../assets/image/bg-big.png") no-repeat;
        background-size: cover;
      }
      /*小于1440*/
      @media only screen and (max-width: 1441px) {
        background: url("../assets/image/bg-small.png") no-repeat;
        background-size: cover;
      }
    }
    .right {
      position: relative;
      /*大于1441*/
      @media only screen and (min-width: 1441px) {
        width: 570px;
      }
      /*小于1440*/
      @media only screen and (max-width: 1441px) {
        width: 500px;
      }
      .content {
        /*大于1441*/
        @media only screen and (min-width: 1441px) {
          padding: 140px 50px 20px 50px;
        }
        /*小于1440*/
        @media only screen and (max-width: 1441px) {
          padding: 40px 50px 20px 50px;
        }
        .title {
          text-align: center;
          font-weight: 500;
          font-size: 34px;
          color: #333333;
          img {
            width: 54px;
            height: 54px;
            vertical-align: middle;
          }
        }
        .input-info {
          margin-top: 60px;
          .title-div {
            position: relative;
            margin-bottom: 30px;
            .title-input {
              font-size: 28px;
            }
            img {
              display: block;
              position: absolute;
              bottom: 3px;
            }
          }
          .el-form {
            .el-form-item {
              .el-form-item__content {
                .el-input {
                  .el-input__inner {
                    border-radius: 0;
                    border: none;
                    border-bottom: 1px solid #D9D9D9;
                  }
                  .get-auth-code {
                    color: #666666;
                    cursor: pointer;
                  }
                  .get-auth-warning {
                    color: #666666;
                  }
                }

              }
            }

          }
          .button-div {
            button {
              width: 100%;
              height: 70px;
              background: #449284;
              color: #ffffff;
              font-size: 24px;
              margin-top: 20px;
              cursor: pointer;
              box-shadow: 0px 10px 8px 0px rgba(59,132,119,0.2);
            }
            .forget-password {
              margin-top: 52px;
              color:red;
              p {
                cursor: pointer;
                width: 80px;
                float: right;
                font-size: 16px;
                color: #449284;
              }
            }
            .login-now {
              margin-top: 24px;
              p {
                width: 80px;
                margin: 0 auto;
                font-size:20px;
                color: #449284;
                cursor: pointer;
              }
            }
          }
        }

      }
      .vrcode {
        position: absolute;
        bottom: 20px;
        width: 100%;
        text-align: center;
        p {
          text-align: center;
          font-size: 20px;
          color: #999999;
          cursor: pointer;
          img {
            vertical-align: middle;
            margin-right: 4px;
          }
        }
      }
    }

  }
</style>
