<!-- 销售明细搜索组件 -->
<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, getCurrentInstance } from 'vue';
    import ProSearch from '@/components/CommonPage/ProSearch2.vue';

    defineOptions({ name: 'SaleSearch' });

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

    const formItems = reactive([
        { type: 'input', label: '订单号', prop: 'orderNo' },
        { type: 'input', label: '收货人', prop: 'receiverName' },
        { type: 'input', label: '收货电话', prop: 'receiverPhone' },
        {
            type: 'daterange',
            label: '下单时间',
            prop: 'dateRange',
            keys: ['createTimeStart', 'createTimeEnd'],
            colProps: { span: 6 },
            props: {
                format: 'YYYY-MM-DD',
                valueFormat: 'YYYY-MM-DD',
                onChange: (val) => {
                    searchRef.value?.setData({
                        createTimeStart: val && val.length > 0 ? val[0] : '',
                        createTimeEnd: val && val.length > 0 ? val[1] : ''
                    });
                }
            }
        }
    ]);

    const initKeys = reactive({
        orderNo: '',
        receiverName: '',
        receiverPhone: '',
        createTimeStart: '',
        createTimeEnd: ''
    });

    const searchRef = ref(null);

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

    /** 重置 */
    const reset = () => {
        searchRef.value?.reset();
    };

    defineExpose({
        reset
    });
</script>
