import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SubOrderVO, SubOrderQuery } from './types';

/**
 * 查询子订单列表
 * @param query
 * @returns {*}
 */
export const listSubOrder = (query?: SubOrderQuery): AxiosPromise<{ total: number, rows: SubOrderVO[] }> => {
    return request({
        url: '/order/subOrder/list',
        method: 'get',
        params: query
    });
};

export const dispatchSubOrder = (data: { orderId: string | number; fulfiller: string | number; price: number; }) => {
    return request({
        url: '/order/subOrder/dispatch',
        method: 'put',
        data
    });
};

export const getSubOrderInfo = (id: string | number): AxiosPromise<SubOrderVO> => {
    return request({
        url: '/order/subOrder/getInfo',
        method: 'get',
        params: { id }
    });
};

export const cancelSubOrder = (data: { orderId: string | number; }) => {
    return request({
        url: '/order/subOrder/cancel',
        method: 'put',
        data
    });
};
