<!-- 搜索表单 -->
<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: 'input', label: '关键字', prop: 'areaInfoLike' },
            {
                type: 'datetimerange',
                label: '添加时间',
                prop: 'time',
                props: {
                    format: 'YYYY-MM-DD HH:mm:ss',
                    valueFormat: 'YYYY-MM-DD HH:mm:ss',
                    onChange: (value) => {
                        searchRef.value?.setData({
                            createTimeStart: value ? value[0] : '',
                            createTimeEnd: value ? value[1] : ''
                        });
                    }
                },
                colProps: {
                    span: 6
                }
            }
        ];
    });

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

    const initKeys = reactive({
        createTimeStart: '',
        createTimeEnd: '',
        areaInfoLike: ''
    });

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