<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
        <cHead :siteInfo="siteInfo"></cHead>
        <el-col :span="24" class="two">
          <div class="logo">
            <el-image class="image" src="/src/assets/login.jpeg" fit="fill" />
          </div>
          <div class="loginform">
            <el-col :span="24" class="tab">
              <el-col :span="5" class="title" @click="toTab(0)" :class="[activeName == '0' ? 'tab0' : 'tab1']">个人用户</el-col>
              <el-col :span="5" class="title" @click="toTab(1)" :class="[activeName == '1' ? 'tab0' : 'tab1']">企业用户</el-col>
              <el-col :span="5" class="title" @click="toTab(2)" :class="[activeName == '2' ? 'tab0' : 'tab1']">科研单位</el-col>
            </el-col>
            <el-col :span="24" class="content" v-show="activeName == '0'">
              <el-form ref="ruleFormRef" :model="form" :rules="rules" label-width="80px" class="form" label-position="left">
                <el-form-item label="账号" prop="account">
                  <el-input v-model="form.account" placeholder="请输入账号">
                    <template #prefix>
                      <el-icon><User /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="用户名" prop="nick_name">
                  <el-input v-model="form.nick_name" placeholder="请输入用户名">
                    <template #prefix>
                      <el-icon><Avatar /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="工作单位" prop="unit">
                  <el-input v-model="form.tel" placeholder="请输入工作单位">
                    <template #prefix>
                      <el-icon><OfficeBuilding /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="联系电话" prop="tel">
                  <el-input v-model="form.tel" placeholder="请输入联系电话">
                    <template #prefix>
                      <el-icon><Iphone /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="身份证号" prop="id_card">
                  <el-input v-model="form.id_card" placeholder="请输入身份证号">
                    <template #prefix>
                      <el-icon><ScaleToOriginal /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="联系邮箱" prop="email">
                  <el-input v-model="form.email" placeholder="请输入联系邮箱">
                    <template #prefix>
                      <el-icon><Message /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                  <el-input v-model="form.password" type="password" show-password placeholder="请输入登录密码">
                    <template #prefix>
                      <el-icon><Unlock /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="确认密码" prop="refpassword">
                  <el-input v-model="form.refpassword" type="password" show-password placeholder="请再次确认输入密码">
                    <template #prefix>
                      <el-icon><Unlock /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-col :span="24" class="remark">
                  <span @click="toLogin">已有账号去登录</span>
                  <span @click="toBack">返回首页</span>
                </el-col>
                <el-col :span="24" class="button">
                  <el-button type="primary" @click="submitForm(ruleFormRef)">注册</el-button>
                </el-col>
                <el-col :span="24" class="agree">
                  <el-checkbox v-model="isAgree"></el-checkbox>
                  <span style="margin: 0 0 0 5px">我已阅读并同意</span><span @click="toRegister">《{{ siteInfo.zhTitle }}使用协议》</span>
                </el-col>
              </el-form>
            </el-col>
            <el-col :span="24" class="content" v-show="activeName == '1'">
              <el-form ref="ruleFormRef" :model="form" :rules="rules" label-width="80px" class="form" label-position="left">
                <el-form-item label="账号" prop="account">
                  <el-input v-model="form.account" placeholder="请输入账号">
                    <template #prefix>
                      <el-icon><User /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="用户名" prop="nick_name">
                  <el-input v-model="form.nick_name" placeholder="请输入用户名">
                    <template #prefix>
                      <el-icon><Avatar /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="工作单位" prop="unit">
                  <el-input v-model="form.tel" placeholder="请输入工作单位">
                    <template #prefix>
                      <el-icon><OfficeBuilding /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="联系电话" prop="tel">
                  <el-input v-model="form.tel" placeholder="请输入联系电话">
                    <template #prefix>
                      <el-icon><Iphone /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="身份证号" prop="id_card">
                  <el-input v-model="form.id_card" placeholder="请输入身份证号">
                    <template #prefix>
                      <el-icon><ScaleToOriginal /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="联系邮箱" prop="email">
                  <el-input v-model="form.email" placeholder="请输入联系邮箱">
                    <template #prefix>
                      <el-icon><Message /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                  <el-input v-model="form.password" type="password" show-password placeholder="请输入登录密码">
                    <template #prefix>
                      <el-icon><Unlock /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="确认密码" prop="refpassword">
                  <el-input v-model="form.refpassword" type="password" show-password placeholder="请再次确认输入密码">
                    <template #prefix>
                      <el-icon><Unlock /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-col :span="24" class="remark">
                  <span @click="toLogin">已有账号去登录</span>
                  <span @click="toBack">返回首页</span>
                </el-col>
                <el-col :span="24" class="button">
                  <el-button type="primary" @click="submitForm(ruleFormRef)">注册</el-button>
                </el-col>
                <el-col :span="24" class="agree">
                  <el-checkbox v-model="isAgree"></el-checkbox>
                  <span style="margin: 0 0 0 5px">我已阅读并同意</span><span @click="toRegister">《{{ siteInfo.zhTitle }}使用协议》</span>
                </el-col>
              </el-form>
            </el-col>
            <el-col :span="24" class="content" v-show="activeName == '2'">
              <el-form ref="ruleFormRef" :model="form" :rules="rules" label-width="80px" class="form" label-position="left">
                <el-form-item label="账号" prop="account">
                  <el-input v-model="form.account" placeholder="请输入账号">
                    <template #prefix>
                      <el-icon><User /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="用户名" prop="nick_name">
                  <el-input v-model="form.nick_name" placeholder="请输入用户名">
                    <template #prefix>
                      <el-icon><Avatar /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="工作单位" prop="unit">
                  <el-input v-model="form.tel" placeholder="请输入工作单位">
                    <template #prefix>
                      <el-icon><OfficeBuilding /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="联系电话" prop="tel">
                  <el-input v-model="form.tel" placeholder="请输入联系电话">
                    <template #prefix>
                      <el-icon><Iphone /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="身份证号" prop="id_card">
                  <el-input v-model="form.id_card" placeholder="请输入身份证号">
                    <template #prefix>
                      <el-icon><ScaleToOriginal /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="联系邮箱" prop="email">
                  <el-input v-model="form.email" placeholder="请输入联系邮箱">
                    <template #prefix>
                      <el-icon><Message /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                  <el-input v-model="form.password" type="password" show-password placeholder="请输入登录密码">
                    <template #prefix>
                      <el-icon><Unlock /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-form-item label="确认密码" prop="refpassword">
                  <el-input v-model="form.refpassword" type="password" show-password placeholder="请再次确认输入密码">
                    <template #prefix>
                      <el-icon><Unlock /></el-icon>
                    </template>
                  </el-input>
                </el-form-item>
                <el-col :span="24" class="remark">
                  <span @click="toLogin">已有账号去登录</span>
                  <span @click="toBack">返回首页</span>
                </el-col>
                <el-col :span="24" class="button">
                  <el-button type="primary" @click="submitForm(ruleFormRef)">注册</el-button>
                </el-col>
                <el-col :span="24" class="agree">
                  <el-checkbox v-model="isAgree"></el-checkbox>
                  <span style="margin: 0 0 0 5px">我已阅读并同意</span><span @click="toRegister">《{{ siteInfo.zhTitle }}使用协议》</span>
                </el-col>
              </el-form>
            </el-col>
          </div>
        </el-col>
        <cFoot></cFoot>
      </el-col>
    </el-row>
  </div>
