<!-- 搜索表单 -->
<template>
    <simple-form-modal
        :title="title"
        width="420"
        :items="formItems"
        ref="editRef"
        :baseUrl="baseUrl"
        @success="(data) => emit('success', data)"
    />
</template>

<script setup>
    import { reactive, ref, defineEmits, getCurrentInstance } from 'vue';
    import { useFormData } from '@/utils/use-form-data';
    import SimpleFormModal from '@/components/CommonPage/SimpleFormModal.vue';
    const { proxy } = getCurrentInstance();

    const emit = defineEmits(['success']);

    const formItems = computed(() => {
        return [
            {
                type: 'input',
                label: '标签名称',
                prop: 'tagName',
                required: true
            }
        ];
    });
    //默认值
    const baseUrl = reactive({
        add: '/user/tag/add',
        update: '/user/tag/update'
    });
    const formData = ref({});

    const editRef = ref(null);
    const title = ref('添加标签');
    function handleOpen(data) {
        title.value = data && data.id ? '编辑标签' : '添加标签';
        formData.value = { ...(data || {}) };
        editRef.value?.handleOpen(formData.value);
    }

    defineExpose({ handleOpen });
</script>
