<template lang="html">
  <div class="loginVue">
    <img src="~static/img/logo.png" alt="" class="logo">
    <div class="loginForm">
      <div class="title">
        <img src="~static/img/login_title.png" alt="">
      </div>
      <div class="form">
        <input type="text" name="username" class="username" v-model="username" spellcheck="false" placeholder="User name" @keydown.enter="login()">
        <input type="password" name="password" class="password" v-model="password" spellcheck="false" placeholder="Password" @keydown.enter="login()">
        <div class="remember">
          <label for="loginCheckbox" class="checkbox">
            <input type="checkbox" name="" v-model="isRemember" id="loginCheckbox">
            <span></span>
            Remember me
          </label>
        </div>
        <button type="button" class="btn4" @click="login()">登录</button>
      </div>
    </div>
  </div>
</template>

<script>
import { bus, requestLogin } from '@/vuex/request.js'

export default {
  data () {
    return {
      username: 'user',
      password: '123456',
      isRemember: false
    }
  },
  mounted () {

  },
  methods: {
    login () {
      if (this.username === '' || this.password === '') {
        bus.$emit('alert', '用户名和密码不可为空！')
        return false
      }
      let data = {
        username: this.username,
        password: this.password,
        isRemember: this.isRemember
      }
      // this.$router.push({'path': '/checkInfo'})
      requestLogin({}, data, (response) => {
        if (response.data) {
          if (response.data.state) {
            bus.$emit('setUserInfo', response.data.data)
            bus.$emit('alert', response.data.message)
            this.$router.push({'path': '/channelData'})
          } else {
            bus.$emit('alert', response.data.message)
          }
        } else {
          bus.$emit('alert', response + '.')
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.loginVue{
  padding: 15px 45px 0 45px;
  background-image: url('~static/img/bg.png');
  .loginForm{
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .title{
      margin-bottom: 20px;
      img{
        margin: auto;
      }
    }
    .form{
      width: 500px;
      height: 400px;
      border: 2px solid #3B444D;
      border-radius: 3px;
      background-color: #23282E;
      padding: 60px 30px;
      color: #49515C;
      box-shadow: 0 0 40px 0 rgba(11, 3, 5, .75), 0 0 10px 0 rgba(11, 3, 5, .75) inset;
      &>input{
        display: block;
        width: 100%;
        height: 40px;
        border-color: transparent;
        border-bottom-color: #49515C;
        transition: all .5s ease;
        font-size: 18px;
        background-repeat: no-repeat;
        background-position: right center;
        &.username{
          margin-bottom: 30px;
          background-image: url('~static/img/username_1.png');
          &:focus{
            border-bottom-color: #49AFF7;
            background-image: url('~static/img/username_2.png');
          }
        }
        &.password{
          margin-bottom: 10px;
          background-image: url('~static/img/password_1.png');
          &:focus{
            border-bottom-color: #49AFF7;
            background-image: url('~static/img/password_2.png');
          }
        }
        &::-webkit-input-placeholder { /* WebKit browsers */
          color: #49515C;
        }
        &:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
          color: #49515C;
        }
        &::-moz-placeholder { /* Mozilla Firefox 19+ */
          color: #49515C;
        }
        &:-ms-input-placeholder { /* Internet Explorer 10+ */
          color: #49515C;
        }
      }
      .remember{
        padding-left: 20px;
        span{
          margin-right: 10px;
        }
      }
      button.btn4:not([disabled]){
        margin-top: 75px;
        font-size: 18px;
      }
    }
  }
}
</style>
