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

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

    const props = defineProps({
        status: {
            type: String,
            default: ''
        }
    });

    const formItems = reactive([
        { type: 'input', label: '合伙人姓名', prop: 'partnerName' },
        { type: 'input', label: '合伙人用户ID', prop: 'inviteUserId' },
        {
            type: 'select',
            label: '状态',
            prop: 'status',
            options: [
                // 1-未结算 2-已结算 3-已到账 4-已作废
                { label: '待结算', value: 1 },
                { label: '已结算', value: 2 },
                { label: '已到账', value: 3 },
                { label: '已作废', value: 4 }
            ]
        },
        {
            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({
                        createTimeStart: value ? value[0] : '',
                        createTimeEnd: value ? value[1] : ''
                    });
                }
            }
        }
    ]);

    const initKeys = reactive({
        createTimeStart: '',
        createTimeEnd: '',
        partnerName: '',
        status: ''
    });

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