</template>
<script setup lang="ts">
// 基础
import type { Ref } from 'vue';
import { onMounted, ref, reactive } from 'vue';
import type { FormInstance, FormRules } from 'element-plus';
import { useRouter } from 'vue-router';
import { siteInfo } from '@/layout/site';
// // 接口
// import { ToolsStore } from '@/stores/tool';
// import type { IQueryResult } from '@/util/types.util';
// const toolsAxios = ToolsStore();
// 路由
const router = useRouter();
// 加载中
const loading: Ref<any> = ref(false);
const form: Ref<any> = ref({});
interface RuleForm {
  account: string;
  password: string;
}
const ruleFormRef = ref<FormInstance>();
const rules = reactive<FormRules<RuleForm>>({
  account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
  password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
});
const activeName: Ref<any> = ref(0);
const isAgree: Ref<any> = ref(false);
// 请求
onMounted(async () => {
  loading.value = true;
  search();
  loading.value = false;
});
const search = async () => {
  // let res: IQueryResult = await toolsAxios.dataCount();
  // if (res.errcode == '0') {
  //     info.value = res.data;
  // }
};
// 选择
const toTab = async (active) => {
  activeName.value = active;
};
// 注册
const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!');
    } else {
      console.log('error submit!', fields);
    }
  });
};
// 去登录
const toLogin = () => {
  router.push({ path: '/login', query: { status: '0' } });
};
// 返回
const toBack = () => {
  router.push({ path: '/home' });
};
</script>
<style scoped lang="scss">
.main {
  .two {
    background-image: url(/src/assets/loginbg.jpg);
    background-position: center center;
    background-repeat: no-repeat;
    height: 500px;
    width: 100%;
    background-size: cover;
    display: flex;
    justify-content: space-evenly;
    .logo {
      margin: 50px 0px 0px 0;
      height: 420px;
      opacity: 0.8;
      .image {
        width: 100%;
        height: 100%;
      }
    }
    .loginform {
      margin: 50px 0 0 0;
      padding: 20px 0 0 0;
      width: 380px;
      height: 422px;
      background-color: #ffffff;
      border-radius: 3px;
      .tab {
        display: flex;
        align-items: center;
        justify-content: center;
        .title {
          text-align: center;
          margin: 0 20px;
          font-family: PingFangSC-Semibold !important;
          font-size: 15px;
          letter-spacing: -0.14px;
          line-height: 30px;
          font-weight: bold;
        }
        .tab0 {
          color: #1492ff;
          border-bottom: 2px solid;
          border-bottom-color: #1492ff;
          padding-bottom: 10px;
        }
        .tab1 {
          color: #333333;
          padding-bottom: 10px;
        }
      }

      .content {
        margin: 30px 30px 0 30px;
        height: 310px;
        overflow-y: auto;
        .remark {
          display: flex;
          justify-content: space-between;
          span {
            cursor: pointer;
            font-family: PingFangSC-Regular;
            font-size: 14px;
            color: #333333;
            letter-spacing: -0.09px;
            text-align: right;
            line-height: 32px;
          }
          span:hover {
            color: #2374ff;
          }
        }
        .button {
          padding: 10px 0;
          :deep(.el-button) {
            width: 318px !important;
            height: 44px !important;
            border: 0 !important;
            color: #f8f8f8 !important;
            font-size: 16px !important;
            text-align: center !important;
            line-height: 40px !important;
            cursor: pointer !important;
            font-family: PingFangSC-Regular !important;
            background-color: #1492ff !important;
          }
        }
        .agree {
          padding: 0 0 40px 0;
          color: #999;
          font-size: 12px;
          span:last-child {
            color: #2374ff;
          }
        }
      }
      .content::-webkit-scrollbar {
        display: none;
      }
    }
  }
}
</style>
