<template>
  <div class="login-container">
    <div class="login-form">

      <div class="title-container">
        <h3 class="title">
           供应商验证
        </h3>
        <div class="desc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
      </div>

      <el-tabs v-model="activeName" stretch>
        <el-tab-pane label="供应商登录" name="first">
          <el-form ref="loginForm" :model="loginForm" :rules="loginRules" autocomplete="on" label-position="left">
            <el-form-item prop="Username">
              <span class="svg-container">
                <svg-icon icon-class="user" />
              </span>
              <el-input
                  ref="Username"
                  v-model="loginForm.Username"
                  placeholder="供应商名称"
                  name="Username"
                  type="text"
                  tabindex="2"
                  autocomplete="on"
                  style="width: 85%"
              />
            </el-form-item>
            <el-tooltip  content="Caps lock is On" placement="right" manual>
              <el-form-item prop="Password">
                <span class="svg-container">
                  <svg-icon icon-class="password" />
                </span>
                <el-input
                    key="passwordType"
                    ref="Password"
                    v-model="loginForm.Password"
                    placeholder="供应商编码"
                    name="Password"
                    tabindex="3"
                    autocomplete="on"
                    style="width: 85%"
                />
              </el-form-item>
            </el-tooltip>
          </el-form>
        </el-tab-pane>
      </el-tabs>
      <div>
        <el-button v-if="loginType" :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="loginSubmit()">
          登录
        </el-button>

      </div>
<!--      <div class="forgotregister">-->
<!--        <router-link :to="{path: '/forgotpassword', query: { } }">-->
<!--          <span style="float: left">{{ $t('login.forgotPassword') }}</span>-->
<!--        </router-link>-->

<!--      </div>-->
    </div>
    <div class="globalFooter">
      <div class="copyright">Copyright &copy;2022 珠海格致软件有限公司</div>
    </div>
  </div>
</template>

<script>

import {login} from "@/api/login";
import * as auth from "@/utils/auth.js"
import {getToken} from "@/utils/auth.js";
import axios from "axios";

export default {
  name: 'Login',
  data() {
    return {
      loading : false,
      activeName:'first',
      loginType:false,
      FBILLNO:'',
      loginForm:{
        Username:"",
        Password:"",
      },
      loginRules: {
        Username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        Password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      data:{
        FormId:"kafe2f22a0498441f9109c31cf5586da5",
        FieldKeys:"FBILLNO,FSupplierId.FName",
        FilterString:"",
        OrderString:"",
        TopRowCount:"0",
        StartRow:"0",
        Limit:100
      }
    }
  },
  watch: {

  },
  created() {
    this.FBILLNO=this.$route.query.FBILLNO
    if (this.$route.query.FBILLNO !== undefined){
      this.loginType=true;
    }
  },
  mounted() {

  },
  destroyed() {

  },
  methods: {
    loginSubmit(){
       let this_=this
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          let FilterString="FBILLNO like'%"+this.FBILLNO+"'";
          this.data.FilterString=FilterString;
          let query={}
          query.FBILLNO=this.FBILLNO;
          query.Username=this.loginForm.Username;
          query.Password=this.loginForm.Password;
          login(query).then((response) => {
            if (response.status===200){
              this.$router.push({
                path: "/master?FBILLNO="+this_.FBILLNO+"&username="+this_.loginForm.Username+"&password="+this_.loginForm.Password,
              });
            }else {
              this.handleWarning("登录失败，请联系管理员")
            }
          });
        }
      })

    },
    handleWarning(response) {
      this.$message({
        message: response.message || response,
        type: 'warning',
        duration: 2000
      })
    },

    handleSuccess(response) {
      this.$message({
        message: response.message || response,
        type: 'success',
        duration: 2000
      })
    }
  }
}
</script>

<style lang="scss">

$bg:#283443;
$light_gray:#fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    // width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      color: $light_gray;
      height: 47px;
      caret-color: $cursor;

      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }

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

<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

::v-deep .el-tabs__item {
  color: white;
}

::v-deep .el-tabs__item.is-active {
  color: #1890ff;
}

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;

  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 160px 35px 0;
    margin: 0 auto;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    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;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

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

    .desc {
      margin-top: 0px;
      margin-bottom: 20px;
      color: white;
      font-size: 14px;
    }

    .set-language {
      color: #fff;
      position: absolute;
      top: 3px;
      font-size: 18px;
      right: 0px;
      cursor: pointer;
    }
  }

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

.globalFooter {
  margin: 48px 0 24px 0;
  padding: 0 16px;
  text-align: center;

  .links {
    margin-bottom: 8px;
  }

  .copyright {
    color: rgba(0,0,0,0.45);
    font-size: 14px;
  }
}

.forgotregister {
  text-align: right;
  font-size: 14px;
  color: white;

  .register {
    float: right;
  }
}
</style>
