<template>
  <div class="login-container">
    <el-form ref="form" :model="form" :rules="ruleForm" class="login-page">
      <h3 style="line-height: 75px;font-size: 26px;font-weight: 800;">系统登录</h3>
      <el-form-item prop="username">
        <el-input v-model="form.username" type="text" placeholder="用户名">
          <template slot="prepend">
            <i class="el-icon-user-solid" />
          </template>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="form.password" type="password" placeholder="密码" @keyup.enter.native="handleSubmit">
          <template slot="prepend">
            <i class="el-icon-s-goods" />
          </template>
        </el-input>
      </el-form-item>
      <el-form-item style="width:100%;">
        <el-button type="primary" style="width:100%;" :loading="logining" @click="handleSubmit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
// import accountApi from '@/api/accountApi'

export default {
  name: 'Login',
  data () {
    return {
      logining: false,
      form: {
        username: '',
        password: ''
      },
      ruleForm: {
        username: [{ required: true, message: '请输入账号', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  },
  mounted () {
    /* 访问该页面重置token值 */
    this.$cookie.remove('token')
  },
  methods: {
    handleSubmit () {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return false
        }

        this.logining = true
        // accountApi.login(this.form).then(data => {
        //   this.logining = false
        //
        //   if (data) {
        //     this.$cookie.set('token', data, {expires: 7, path: '/'})
        //
        //     if (this.$route.query.redirect) {
        //       this.$router.push({path: `${this.$route.query.redirect}`})
        //       return
        //     }
        //
        //     this.$router.push({path: '/'})
        //   }
        // }).catch(() => {
        //   this.logining = false
        // })
      })
    }
  }
}
</script>

<style scoped>
  .login-container {
    width: 100%;
    height: 100%;
  }

  .login-page {
    -webkit-border-radius: 5px;
    border-radius: 5px;
    margin: 125px auto;
    width: 350px;
    padding: 15px 25px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }
</style>
