<template>
    <ele-card :body-style="{ paddingBottom: '8px' }">
        <ProSearch
            :items="formItems"
            ref="searchRef"
            @search="search"
            :initKeys="initKeys"
        />
    </ele-card>
</template>

<script setup>
    import { reactive, ref } from 'vue';
    import ProSearch from '@/components/CommonPage/ProSearch2.vue';

    const emit = defineEmits(['search']);
    const searchRef = ref(null);

    const formItems = reactive([
        { type: 'input', label: '订单编号', prop: 'orderId' },
        { type: 'input', label: '收件人姓名', prop: 'receiverName' },
        { type: 'input', label: '收件人手机号', prop: 'receiverMobile' },
        { type: 'input', label: '发货物流单号', prop: 'waybillCode' },
        { type: 'input', label: '退货物流单号', prop: 'refundWaybillCode' },
        {
            type: 'select',
            label: '是否催单',
            prop: 'urgeStatus',
            options: [
                { label: '是', value: 1 },
                { label: '否', value: 0 }
            ]
        },
        {
            type: 'dictSelect',
            label: '全部订单状态',
            prop: 'status',
            props: { code: 'shop_order_status' }
        },
        { type: 'input', label: '搜索备注关键字', prop: 'remark' },
        {
            type: 'dictSelect',
            label: '支付方式',
            prop: 'payType',
            props: { code: 'shop_order_pay_type' }
        },
        {
            type: 'daterange',
            label: '下单时间',
            prop: 'dateRange',
            keys: ['createTimeStart', 'createTimeEnd'],
            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({
        orderId: '',
        receiverName: '',
        receiverMobile: '',
        waybillCode: '',
        refundWaybillCode: '',
        status: '',
        remark: '',
        payType: '',
        createTimeStart: '',
        createTimeEnd: ''
    });

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