<template>
  <div class="login-container">
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
      <h3 class="title">KA管理系统</h3>
      <h3 class="title2">
        <span class="svg-container">
          <svg-icon :iconClass="'example'"/>
        </span>登陆试试~~</h3>
      <el-form-item prop="username">
        <span class="svg-container">
          <svg-icon :iconClass="'user'"/>
        </span>
        <el-input v-model="loginForm.username" name="username" placeholder="邮箱前缀">
            <template slot="append">@quantgroup.cn</template>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <span class="svg-container">
          <svg-icon :iconClass="'password'" />
        </span>
        <el-input
          v-model="loginForm.password"
          :type="pwdType"
          name="password"
          auto-complete="on"
          placeholder="password"
          @keyup.enter.native="handleLogin" />
        <span class="show-pwd" @click="showPwd">
          <svg-icon :iconClass="pwdType === 'password' ? 'eye' : 'eye-open'" />
        </span>
      </el-form-item>
      <el-form-item>
        <el-button :loading="loading" type="primary" style="width:100%;" @click.native.prevent="handleLogin">
          登陆
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import '@/icons'
  import {mapGetters} from 'vuex'


  export default {
    data() {
      return {
        loginForm: {
          username: '',
          password: ''
        },
        loginRules: {
          // username: [{ required: true, trigger: 'blur', validator: validateUsername }],
          // password: [{ required: true, trigger: 'blur', validator: validatePass }]
        },
        loading: false,
        pwdType: 'password',
        redirect: undefined,
        nsArray: []
      }
    },
    computed: mapGetters([
      'tokens'
    ]),
    watch: {
      tokens: function (val) {
        this.$router.push('/home/channels');
      }
    },
    created() {
    },
    methods: {
      showPwd() {
        if (this.pwdType === 'password') {
          this.pwdType = ''
        } else {
          this.pwdType = 'password'
        }
      },
      handleLogin() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
            this.loading = true
            // this.$store.dispatch('login', this.loginForm)
            this.$store.dispatch('login', this.loginForm).then(() => {
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      }
    }
  }
</script>

<style>
  .login-container .el-input {
      /*display: inline-block;*/
      height: 47px;
      width: 82%;
    }

  .login-container .el-input input {
    background: transparent;
    border: 0px;
    -webkit-appearance: none;
    border-radius: 0px;
    padding: 12px 5px 12px 15px;
    color: #eee;
    height: 47px;
  }
  .login-container .el-input input:-webkit-autofill{
    -webkit-box-shadow: 0 0 0px 1000px #2d3a4b inset !important;
    -webkit-text-fill-color: #fff !important;
  }

  .login-form .el-input-group__append{
      background: #2d3a4b;
      border: 0px solid rgba(255, 255, 255, 0.1);
  }

  .login-container .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }

</style>

<style scoped>
    .login-container {
        position: fixed;
        height: 100%;
        width: 100%;
        background-color: #2d3a4b;
    }
    .login-container .login-form {
      position: absolute;
      left: 0;
      right: 0;
      width: 520px;
      max-width: 100%;
      padding: 35px 35px 15px 35px;
      margin: 120px auto;
    }
    .login-container .tips {
        font-size: 14px;
        color: #fff;
        margin-bottom: 10px;
    }

    .svg-container {
      padding: 6px 5px 6px 15px;
      color: #889aa4;
      vertical-align: middle;
      width: 30px;
      display: inline-block;
    }
    .title {
      font-size: 26px;
      font-weight: 400;
      color: #eee;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  .title2 {
    font-size: 16px;
    font-weight: 400;
    color: #eee;
    margin: 0px auto 40px auto;
    text-align: center;
    font-weight: bold;
  }
    .show-pwd {
      position: absolute;
      right: 10px;
      top: 7px;
      font-size: 16px;
      color: #889aa4;
      cursor: pointer;
      user-select: none;
    }

</style>
