<script lang="ts" setup>
import { Page } from '@vben/common-ui';
import { reactive, ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import type { FormInstance, FormRules } from 'element-plus';
const router = useRouter();
const route = useRoute();
const ruleFormRef = ref<FormInstance>();
const examinformation = {
  ExamName: '考试名称 1',
  TotalExamScore: '100',
  Passingscore: '60',
  Examduration: '30分钟',
  ExamInstructions: '这是考试说明',
};
const ruleForm = reactive({
  username: '',
  mobilenumber: '',
});

const rules = reactive<FormRules<typeof ruleForm>>({
  username: [
    {
      required: true,
      message: '姓名不能为空！',
      trigger: 'change',
    },
  ],
  mobilenumber: [
    {
      required: true,
      message: '手机号不能为空！',
      trigger: 'change',
    },
  ],
});

const submitForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.validate((valid) => {
    if (valid) {
      router.replace({
        path: '/startexamin',
      });
    } else {
      console.log('error submit!');
    }
  });
};
</script>
<template>
  <Page>
    <div style="display: flex; flex-direction: column; align-items: center">
      <div class="title">欢迎进入联合汇能考试中心</div>
      <div class="examinformation">
        <div class="examinformation_item">
          <div class="examinformation_item_left">考试名称</div>
          <div class="examinformation_item_right">
            {{ examinformation.ExamName }}
          </div>
        </div>
        <div class="examinformation_item">
          <div class="examinformation_item_left">考试总分</div>
          <div class="examinformation_item_right">
            {{ examinformation.TotalExamScore }}
          </div>
        </div>
        <div class="examinformation_item">
          <div class="examinformation_item_left">及格分数</div>
          <div class="examinformation_item_right">
            {{ examinformation.Passingscore }}
          </div>
        </div>
        <div class="examinformation_item">
          <div class="examinformation_item_left">考试时长</div>
          <div class="examinformation_item_right">
            {{ examinformation.Examduration }}
          </div>
        </div>
        <div class="examinformation_item">
          <div class="examinformation_item_left">考试说明</div>
          <div class="examinformation_item_right">
            {{ examinformation.ExamInstructions }}
          </div>
        </div>
      </div>
      <div class="examinformation_content">
        <el-form
          ref="ruleFormRef"
          style="width: 400px"
          :model="ruleForm"
          status-icon
          :rules="rules"
          label-width="auto"
          class="demo-ruleForm"
        >
          <el-form-item label="姓名" prop="username">
            <el-input v-model="ruleForm.username" autocomplete="off" />
          </el-form-item>
          <el-form-item label="手机号" prop="mobilenumber">
            <el-input v-model="ruleForm.mobilenumber" autocomplete="off" />
          </el-form-item>
          <el-form-item>
            <el-button
              style="margin: 0 auto; width: 160px; height: 40px"
              type="primary"
              @click="submitForm(ruleFormRef)"
            >
              开 始 考 试
            </el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </Page>
</template>
<style lang="scss" scoped>
.title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 48px;
}
.examinformation {
  width: 100%;
  height: 180px;
  border: 1px solid #d4d6d9;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .examinformation_item {
    flex: 1;
    border-bottom: 1px solid #d4d6d9;
    display: flex;
    justify-content: space-between;
    color: #31373d;
    font-size: 14px;
    .examinformation_item_left {
      background-color: #f2f3f5;
      width: 240px;
      font-weight: 500;
      display: flex;
      align-items: center;
      justify-content: end;
      box-sizing: border-box;
      padding-right: 16px;
    }
    .examinformation_item_right {
      border-left: 1px solid #d4d6d9;
      flex: 1;
      font-weight: 400;
      display: flex;
      align-items: center;
      box-sizing: border-box;
      padding-left: 16px;
    }
    &:last-child {
      border-bottom: none;
    }
  }
}
.examinformation_content {
  margin-top: 129px;
  //   border: 1px solid red;
  // display: flex;
  //   width: 352px;
  //   height: 40px;
  //   display: flex;
  //   justify-content: space-between;
  //   gap: 32px;
  //   margin: 24px auto;
}
</style>
