<template>
  <div class="logincontainer">
    <el-form class="loginForm" :model="loginModel" ref="loginFormRef" :rules="rules" :inline="false">
      <el-form-item>
        <div class="loginTitle">永信达商城系统</div>
      </el-form-item>
      <el-form-item prop="username">
        <el-input placeholder="请输入账户" size="large" v-model="loginModel.username">
          <template #prefix>
            <el-icon class="el-input__icon">
              <component :is="'avatar'" />
            </el-icon>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" size="large" placeholder="请输入密码" v-model="loginModel.password">
          <template #prefix>
            <el-icon class="el-input__icon">
              <component :is="'lock'" />
            </el-icon>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item prop="code">
        <el-row :gutter="24">
          <el-col :span="16">
            <el-input placeholder="请输入验证码" size="large" v-model="loginModel.code" maxlength="4"
              @keyup.enter.native="login" spellcheck="false">
              <template #prefix>
                <el-icon class="el-input__icon">
                  <circle-check />
                </el-icon>
              </template>
            </el-input>
          </el-col>
          <el-col :span="2"></el-col>
          <el-col :span="4">
            <img :src="imgSrc" @click="getImage" />
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item>
        <el-button class="mybtn" @click="login" type="primary" size="large" :loading="loginState">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup lang="ts">
import useImage from "@/services/business/login/useImage";
import useBaseLogin from "@/services/business/login/useBaseLogin";
import useLogin from "@/services/business/login/useLogin";
//基础数据
const { loginModel, rules, loginFormRef } = useBaseLogin();

//验证码
const { imgSrc, getImage } = useImage();

//登录
const { login, loginState } = useLogin(loginModel);
</script>
<style scoped lang="scss">
.logincontainer {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url("../../assets/login-background.jpg");

  .loginForm {
    height: 320px;
    width: 400px;
    border-radius: 10px;
    padding: 20px 35px;
    background-color: white;
    box-shadow: 0 0 25px #cac6c6;

    .loginTitle {
      margin: 0 auto;
      font-size: 24px;
      font-weight: 600;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .mybtn {
      width: 100%;
    }

    .el-icon {
      height: 2.8em;
      margin-left: -5px;
    }
  }
}
</style>
