<!-- 搜索表单 -->
<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 props = defineProps({
        status: {
            type: String,
            default: ''
        }
    });

    const formItems = reactive([
        { type: 'input', label: '用户ID', prop: 'userId' },
        {
            type: 'select',
            label: '状态',
            prop: 'status',
            options: [
                { label: '待结算', value: 1 },
                { label: '已结算', value: 2 }
            ]
        },
        {
            type: 'datetimerange',
            label: '时间',
            prop: 'timeRange',
            props: {
                valueFormat: 'YYYY-MM-DD HH:mm:ss',
                format: 'YYYY-MM-DD HH:mm:ss',
                startPlaceholder: '开始日期',
                endPlaceholder: '结束日期',
                onChange: (value) => {
                    searchRef.value?.setData({
                        startTime: value ? value[0] : '',
                        endTime: value ? value[1] : ''
                    });
                }
            }
        }
    ]);

    const initKeys = reactive({
        startTime: '',
        endTime: '',
        nickName: '',
        status: ''
    });

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