<!-- 搜索表单 -->
<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,
                    remote: true,
                    remoteMethod: (query) => {
                        if (!query) {
                            return [];
                        }
                        return getStoreList(query).then((res) => {
                            if (res.data.code == 200) {
                                return res.data.data.map((v) => ({
                                    label: v.name,
                                    value: v.id
                                }));
                            } else {
                                return [];
                            }
                        });
                    }
                }
            },
            { type: 'input', label: '库位编码', prop: 'positionCode' },
            { type: 'input', label: '订单编号', prop: 'orderId' },
            { type: 'input', label: '物流编号', prop: 'waybillCode' }
        ];
    });

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

    const initKeys = reactive({
        godownId: '',
        positionCode: '',
        waybillCode: '',
        orderId: ''
    });

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