<script setup>
import { ref } from 'vue';
import { ElInput, ElButton, ElForm, ElFormItem, ElMessage } from 'element-plus';
import 'element-plus/dist/index.css';

const companyName = ref('');
const contactInfo = ref('');
const password = ref('');
const verificationCode = ref('');

const handleRegister = () => {
  console.log('Registering with', { companyName: companyName.value, contactInfo: contactInfo.value, password: password.value, verificationCode: verificationCode.value });
  // 处理注册逻辑
};

const sendVerificationCode = () => {
  ElMessage.success('验证码已发送');
  // 处理发送验证码逻辑
};
</script>

<template>
  <div class="register-container">
    <div class="register-box">
      <h2>企业租户注册</h2>
      <ElForm @submit.prevent="handleRegister">
        <ElFormItem>
          <label for="companyName">企业名称</label>
          <ElInput v-model="companyName" type="text" id="companyName" placeholder="请输入企业名称" required />
        </ElFormItem>
        <ElFormItem>
          <label for="contactInfo">企业联系方式</label>
          <ElInput v-model="contactInfo" type="text" id="contactInfo" placeholder="请输入企业联系方式" required />
        </ElFormItem>
        <ElFormItem>
          <label for="password">密码</label>
          <ElInput v-model="password" type="password" id="password" placeholder="请输入密码" required />
        </ElFormItem>
        <ElFormItem>
          <label for="verificationCode">验证码</label>
          <ElInput v-model="verificationCode" type="text" id="verificationCode" placeholder="请输入验证码" required>
            <template #append>
              <ElButton type="primary" @click="sendVerificationCode" class="verification-button">获取验证码</ElButton>
            </template>
          </ElInput>
        </ElFormItem>
        <ElFormItem>
          <ElButton type="primary" native-type="submit" class="register-button">注册</ElButton>
        </ElFormItem>
        <ElFormItem>
          <ElButton type="text" @click="() => $router.push('/login')">返回登录</ElButton>
        </ElFormItem>
      </ElForm>
    </div>
  </div>
</template>

<style scoped>
.register-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: url('background.jpg') no-repeat center center;
  background-size: cover;
}

.register-box {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  text-align: center;
  width: 20%;
}

h2 {
  margin-bottom: 1rem;
}

.el-form-item {
  margin-bottom: 1rem;
  text-align: left;
}

.el-form-item label {
  display: block;
  margin-bottom: 0.5rem;
}

.el-input {
  width: 100%;
}

.verification-button {
  width: 120px; /* 确保按钮宽度合适 */
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0; /* 去除默认内边距 */
}

.el-button {
  width: 100%;
  padding: 0.75rem;
}

.el-button--primary {
  background-color: #007bff;
  color: white;
}

.el-button--primary:hover {
  background-color: #0056b3;
}
</style>
