<template>
  <div>
    <a-form-model
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
    >
      <a-form-model-item ref="name" label="姓名" prop="name">
        <a-input
          v-model="form.name"
          @blur="
            () => {
              $refs.name.onFieldBlur();
            }
          "
        />
      </a-form-model-item>
      <a-form-model-item label="证件类型" prop="card">
        <a-input v-model="form.card" :readonly="true" />
      </a-form-model-item>
      <a-form-model-item label="性别" prop="gender">
        <a-radio-group v-model="form.gender">
          <a-radio value="1"> 男 </a-radio>
          <a-radio value="2"> 女</a-radio>
        </a-radio-group>
      </a-form-model-item>
      <a-form-model-item label="生日日期" required prop="date">
        <a-date-picker
          v-model="form.date"
          show-time
          type="date"
          placeholder="选择生日"
          style="width: 100%"
        />
      </a-form-model-item>
      <a-form-model-item label="婚姻状况" prop="marriage">
        <a-radio-group v-model="form.gender">
          <a-radio value="1">未婚 </a-radio>
          <a-radio value="2">已婚</a-radio>
        </a-radio-group>
      </a-form-model-item>
      <a-form-model-item ref="name" label="联系电话" prop="phone">
        <a-input
          v-model="form.phone"
          @blur="
            () => {
              $refs.name.onFieldBlur();
            }
          "
        />
      </a-form-model-item>
      <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
        <a-button type="primary" @click="onSubmit">立即预约</a-button>
      </a-form-model-item>
    </a-form-model>
  </div>
</template>

<script>
export default {
  name: "self-form",
  components: {},
  data() {
    return {
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      other: "",
      form: {
        name: "",
        card: "身份证",
        date: undefined,
        gender: "1",
        marriage: "1",
        phone: "",
      },
      rules: {
        name: [
          {
            required: true,
            message: "请输入姓名",
            trigger: "blur",
          },
          {
            max: 5,
            message: "姓名长度不低于3",
            trigger: "blur",
          },
        ],
        phone: [
          {
            required: true,
            message: "请输入手机号吗",
            trigger: "blur",
          },
        ],

        date: [{ required: true, message: "请选择日期", trigger: "change" }],
      },
    };
  },
  computed: {},
  methods: {
    onSubmit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
::v-deep .ant-btn {
  position: relative;
  left: 100px;
  width: 120px;
}
::v-deep .ant-form-item-control {
  width: 360px;
}
</style>
