<!-- 搜索表单 -->
<template>
    <ele-card :body-style="{ padding: '0', paddingTop: '12px' }">
        <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 = computed(() => {
        return [
            { type: 'input', label: '活动名称', prop: 'activityName' },
            { type: 'input', label: '省份', prop: 'provinceName' },
            { type: 'input', label: '地区', prop: 'cityName' },
            {
                type: 'select',
                label: '活动状态',
                prop: 'status',
                options: [
                    { value: '0', label: '已关闭' },
                    { value: '1', label: '进行中' }
                ]
            },
            {
                type: 'daterange',
                label: '申请时间',
                prop: 'timeRange',
                style: {
                    minWidth: '300px'
                },
                props: {
                    valueFormat: 'YYYY-MM-DD',
                    format: 'YYYY-MM-DD',
                    startPlaceholder: '开始日期',
                    endPlaceholder: '结束日期',
                    onChange: (value) => {
                        searchRef.value?.setData({
                            startTime: value ? value[0] : '',
                            endTime: value ? value[1] : ''
                        });
                    }
                }
            }
        ];
    });

    const initKeys = reactive({
        activityName: '',
        provinceName: '',
        cityName: '',
        status: '',
        startTime: '',
        endTime: ''
    });

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