<template>
  <view class="loginBox">
    <view class="logo-content">
      <img :src="globalConfig" alt="" class="logo" style="width: 250rpx" />
    </view>
    <u-form
      :model="userform"
      :rules="userRules"
      class="loginForm"
      ref="loginForm"
    >
      <u-form-item prop="loginCode" ref="item1" :borderBottom="true">
        <u--input
          v-model="userform.loginCode"
          :border="'none'"
          :placeholder="'请输入账号'"
          prefixIcon="account"
          prefixIconStyle="font-size: 22px;color: #909399"
        ></u--input>
      </u-form-item>
      <u-form-item prop="loginPwd" ref="item1" :borderBottom="true">
        <u--input
          v-model="userform.loginPwd"
          :border="'none'"
          prefixIcon="lock"
          :placeholder="'请输入密码'"
          password
          prefixIconStyle="font-size: 22px;color: #909399"
        ></u--input>
      </u-form-item>
    </u-form>
    <view class="btn">
      <u-button
        text="认证"
        size="normal"
        type="primary"
        @click="handlerSubmit"
      ></u-button>
    </view>
    <u-toast ref="uToast"></u-toast>
  </view>
</template>

<script>
import { authApi } from "@/api/login";
import logo from "@/static/logo1.png";
import localStorage from "@/utils/localStorage";
export default {
  data() {
    return {
      globalConfig: logo,
      userform: {
        loginCode: "",
        loginPwd: "",
      },
      userRules: {
        loginCode: [
          {
            required: true,
            message: "请输入账号",
            trigger: ["change", "blur"],
          },
        ],
        loginPwd: [
          {
            required: true,
            message: "请输入密码",
            trigger: ["change", "blur"],
          },
        ],
      },
      userid: "",
    };
  },
  onReady() {
    this.$ddFunction.setTitle("钉钉免登录认证");
  },
  methods: {
    handlerSubmit() {
      this.$refs.loginForm
        .validate()
        .then((res) => {
          let params = {
            loginCode: this.userform.loginCode,
            password: this.userform.loginPwd,
            ddUserId: localStorage.get("MIDDLEGROUND-USERID"),
          };
          this.submit(params);
        })
        .catch((errors) => {});
    },
    async submit(params) {
      let res = await authApi(
        "loginService",
        "sysTestjdbc",
        "doLogin",
        "",
        params
      );
      if (res.status === "200") {
        this.$refs.uToast.show({
          type: "success",
          message: "认证成功！",
        });
        setTimeout(() => {
          localStorage.set("MIDDLEGROUND-TOKEN", res.attribute.token);
          localStorage.set("MIDDLEGROUND-USERINFO", res.attribute.userInfo);
          uni.switchTab({
            url: "/pages/homePage/index",
          });
        }, 1000);
      }
    },
  },
};
</script>

<style scoped lang="scss">
.logo-content {
  background: #c73b26;
  border-radius: 10px;
  padding: 15px;
  display: flex;
  align-items: center;
  width: 310rpx;
  text-align: center;
  margin: auto;
  
}
.loginBox {
  background: #ffffff;
  padding-top: 20%;
  .loginForm {
    padding: 70rpx 80rpx;
  }
  .btn {
    padding: 30rpx 80rpx;
  }
}
</style>
<style scoped>
page {
  background: #fff;
}
</style>