<!-- eslint-disable no-unused-vars -->
<!--
 * @Author: Kane
 * @Date: 2022-12-14 15:23:54
 * @LastEditors: Kane
 * @LastEditTime: 2022-12-26 16:50:02
 * @FilePath: \admin_system\src\views\account\Login.vue
 * @Description: 
 * 
 * Copyright (c) ${2022} by Kane, All Rights Reserved. 
-->
<template>
  <div id="login">
    <div class="form-warp">
      <ul class="menu-tab">
        <li :class="{ 'current': current_menu === item.type }" @click="onToggleMenu(item.type)" v-for="item in tab_menu"
          :key="item.type">{{ item.label }}
        </li>
      </ul>
      <!-- <el-form ref="form" :model="form"> -->
      <el-form ref="form">
        <el-form-item>
          <label class="form-label">用户名</label>
          <el-input type="text" v-model.lazy.trim="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item>
          <label class="form-label">密码</label>
          <el-input type="password" v-model.lazy.trim="loginForm.password"></el-input>
        </el-form-item>
        <el-form-item v-show="current_menu === tab_menu[1].type">
          <label class="form-label">确认密码</label>
          <el-input type="password" v-model.lazy.trim="loginForm.confirm_password"></el-input>
        </el-form-item>
        <el-form-item>
          <label class="form-label">验证码</label>
          <el-row :gutter="10">
            <el-col :span="14">
              <el-input type="text"></el-input>
            </el-col>
            <el-col :span="10">
              <el-button type="danger" class="el-button-block" @click="getValidateCode()">获取验证码</el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="el-button-block" @click="login" :disabled="submit_btn_disable"
            :loading="submit_btn_loading">
            {{ current_menu === "login" ? "登录" : "注册" }}
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { Login } from "@/utils/api/info/account";
import { ElMessage } from "element-plus";

export default {
  name: "loginPage",
  data()
  {
    return {
      loginForm: {
        username: "",
        password: "",
        confirm_password: "",
        validateCode: "",
      },
      tab_menu: [
        { type: "login", label: "登录" },
        { type: "regiester", label: "注册" },
      ],
      current_menu: "",
      staffInfo: null,
      submit_btn_disable: false,
      submit_btn_loading: false,
    };
  },
  methods: {
    onToggleMenu(type)
    {
      this.current_menu = type;
      console.log(process.env.VUE_APP_API_URL_LOGIN);
    },
    getValidateCode()
    {
      ElMessage({
        message: "测试文字测试文字测试文字测试文字测试文字测试文字测试文字测试文字测试文字",
        center: true,
        type: "error",
      });
    },
    login()
    {
      this.submit_btn_disable = true;
      this.submit_btn_loading = true;

      const userInfo = {
        p13account: "588",
        password: "Kane@19831",
      };

      Login(userInfo)
        .then((response) =>
        {
          const data = response.data;

          //判断是否成功，显示提示信息
          if (data.success === true)
          {
            ElMessage({
              message: data.message,
              type: "success",
              center: true,
            });

            this.staffInfo = data.staffInfo;
          }
          else
          {
            ElMessage({
              message: data.message,
              type: "error",
              center: true,
            });
          }

          this.submit_btn_disable = false;
          this.submit_btn_loading = false;
        })
        .catch((error) =>
        {
          console.log(error);

          ElMessage({
            message: error.message,
            type: "error",
            center: true,
          });

          this.submit_btn_disable = false;
          this.submit_btn_loading = false;
        });
    }
  },
  created()
  {
    //初始化菜单选项
    this.current_menu = this.tab_menu[0].type;
  }
};
</script>

<style scoped>
#login {
  height: 100vh;
  background-color: #344a5f;
  padding-top: 50px;
}

.form-warp {
  width: 320px;
  padding: 30px;
  margin: auto;
  background-color: #ffffff10;
  border-radius: 5px;
}

/*.menu-tab {
  text-align: center;
  margin-bottom: 15px;

  li {
    display: inline-block;
    padding: 10px 24px;
    margin: 0 10px;
    color: #fff;
    font-size: 16px;
    border-radius: 5px;
    cursor: pointer;

    &.current {
      background-color: rgba(0, 0, 0, 0.1);
    }
  }
}*/
.menu-tab {
  text-align: center;
  margin-bottom: 15px;
}

.menu-tab li {
  display: inline-block;
  padding: 10px 24px;
  margin: 0 10px;
  color: #fff;
  font-size: 14px;
  border-radius: 5px;
  cursor: pointer;
}

.menu-tab .current {
  background-color: rgba(0, 0, 0, 0.1);
}

.form-label {
  display: block;
  color: #fff;
  font-size: 14px;
}

.el-button-block {
  width: 100%;
}
</style>