import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { OrderMainCrrcExtVO, OrderMainCrrcExtForm, OrderMainCrrcExtQuery } from '@/api/order/orderMainCrrcExt/types';

/**
 * 查询中车电子商城订单扩展列表
 * @param query
 * @returns {*}
 */
export const listOrderMainCrrcExt = (query?: OrderMainCrrcExtQuery): AxiosPromise<OrderMainCrrcExtVO[]> => {
  return request({
    url: '/order/mainCrrcExt/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询中车电子商城订单扩展详细
 * @param id
 */
export const getOrderMainCrrcExt = (id: string | number): AxiosPromise<OrderMainCrrcExtVO> => {
  return request({
    url: '/order/mainCrrcExt/' + id,
    method: 'get'
  });
};

/**
 * 新增中车电子商城订单扩展
 * @param data
 */
export const addOrderMainCrrcExt = (data: OrderMainCrrcExtForm) => {
  return request({
    url: '/order/mainCrrcExt',
    method: 'post',
    data: data
  });
};

/**
 * 修改中车电子商城订单扩展
 * @param data
 */
export const updateOrderMainCrrcExt = (data: OrderMainCrrcExtForm) => {
  return request({
    url: '/order/mainCrrcExt',
    method: 'put',
    data: data
  });
};

/**
 * 删除中车电子商城订单扩展
 * @param id
 */
export const delOrderMainCrrcExt = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/mainCrrcExt/' + id,
    method: 'delete'
  });
};

/**
 * 导出中车电子商城订单扩展
 * @param query
 */
export const exportOrderMainCrrcExt = (query?: OrderMainCrrcExtQuery) => {
  return request({
    url: '/order/mainCrrcExt/export',
    method: 'post',
    params: query
  });
};

/**
 * 一键确定订单
 * @param orderIds 订单ID列表，多个用逗号分隔
 */
export const oneKeyConfirmOrder = (orderIds: string) => {
  return request({
    url: '/order/mainCrrcExt/oneKeyConfirmOrder/' + orderIds,
    method: 'post'
  });
};

/**
 * 导入订单发货数据
 * @param file 导入文件
 */
export const importDeliverData = (file: File) => {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/order/mainCrrcExt/importDeliverData',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};

/**
 * 获取订单发货导入模板
 */
export const importDeliverTemplate = () => {
  return request({
    url: '/order/mainCrrcExt/importDeliverTemplate',
    method: 'post',
    responseType: 'blob'
  });
};
/**
 * 导出发货信息
 */
export const exportOrderDeliverInfo = () => {
  return request({
    url: '/order/mainCrrcExt/exportOrderDeliverInfo',
    method: 'post',
    responseType: 'blob'
  });
};
