<template>
  <div class="login-page">
    <div class="login-card">
      <h2>家属注册</h2>
      <el-form :model="form" label-position="top">
        <el-form-item label="账号">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password" type="password"></el-input>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="form.phone"></el-input>
        </el-form-item>
        <el-form-item label="亲属身份证号">
          <el-input v-model="form.elderIdCard"></el-input>
        </el-form-item>
        <el-form-item label="关系">
          <el-input v-model="form.relationship" placeholder="如：儿子/女儿/配偶"></el-input>
        </el-form-item>
        <el-button type="primary" style="width: 100%;" @click="handleRegister">注册</el-button>
      </el-form>
      <div class="login-footer">
        <el-button type="text" @click="$router.push('/login')">返回登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { register } from "../api";

export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
        name: "",
        phone: "",
        elderIdCard: "",
        relationship: ""
      }
    };
  },
  methods: {
    async handleRegister() {
      try {
        await register(this.form);
        this.$message.success("注册成功");
        this.$router.push("/login");
      } catch (e) {
        this.$message.error(e.message || "注册失败");
      }
    }
  }
};
</script>

<style scoped>
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #dff3e7, #f3f8f3);
}
.login-card {
  width: 420px;
  padding: 28px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.12);
}
.login-footer {
  margin-top: 12px;
  text-align: center;
}
</style>


