<!-- 搜索表单 -->
<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 formItems = reactive([
        { type: 'input', label: '书名', prop: 'bookName' },
        { type: 'input', label: 'ISBN', prop: 'isbn' },
        { type: 'input', label: '作者', prop: 'author' },
        { type: 'input', label: '出版社', prop: 'publish' },
        { type: 'input', label: '员工姓名', prop: 'feedbackUserName' },
        {
            type: 'inputNumberRange',
            label: '定价',
            prop: 'price',
            keys: ['priceMin', 'priceMax'],
            props: {
                label: '定价',
                onChange: (val) => {
                    searchRef.value?.setData({
                        priceMin: val.min,
                        priceMax: val.max
                    });
                }
            }
        },
        {
            type: 'inputNumberRange',
            label: '回收折扣',
            prop: 'recoveryDiscount',
            keys: ['discountMin', 'discountMax'],
            props: {
                minAttrs: { min: 0 },
                maxAttrs: { max: 10 },
                label: '回收折扣',
                onChange: (val) => {
                    searchRef.value?.setData({
                        discountMin: val.min,
                        discountMax: val.max
                    });
                }
            }
        },
        {
            type: 'select',
            label: '处理状态',
            prop: 'handStatus',
            options: [
                { label: '未处理', value: 0 },
                { label: '已处理', value: 1 }
            ]
        },
        {
            type: 'datetime',
            label: '反馈时间开始',
            prop: 'feedbackTimeStart',
            props: {
                format: 'YYYY-MM-DD HH:mm:ss',
                valueFormat: 'YYYY-MM-DD HH:mm:ss'
            }
        },
        {
            type: 'datetime',
            label: '反馈时间结束',
            prop: 'feedbackTimeEnd',
            props: {
                format: 'YYYY-MM-DD HH:mm:ss',
                valueFormat: 'YYYY-MM-DD HH:mm:ss'
            }
        }
    ]);

    const initKeys = reactive({
        bookName: '',
        isbn: '',
        author: '',
        publish: '',
        feedbackUserName: '',
        handStatus: void 0,
        priceMin: void 0,
        priceMax: void 0,
        discountMin: void 0,
        discountMax: void 0,
        feedbackTimeStart: '',
        feedbackTimeEnd: ''
    });

    const searchRef = ref(null);
    /** 搜索 */
    const search = (data) => {
        let params = JSON.parse(JSON.stringify(data));
        delete params.price;
        delete params.recoveryDiscount;
        emit('search', params);
    };
</script>
