<!-- 搜索表单 -->
<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';

    const emit = defineEmits(['search']);

    const formItems = reactive([
        { type: 'input', label: '书名', prop: 'bookName' },
        { type: 'input', label: 'ISBN', prop: 'isbn' },
        {
            type: 'inputNumberRange',
            label: '库存',
            prop: 'stock',
            keys: ['minStock', 'maxStock'],
            props: {
                minAttrs: { min: 0 },
                maxAttrs: { max: 10 },
                label: '库存',
                onChange: (val) => {
                    searchRef.value?.setData({
                        minStock: val.min,
                        maxStock: val.max
                    });
                }
            }
        }
    ]);

    const initKeys = reactive({
        bookName: '',
        isbn: '',
        minStock: void 0,
        maxStock: void 0
    });

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