<template>
  <div id="login">
    <h1>程序员客栈 - BOSS</h1>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="ruleForm">
      <el-form-item label="账号" prop="webmaster">
        <el-input v-model="ruleForm.webmaster" placeholder="请输入账号"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="ruleForm.password" type="password" placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item label="口令" prop="cypher">
        <el-input
          v-model="ruleForm.cypher"
          type="password"
          placeholder="请输入口令"
          @keyup.native.enter="submit"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button style="width: 100%;" type="primary" @click="submit">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  layout: "empty",
  data() {
    return {
      ruleForm: {
        // 账号
        webmaster: "",
        // 密码
        password: "",
        // 口令，格式：inn月日，无 0
        cypher: ""
      },
      rules: {
        webmaster: [{ required: true, message: "请输入账号", trigger: "blur" }],
        password: [
          { required: true, message: "请输入密码", trigger: "change" },
          { min: 6, message: "长度在 6 个字符以上", trigger: "blur" }
        ],
        cypher: [{ required: true, message: "请输入账号", trigger: "blur" }]
      }
    };
  },
  methods: {
    async submit() {
      // this.$router.replace('/main')
      // return
      const { webmaster, password, cypher } = this.ruleForm;
      const res = await this.$post("/api/admin/index/login", {
        webmaster,
        password,
        cypher
      });
      console.log(res);
      if (res && res.status) this.$router.replace("/main");
    }
  }
};
</script>

<style>
#login {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 200px;
}
.ruleForm {
  width: 550px;
}
</style>
