<template>
  <div class="login-container">
    <el-form
        ref="formRef"
        :model="form"
        :rules="rules"
        class="login-form">
      <div class="title-container">
        <h3 class="title">甲情甲意管理平台</h3>
      </div>
      <el-form-item prop="userAccount">
        <!--        <el-icon :size="20" class="svg-container">-->
        <!--          <User/>-->
        <!--        </el-icon>-->
        <svg-icon icon="user" class="svg-container"></svg-icon>
        <el-input v-model="form.userAccount" placeholder="请输入用户名..."></el-input>
      </el-form-item>
      <el-form-item prop="userPassword">
        <!--        <el-icon :size="20" class="svg-container">-->
        <!--          <lock/>-->
        <!--        </el-icon>-->
        <svg-icon icon="password" class="svg-container"></svg-icon>
        <el-input v-model="form.userPassword" placeholder="请输入密码..."
                  type="password"  />
      </el-form-item>
      <el-button type="primary" class="login-button" @click="handleLogin">登录</el-button>
    </el-form>
  </div>
</template>
<script setup>
import {ref} from 'vue'
import {Lock, User} from '@element-plus/icons-vue'
import axios, {request} from "axios";
import axiosUtil from '@/util/axios'
import {ElMessage} from "element-plus";
import router from "@/router";

const form = ref({
  userAccount: 'root2',
  userPassword: '12345678'
});

const rules = ref({
  userAccount: [
    {
      required: true,
      message: '请输入用户名',
      trigger: 'blur'
    }
  ],
  userPassword: [
    {
      required: true,
      message: '请输入密码',
      trigger: 'blur'
    }
  ]
})
const formRef = ref(null);

const handleLogin = () => {
  formRef.value.validate(async (valid) => {
    if (valid) {
      try {
        let result = await axiosUtil.post("user/login", form.value);
        let data = result.data;
        console.log(result)
        // const value = response.data;
        // // 在Vue中使用获取到的值
        // this.sessionValue = value;
        // console.log("宿舍楼靠近对方"+data.value)
        // console.log("爱上了对方骄傲"+JSON.stringify(data))
        if (data.code == 0) {
           // console.log(form.value)
          ElMessage.success("登录成功");
           window.sessionStorage.setItem("token",JSON.stringify(form.value));
          window.sessionStorage.setItem("USER_LOGIN_STATE", JSON.stringify(data.data));
          router.push('/home');
        } else {
          ElMessage.error(data.description);
        }
      } catch (err) {
        console.log("error:" + err);
        ElMessage.error("系统运行出错，请联系管理员");
      }
    }else {
      console.log("验证失败");
    }
  })
}
</script>
<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;
$cursor: #fff;
.login-container {
  min-height: 100%;
  width: 100%;
  background-color: #ece0e3;
  overflow: hidden;

  .login-form {
    box-shadow: 10px 10px 5px #888888;
    position: relative;
    background-color: #f8f3f4;
    width: 520px;
    border-radius: 20px;
 //   border: 1px solid red;
    max-width: 100%;
    padding: 40px 35px 40px;
    margin: 140px auto;
    overflow: hidden;

    ::v-deep .el-form-item {
      border: 1px solid rgba(255, 255, 255, 0.1);
      background: rgba(0, 0, 0, 0.1);
      border-radius: 5px;
      color: #454545;
    }

    ::v-deep .el-form-item__content {
      color: #454545;
      background: rgba(0, 0, 0, 0.1);
    }

    ::v-deep .el-input__wrapper {
      display: block;
      color: #9a9a9a;
      background: #fff;
      box-shadow: none;
    }

    ::v-deep .el-input {
      display: inline-block;
      background: #fff;
      height: 47px;
      width: 85%;

      input {
        background-color: #ffffff;
        border: 0px;
        -webkit-appearance: none;
        border-radius: 0px;
        padding: 12px 5px 12px 15px;
        color: #c8c4c5;
        height: 47px;
        caret-color: $cursor;
      }
    }

    .login-button {
      width: 100%;
      box-sizing: border-box;
      border-radius: 10px;
      border: 0px;
      background-color: #de868f;
    }
  }

  .tips {
    font-size: 16px;
    line-height: 28px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    display: inline-block;

  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: black;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }

    ::v-deep .lang-select {
      position: absolute;
      top: 4px;
      right: 0;
      background-color: white;
      font-size: 22px;
      padding: 4px;
      border-radius: 4px;
      cursor: pointer;
    }
  }

  .show-pwd {
    // position: absolute;
    // right: 10px;
    // top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>

<!--<template>-->

<!--</template>-->
<!--<style>-->

<!--</style>-->
<!--<script>-->
<!--const t=[]-->
<!--axios.post(url, {-->
<!--  参数名1: 参数值1,-->
<!--  参数名2: 参数值2-->
<!--}).then(res => {-->
<!--  // res.data就是我们的结果-->
<!--  // 注意可以进行链式调用-->
<!--  // 继续在括号后面.then或者.catch-->
<!--})-->
<!--</script>-->


<!--<template>-->
<!--  <table cellspacing="0px" cellpadding="10px">-->
<!--    <tr>-->
<!--      <td>openID</td>-->
<!--      <td>shopID</td>-->
<!--      <td>totalAmout</td>-->
<!--      <td>orderID</td>-->
<!--      <td>note</td>-->
<!--    </tr>-->
<!--    <tr v-for="book in books" :key="book.orderID">-->
<!--      <td>{{ book.openID }}</td>-->
<!--      <td>{{ book.shopID }}</td>-->
<!--      <td>{{ book.totalAmout }}</td>-->
<!--      <td>{{ book.orderID }}</td>-->
<!--      <td>{{ book.note }}</td>-->
<!--    </tr>-->
<!--  </table>-->
<!--  <a href="http://localhost:5657/alipay/pay?subject=我是⭐&traceNo=124&totalAmount=8888&alipayTraceNo=1000">xixi</a>-->
<!--</template>-->

<!--<script setup>-->
<!--import axios from 'axios'-->
<!--import {ref} from "vue";-->
<!--let books =ref([]);-->

<!--// axios.get(-->
<!--//     'http://localhost:5657/alipay/pay?subject=我是⭐&traceNo=124&totalAmount=8888&alipayTraceNo=1000')-->
<!--//-->
<!--//     .then(response => {-->
<!--//-->
<!--//-->
<!--//       console.log(response.data)-->
<!--//-->
<!--//     })-->
<!--//-->
<!--//     .catch(error => {-->
<!--//-->
<!--//       console.log(error)-->
<!--//-->
<!--//     })-->
<!--</script>-->
