<!-- 搜索表单 -->
<template>
    <simple-form-modal
        :title="title"
        :items="formItems"
        ref="editRef"
        :baseUrl="baseUrl"
        label-width="120px"
        @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: 'username',
                required: true
            },
            {
                type: 'input',
                label: '联系方式',
                prop: 'mobile',
                required: true,
                rules: [
                    { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号' }
                ]
            },
            {
                type: 'dictSelect',
                label: '加入黑名单原因',
                prop: 'reason',
                required: true,
                props: {
                    code: 'school_tag'
                }
            },
            {
                type: 'textarea',
                label: '备注',
                prop: 'reason',
                required: true
            }
        ];
    });
    //默认值
    const baseUrl = reactive({
        add: '/baseinfo/schoolInfo/save',
        update: '/baseinfo/schoolInfo/edit'
    });
    const formData = ref({ schoolTag: '1' });

    const editRef = ref(null);

    const title = ref('添加黑名单');
    function handleOpen(data = {}) {
        title.value = data.id ? '编辑黑名单' : '添加黑名单';
        formData.value = Object.assign(formData.value, data || {});
        editRef.value?.handleOpen(formData.value);
    }

    defineExpose({ handleOpen });
</script>
