<!-- 搜索表单 -->
<template>
    <simple-form-modal
        :title="title"
        :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 provinceList = ref([]);
    const cityList = ref([]);
    const title = ref('新增');
    const emit = defineEmits(['success']);

    const formItems = computed(() => {
        return [
            {
                type: 'input',
                label: '服务名称',
                prop: 'name',
                required: true
            },
            {
                type: 'textarea',
                label: '服务内容',
                prop: 'content',
                required: true
            },
            {
                type: 'switch',
                label: '前台展示',
                prop: 'optimizationType',
                props: { code: 'optimization_type' },
                required: true
            },
            {
                type: 'dictRadio',
                label: '状态',
                prop: 'status',
                props: { code: 'sys_normal_disable' },
                required: true
            }
        ];
    });
    //默认值
    const baseUrl = reactive({
        add: '/baseinfo/schoolInfo/save',
        update: '/baseinfo/schoolInfo/edit'
    });
    const formData = ref({ schoolTag: '1' });

    const editRef = ref(null);

    function handleOpen(data = {}) {
        title.value = data && data.id ? '编辑服务' : '新增服务';
        formData.value = Object.assign(formData.value, data || {});
        editRef.value?.handleOpen(formData.value);
    }

    defineExpose({ handleOpen });
</script>
