<!-- 搜索表单 -->
<template>
    <ele-card :body-style="{ paddingBottom: '8px' }">
        <ProSearch
            :items="columns"
            ref="searchRef"
            :isShowLabel="false"
            @search="search"
        >
            <el-col :span="6" style="min-width: 160px">
                <el-button
                    style="width: 80px"
                    type="primary"
                    plain
                    @click="search"
                    >查询</el-button
                >
                <el-button style="width: 80px" type="info" @click="reset"
                    >重置</el-button
                >
            </el-col>
        </ProSearch>
    </ele-card>
</template>

<script setup>
    import { reactive, ref, defineEmits } from 'vue';
    import { useFormData } from '@/utils/use-form-data';
    import ProSearch from '@/components/CommonPage/ProSearch2.vue';
    import request from '@/utils/request';

    const emit = defineEmits(['search']);
    const columns = ref([
        {
            type: 'input',
            label: '发件人名称',
            prop: 'sendNameLike'
        },
        {
            type: 'input',
            label: '发件人电话',
            prop: 'sendMobileLike'
        },
        {
            type: 'input',
            label: '发件人地址(仅查询7天内数据)',
            prop: 'sendAddressLike'
        },
        {
            type: 'input',
            label: '用户名',
            prop: 'userName'
        },
        {
            type: 'dictSelect',
            label: '售后状态',
            prop: 'refundStatus',
            props: { code: 'recycle_refund_status' }
        },
        {
            type: 'autocomplete',
            label: '全部备注',
            prop: 'remark',
            props: {
                fetchSuggestions: (queryString, cb) => {
                    cb([
                        { value: '无内容', label: '0' },
                        { value: '有内容', label: '1' }
                    ]);
                }
            }
        },
        {
            type: 'select',
            label: '收货仓库',
            prop: 'godownId',
            options: []
        },
        {
            type: 'dictSelect',
            label: '订单类型',
            prop: 'orderType',
            props: { code: 'order_type' }
        },
        {
            type: 'dictSelect',
            label: '物流公司',
            prop: 'finalExpress',
            props: { code: 'final_express' }
        },
        {
            type: 'select',
            label: '结算方式',
            prop: 'verifyPeriodDays',
            options: [
                { label: '7天极速验货', value: 7 },
                { label: '15天安心验货', value: 15 }
            ]
        },
        {
            type: 'dictSelect',
            label: '全部方式',
            prop: 'expressType',
            props: { code: 'express_type' }
        },
        {
            type: 'datetime',
            label: '建单时间（开始时间）',
            prop: 'createTimeStart',
            props: {
                format: 'YYYY-MM-DD HH:mm:ss',
                valueFormat: 'YYYY-MM-DD HH:mm:ss'
            }
        },
        {
            type: 'datetime',
            label: '建单时间（结束时间）',
            prop: 'createTimeEnd',
            props: {
                valueFormat: 'YYYY-MM-DD HH:mm:ss'
            }
        },
        {
            type: 'datetime',
            label: '提交时间（开始时间）',
            prop: 'orderTimeStart',
            props: {
                valueFormat: 'YYYY-MM-DD HH:mm:ss'
            }
        },
        {
            type: 'datetime',
            label: '提交时间（结束时间）',
            prop: 'orderTimeEnd',
            props: {
                type: 'datetime',
                valueFormat: 'YYYY-MM-DD HH:mm:ss'
            }
        },
        {
            type: 'input',
            label: '订单编号(多个以中文逗号、空格或换行分割)',
            prop: 'orderIds',
            colProps: { span: 8 }
        },
        {
            type: 'input',
            label: '物流单号(多个以中文逗号、空格或换行分割)',
            prop: 'waybillCodes',
            colProps: { span: 8 }
        }
    ]);

    //获取仓库数据
    function getGodownList() {
        request.post('/baseinfo/godown/searchGodown?name=').then((res) => {
            if (res.data.code === 200) {
                let item = columns.value.find(
                    (item) => item.prop === 'godownId'
                );
                item.options = res.data.data.map((item) => ({
                    label: item.godownName,
                    value: item.id
                }));
            }
        });
    }
    getGodownList();

    const searchRef = ref(null);
    /** 搜索 */
    const search = (data) => {
        data.remark =
            data.remark === '无内容'
                ? '0'
                : data.remark === '有内容'
                  ? '1'
                  : data.remark;
        emit('search', { ...data });
    };

    /** 重置 */
    const reset = () => {
        resetFields();
        search();
    };
</script>
