<template>
  <div class="username">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item prop="name">
        <el-input v-model="ruleForm.name" placeholder="请输入账号"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="ruleForm.password"
          placeholder="请输入密码"
          show-password
        ></el-input>
      </el-form-item>
      <el-button type="primary" @click="submitForm()">登录</el-button>
      <p>
        还没有账号？<span @click="$router.push('/user/register')">立即注册</span
        ><span>|</span
        ><span @click="$router.push('/user/forgetPassword')">忘记密码？</span>
      </p>
    </el-form>
  </div>
</template>

<script>
import { userPinByLgoin } from "@/api/user.js";
import { seveCookie } from "@/utils/getToken.js";
export default {
  data() {
    return {
      ruleForm: {
        name: "",
        password: ""
      },
      rules: {
        name: [{ required: true, message: "请输入账号", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  methods: {
    //提交表单
    submitForm() {
      let from = {
        userName: this.ruleForm.name, // Y 手机号
        password: this.ruleForm.password // Y 密码
      };
      if (this.ruleForm.name && this.ruleForm.password) {
        userPinByLgoin(from).then(res => {
          if (res.status == 0) {
            seveCookie("userpin", res.data.userpin);
            seveCookie("username", this.ruleForm.name);
            this.$message({
              message: "登录成功！",
              type: "success"
            });
            this.$router.push("/jdtrademark");
          } else if (res.status == 2010) {
            this.$message.error("账户或密码错误！");
          } else if (res.status == 2060) {
            this.$message({
              message: "请不要重新登录！",
              type: "warning"
            });
          } else {
            this.$message.error("登录失败！");
          }
        });
      }
    }
  }
};
</script>

<style lang="scss">
.username {
  .el-form {
    .el-form-item {
      .el-form-item__content {
        margin-left: 0 !important;
        display: flex;
      }
    }
  }
  p {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(153, 153, 153, 1);
    line-height: 20px;
    margin-top: 60px;
    text-align: center;
  }
  .el-input {
    input {
      width: 100%;
      height: 42px;
      border-radius: 0;
    }
  }
  .el-form {
    .el-form-item {
      margin-top: 30px;
      button {
        border-radius: 0;
        border: 1px solid #108ee9;
        color: #108ee9;
        margin-left: 10px;
        min-width: 150px;
        height: 41px;
        margin-top: 0;
      }
    }
    button {
      width: 100%;
      height: 42px;
      margin-top: 20px;
      border-radius: 0;
      background: #3071fe;
      border: 1px solid #3071fe;
    }
    p {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: rgba(102, 102, 102, 1);
      line-height: 20px;
      text-align: center;
      margin-top: 10px;
      span {
        color: #108ee9;
        cursor: pointer;
        margin: 0 5px;
      }
    }
  }
}
</style>
