<template>
  <div class="login">
    <el-form
        ref="loginForm"
        :model="loginForm"
        :rules="loginRules"
        class="login-form"
    >
      <h3 class="title">{{ title }}</h3>
      <el-form-item
          prop="username"
      >
        <el-input
            v-model="loginForm.username"
            type="text"
            auto-complete="off"
            placeholder="请输入账号"
            :prefix-icon="User"
            clearable
        >
        </el-input>
      </el-form-item>
      <el-form-item
          prop="password"
      >
        <el-input
            class="password-input"
            v-model="loginForm.password"
            type="password"
            auto-complete="off"
            placeholder="请输入密码"
            :prefix-icon="Lock"
            clearable
            show-password
        >
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="login-btn" type="primary" @click="submitForm()">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts" name="webLogin" setup>
// 引入icon （如果没有引入 可以注释）
import router from "@/router";
import { User, Lock } from '@element-plus/icons-vue';
import { ref } from "vue";
import { ElForm, ElMessageBox } from "element-plus";


const title: string = '数字物流平台'
const codeUrl = ref<string>("");
const registerRef = ref<InstanceType<typeof ElForm>>();

const loginForm = ref({
  username: "",
  password: "",
  rememberMe: false,
  code: "",
  uuid: "",
})

const loginRules = {
  // 对用户名进行校验 数组 一个输入框可以有多条校验规则
  username: [
    { required: true, trigger: "blur", message: "请输入您的账号" },
  ],
  password: [
    { required: true, trigger: "blur", message: "请输入您的密码" },
  ],
  code: [
      { required: true, trigger: "change", message: "请输入验证码" }
  ],
}

const submitForm = () => {
  registerRef.value?.validate((valid: boolean) => {
    if (valid) {
      alert('check success submit!');
      router.push('/')
    } else {
      console.log('error submit!!');
      return false;
    }
  })
}
</script>

<style scoped>

.login {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background-size: cover;
}

.login-form {
  width: 250px;
}

.password-input {
  margin-top: 15px;
}

.login-btn {
  display: block;
  margin: 15px auto 0;
  width: 100%;
}

</style>
