<!-- 搜索表单 -->
<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, watch } from 'vue';
    import ProSearch from '@/components/CommonPage/ProSearch2.vue';

    let { proxy } = getCurrentInstance();
    const emit = defineEmits(['search']);

    const formItems = reactive([
        { type: 'input', label: '用户名', prop: 'nickName' },
        {
            type: 'dictSelect',
            label: '状态',
            prop: 'status',
            props: { code: 'withdrawal_status' }
        },
        {
            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 props = defineProps({
        status: {
            type: String,
            default: ''
        }
    });

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

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