import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { OrderFormVO, OrderFormForm, OrderFormQuery } from '@/api/orderForm/types';

/**
 * 查询全部订单列表
 * @param query
 * @returns {*}
 */

export const listOrderForm = (query?: OrderFormQuery & PageQuery): AxiosPromise<{ records: OrderFormVO[] }> => {
  return request({
    url: '/order-form/list',
    method: 'post',
    data: query
  });
};

/**
 * 查询全部订单详细
 * @param id
 */
export const getOrderForm = (id: string | number, scopeMenuId?: string | number): AxiosPromise<OrderFormVO> => {
  return request({
    url: '/order-form/get-by-id',
    method: 'post',
    data: {
      id,
      scopeMenuId
    }
  });
};

/**
 * 查询全部订单详细 - 订单详情页面翻页用
 * @param id
 */
export function getOrderFormPreNext(id: string | number, scopeMenuId?: string | number) {
  return request({
    url: '/order-form/get-pre-nex-by-id',
    method: 'post',
    data: {
      id,
      scopeMenuId,
      preNextScopeMenuId: scopeMenuId
    },
  })
}

/**
 * 新增全部订单
 * @param data
 */
export const addOrderForm = (data: OrderFormForm) => {
  return request({
    url: '/order-form/add',
    method: 'post',
    data: data
  });
};

/**
 * 修改全部订单
 * @param data
 */
export const updateOrderForm = (data: OrderFormForm) => {
  return request({
    url: '/order-form/edit',
    method: 'post',
    data: data
  });
};

/**
 * 删除全部订单
 * @param id
 */
export const delOrderForm = (id?: string | number | Array<string | number>) => {
  let data = typeof id == 'object' ? { ids: id } : { id }
  return request({
    url: '/order-form/delete',
    method: 'post',
    data
  });
};
