<!-- 搜索表单 -->
<template>
    <ele-card :body-style="{ paddingBottom: '8px' }">
        <ProSearch
            :items="formItems"
            ref="searchRef"
            @search="search"
            :offset="1"
        />
    </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: 'daterange',
                label: '日期',
                prop: 'time',
                props: {
                    format: 'YYYY-MM-DD',
                    valueFormat: 'YYYY-MM-DD',
                    onChange: (value) => {
                        searchRef.value?.setData({
                            statisticDateStart: value ? value[0] : '',
                            statisticDateEnd: value ? value[1] : ''
                        });
                    }
                },
                colProps: {
                    span: 6
                }
            },
            {
                type: 'select',
                label: '仓库名称',
                prop: 'godownId',
                options: godownList.value.map((d) => {
                    return { label: d.godownName, value: d.id };
                }),
                props: {
                    placeholder: '请选择或输入搜索',
                    filterable: true
                }
            }
        ];
    });

    const initKeys = reactive({
        statisticDateStart: '',
        statisticDateEnd: '',
        godownId: ''
    });

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

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