<template>
  <a-form :label-col="{ span: 4 }" :wrapper-col="{ span: 14 }" >
    <a-form-item label="支付宝域名配置" v-bind="validateInfos.name">
      <a-input v-model:value="modelRef.name" />
    </a-form-item>
    <a-form-item label="微信域名配置" v-bind="validateInfos['sub.name']">
      <a-input v-model:value="modelRef.sub.name" />
    </a-form-item>
    <a-form-item :wrapper-col="{ span: 14, offset: 4 }">
      <a-button type="primary" @click.prevent="onSubmit">提交</a-button>
      <a-button style="margin-left: 10px" @click="reset">重置</a-button>
    </a-form-item>
  </a-form>
</template>
<script lang="ts" setup>
import { defineExpose, reactive, toRaw } from "vue";
import { Form } from "ant-design-vue";
import { onCreaterealmName } from "@/api/index";
const useForm = Form.useForm;

    const modelRef = reactive({
      name: "",
      sub: {
        name: "",
      },
    });
    const { resetFields, validate, validateInfos } = useForm(
      modelRef,
      reactive({
        name: [
          {
            required: true,
            message: "Please input name",
          },
        ],
        "sub.name": [
          {
            required: true,
            message: "Please input sub name",
          },
        ],
      })
    );
    const onSubmit = async() => {
      validate()
        .then((res) => {
          
          console.log(res, toRaw(modelRef));
          const data = await onCreaterealmName(toRaw(modelRef))
          console.log(data,'data');
          
        })
        .catch((err) => {
          console.log("error", err);
        });
    };
    const reset = () => {
      resetFields();
    };
    defineExpose({
      validateInfos,
      reset,
      modelRef,
      onSubmit,
    });

</script>
<style>
.dynamic-delete-button {
  cursor: pointer;
  position: relative;
  top: 4px;
  font-size: 24px;
  color: #999;
  transition: all 0.3s;
}
.dynamic-delete-button:hover {
  color: #777;
}
.dynamic-delete-button[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}
</style>
<style scoped lang="less">
.addform {
}
</style>
