<!-- 搜索表单 -->
<template>
    <ele-card :body-style="{ paddingBottom: '8px' }">
        <ProSearch
            :items="formItems"
            ref="searchRef"
            @search="search"
            :initKeys="initKeys"
        />
    </ele-card>
</template>

<script setup>
    import { reactive, ref, defineEmits } from 'vue';
    import ProSearch from '@/components/CommonPage/ProSearch2.vue';

    let { proxy } = getCurrentInstance();
    const emit = defineEmits(['search']);
    const godownList = ref([]);
    const formItems = computed(() => {
        return [
            {
                type: 'select',
                label: '仓库名称',
                prop: 'godownId',
                options: godownList.value.map((d) => {
                    return { label: d.godownName, value: d.id };
                }),
                props: {
                    placeholder: '请选择或输入搜索',
                    filterable: true
                }
            },
            { type: 'input', label: '库位编码', prop: 'code' },
            {
                type: 'dictSelect',
                label: '状态',
                prop: 'useStatus',
                props: {
                    code: 'use_status'
                }
            }
        ];
    });

    function getStoreList(name = '') {
        return proxy.$http.post(`/baseinfo/godown/searchGodown?name=${name}`);
    }
    getStoreList().then((res) => {
        godownList.value = res.data.data;
    });

    const initKeys = reactive({
        godownId: '',
        useStatus: '',
        code: ''
    });

    const searchRef = ref(null);
    /** 搜索 */
    const search = (data) => {
        emit('search', { ...data });
    };
</script>
