<style scoped>

  .login-container {
    position: fixed;
    height: 100%;
    width: 100%;
    /*background-color: rgba(42, 53, 70, 0.85);*/
  }

  .login {
    margin-top: 10%;
  }

  .login-form {
    /*border: 1px solid rgba(127, 125, 125, 0.41);*/
    border-radius: 4px;
    transition: .2s;
    padding: 16px;
    color: rgba(241, 250, 247, 0.05);
  }

  .login-button {
    margin-left: 43%;
    /*text-align: center;*/
    width: 20%;
  }

  .text-content {
    /*color: #e0e1e2;*/
  }

  .font-color .el-form-item__label {
    color: #e0e1e2;
  }

  /*.input-color .el-input__inner {*/
  /*  background-color: #2d3a4b;*/

  /*}*/
  /*.el-input__inner[SuccessColor="success"] {*/
  /*  background-color: #67C23A;    //绿色*/
  /*}*/
</style>
<template>
  <div class="login-container">
    <div class="login">
      <el-row>
        <el-col :span="10">&nbsp;</el-col>
        <el-col :span="8"><h1 class="text-content">KA后台管理系统</h1></el-col>
      </el-row>
      <el-row>
        <el-col :span="8">&nbsp;</el-col>
        <el-col :span="8" class="login-form">
          <el-form :model="user" :rules="rules" ref="loginForm" label-width="100px" label-suffix="：">
            <el-form-item class="font-color" label="用户名" prop="name">
              <el-input class="input-color" v-model="user.name" auto-complete="on" placeholder="username"></el-input>
            </el-form-item>
            <el-form-item class="font-color" label="密码" prop="pass">
              <span class="svg-container">
                <svg-icon icon-class="password"/>
              </span>
              <el-input class="input-color" type="password" v-model="user.pass" auto-complete="on"
                        placeholder="password"></el-input>
            </el-form-item>

          </el-form>
          <el-form>
            <el-form-item>
              <el-button class="login-button" type="primary" @click="login('loginForm')">登录</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
  </div>
</template>


<script>
  import {mapGetters} from 'vuex'
  // import {login} from '../../apis/login'

  export default {
    data() {
      let checkName = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('用户名不能为空'));
        }
        setTimeout(() => {
          if (!value) {
            callback(new Error('用户名不能为空'));
          } else {
            callback();
          }
        }, 1000);
      };
      return {
        user: {
          name: '',
          pass: ''
        },
        rules: {
          name: [
            {required: true, message: '请输入用户名，用户名不能为空', trigger: 'blur'},
            {validator: checkName, trigger: 'blur'}
          ],
          pass: [
            {required: true, message: '请输入密码', trigger: 'blur'},
            {min: 3, max: 15, message: '长度为 3~15 个字符', trigger: 'blur'}
          ]
        }
      };
    },
    computed: mapGetters([
      'tokens'
    ]),
    watch: {
      tokens: function (val) {
        this.$router.push('/home/channels');
      }
    },
    methods: {
      login(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$store.dispatch('login', {name: this.user.name, pass: this.user.pass})
          } else {
            return false;
          }
        });
      }
    }
  }
</script>
