<!-- 搜索表单 -->
<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 = reactive([
        {
            type: 'input',
            label: '活动省份',
            prop: 'provinceName',
            placeholder: '请输入活动省份'
        },
        {
            type: 'input',
            label: '活动地区',
            prop: 'cityName',
            placeholder: '请输入活动地区'
        },
        {
            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] : ''
                    });
                }
            }
        },
        {
            type: 'input',
            label: '用户ID',
            prop: 'userId',
            placeholder: '请输入用户ID'
        },
        {
            type: 'input',
            label: '订单编号',
            prop: 'orderId',
            placeholder: '请输入订单编号'
        }
    ]);

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

    const searchRef = ref(null);

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

    defineExpose({
        search
    });
</script>

<style lang="scss" scoped>
    :deep(.el-form-item__content) {
        width: 100%;
    }
</style>
