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

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

    const formItems = reactive([
        {
            type: 'input',
            label: '姓名',
            prop: 'name',
            placeholder: '请输入姓名'
        },
        {
            type: 'input',
            label: '用户ID',
            prop: 'userId',
            placeholder: '请输入用户ID'
        },
        {
            type: 'input',
            label: '手机号',
            prop: 'mobile',
            placeholder: '请输入手机号'
        },
        {
            type: 'input',
            label: '学校',
            prop: 'school',
            placeholder: '请输入学校'
        },
        {
            type: 'dictSelect',
            label: '状态',
            prop: 'status',
            props: { code: 'partner_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({
                        applyTimeStart: value ? value[0] : '',
                        applyTimeEnd: value ? value[1] : ''
                    });
                }
            }
        }
    ]);

    const initKeys = reactive({
        name: '',
        mobile: '',
        school: '',
        status: '',
        applyTimeStart: '',
        applyTimeEnd: ''
    });

    const searchRef = ref(null);

    /** 搜索 */
    const search = (data) => {
        emit('search', { ...data });
    };

    defineExpose({
        search
    });
</script>
