<!-- 结算搜索表单 -->
<template>
    <ele-card :body-style="{ padding: '0', paddingTop: '30px' }">
        <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: 'partnerName',
            placeholder: '请输入姓名'
        },
        {
            type: 'input',
            label: '用户ID',
            prop: 'inviteUserId',
            placeholder: '请输入用户ID'
        },
        {
            type: 'input',
            label: '手机号',
            prop: 'mobile',
            placeholder: '请输入手机号'
        },
        {
            type: 'input',
            label: '订单编号',
            prop: 'orderId',
            placeholder: '请输入订单编号'
        },
        {
            type: 'dictSelect',
            label: '结算状态',
            prop: 'status',
            props: {
                code: 'partner_settle_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({
                        createTimeStart: value ? value[0] : '',
                        createTimeEnd: value ? value[1] : ''
                    });
                }
            }
        }
    ]);

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

    const searchRef = ref(null);

    /** 搜索 */
    const search = (data) => {
        let params = JSON.parse(JSON.stringify(data));
        delete params.timeRange;
        emit('search', params);
    };

    defineExpose({
        search
    });
</script>
