<!-- 搜索表单 -->
<template>
    <simple-form-modal
        :title="title"
        :items="formItems"
        ref="editRef"
        :baseUrl="baseUrl"
        @success="(data) => emit('success', data)"
        labelWidth="120px"
    />
</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 title = ref('新增提醒书籍');
    const emit = defineEmits(['success']);

    const formItems = computed(() => {
        return [
            { type: 'input', label: 'ISBN', prop: 'isbn', required: true },
            {
                type: 'select',
                label: '需要提醒的仓库',
                prop: 'godownId',
                required: true,
                props: {
                    filterable: true
                },
                options: godownList.value
                    .filter((v) => v.useStatus == 1)
                    .map((d) => {
                        return { label: d.godownName, value: d.id };
                    })
            }
        ];
    });
    const godownList = ref([]);
    async function getGodownList() {
        return proxy.$http.post('/baseinfo/godown/searchGodown?name=');
    }

    //默认值
    const baseUrl = reactive({
        add: '/book/checkWarn/addCheckWarnBook'
    });
    const formData = ref({});
    const editRef = ref(null);

    function handleOpen(data = {}) {
        title.value = data && data.id ? '编辑提醒书籍' : '新增提醒书籍';
        formData.value = Object.assign(formData.value, data || {});
        editRef.value?.handleOpen(formData.value);
        getGodownList().then((res) => {
            if (res.data.code == 200) {
                godownList.value = res.data.data;
            }
        });
    }

    defineExpose({ handleOpen });
</script>
