<template>
  <div class="login">
    <div class="login-form">
      <div>
        <h3 class="title">专家库管理集约化平台</h3>
        <h4 class="title">{{ wbjName }} - 专家</h4>
      </div>
      <div>
        <div class="unified-href">
          <el-button type="primary" @click="sendGotoUrlToBack">专家登录</el-button>
          <el-button type="primary" @click="gotoRegister">专家注册</el-button>
        </div>
      </div>
    </div>
    <!--  底部  -->
    <div class="el-login-footer">
      <span>技术支持：山西云时代技术有限公司</span>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { useUserStore } from '@/store/modules/user';
import { UNIFIED_AUTHENTICATION_REGISTER } from '@/config';

const userStore = useUserStore();
const route = useRoute();
const tenantList = computed(() => userStore.tenantList);
const wbjKey = computed(() => route.params.wbjKey);
const wbjName = computed(() => {
  let item = tenantList.value.find((item) => item.domain === wbjKey.value);
  return item?.companyName || '';
});

const sendGotoUrlToBack = async () => {
  await userStore.sendGotoUrlToBack();
};
const gotoRegister = () => {
  location.href = UNIFIED_AUTHENTICATION_REGISTER;
};
watch(
  wbjKey,
  (n: string) => {
    if (!n) {
      localStorage.setItem('wbjKey', '');
      return;
    }
    localStorage.setItem('wbjKey', n);
  },
  {
    deep: true,
    immediate: true
  }
);
</script>

<style lang="scss" scoped>
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url('@/assets/images/login-background.jpg');
  background-size: cover;
}

.title {
  margin: 0 auto 30px auto;
  text-align: center;
  color: #707070;
}

.login-form {
  border-radius: 6px;
  background: #ffffff;
  width: 400px;
  padding: 25px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial, serif;
  font-size: 12px;
  letter-spacing: 1px;
}

.unified-href {
  width: 100%;

  :deep(.el-button) {
    width: 100%;
    display: block;
    margin: 10px 0 0;
  }
}

h3 {
  font-weight: bold;
}
</style>
