<template>
  <view class="pass-box">
    <en-nav  :right-show="true" right-text="忘记密码?" @rightClick="goToEditPass"></en-nav>
    <view class="login-box" >
      <view class="login-top">
        <view class="login-title">
          <text class="title-item sys-color-black sys-weight-600">账号登录</text>
        </view>
        <view class="login-from">
          <view class="from-text" :class="{'apply-shake':phoneShake}">
            <input type="tel" class="from-input sys-color-gray-3" max="11" v-model="phone" placeholder="请输入手机号"></input>
          </view>
          <view class="from-text from-item" :class="{'apply-shake':passwordShake}">
            <input type="password" class="from-input sys-color-gray-3" v-model="password" placeholder="请输入密码"></input>
          </view>
        </view>
        <view class="login-but sys-color-white sys-background-black sys-selected-but" @click="login" :class="{'sys-unselected-but':!isLogin}">登录</view>
      </view>
    </view>
  </view>
</template>


<script>
import EnNav from "@/components/en-utils/en-nav/en-nav";
import tools from "@/service/tools";
export default {
  components: {EnNav},
  data() {
    return {
      isLogin:false,
      phoneShake:false,
      passwordShake:false,
      phone:'',
      password:'',
    }
  },
  watch:{
    'phone':function (){
      this.verifyIsLogin()
    },
    'password':function (){
      this.verifyIsLogin()
    },
  },
  methods: {
    login(){
      if(this.phone.length !== 11){
        tools.error('请输入手机号码')
        this.setShake(1)
        tools.vibrate()
        return false
      }
      if(this.password ===''){
        tools.error('请输入密码')
        this.setShake(2)
        tools.vibrate()
        return false
      }
      uni.navigateTo({
        'url':'/pages/index/index'
      })
    },
    setShake(type){
      if(type===1){
        this.phoneShake=true
      }else {
        this.passwordShake=true
      }
      setTimeout(()=>{
        this.phoneShake=false
        this.passwordShake=false
      },500)
    },
    verifyIsLogin(){
      this.isLogin = this.phone.length === 11 && this.password.length>=6;
    },
    goToEditPass(){
      uni.navigateTo({
        'url':'/pages/login/forgetPass'
      })
    }
  }
}
</script>

<style scoped lang="scss">
.pass-box{
  padding: 82rpx 80rpx 0 80rpx;
  box-sizing: border-box;
  position: relative;
  .login-top{
    .login-title{
      padding-bottom: 60rpx;
      .title-item{
        font-size: 48rpx;
      }
    }
    .login-from{
      .from-text{
        width: 100%;
        padding-bottom: 40rpx;
        border-bottom: 1rpx solid #E0E0E0;
        .from-input{
          font-size: 32rpx;
          height: 44rpx;
          line-height: 44rpx;
        }
        .from-input::placeholder{
          color: #999999;
        }
      }
      .from-item{
        margin-top: 60rpx;
      }

    }

    .login-but{
      margin-top: 120rpx;
    }

    .local-txt{
      padding-top: 32rpx;
      font-size: 24rpx;
      text-align: center;
    }
  }
  .login-bottom{
    padding-bottom: calc(186rpx + env(safe-area-inset-bottom));
    position: absolute;
    bottom: 0;
    left: 80rpx;
    width:calc(100vw - 160rpx);
  }
}

</style>
