import request from '@/utils/request';
import { download } from '@/utils/file';
/**
 * 获取信息列表
 */
export async function getTableList(params) {
  const res = await request.get(`/eom/saleorder/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 查询仓库列表
 */
export async function getWarehouseList() {
  const res = await request.post(`/wms/warehouse/select/warehouseList`, {
    params: { status: 1 }
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 查询库存可用数
 */
export async function getWarehouseOutStock(params) {
  const res = await request.get(`/wms/stocktwo/getWarehouseOutStock`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取信息详情
 */
export async function getSaleOrderDetail(id) {
  const res = await request.get(`/eom/saleorder/getById/${id}`, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 更新信息
 */
export async function UpdateInformation(data) {
  const res = await request.put(`/eom/saleorder/update`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 新增信息
 */
export async function addInformation(data) {
  const res = await request.post(`/eom/saleorder/save`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除
 */
export async function deleteInformation(data) {
  const res = await request.delete('/eom/saleorder/delete', { data });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 导出报价单
 */
export async function getExport(id) {
  const res = await request.get(`/eom/quote/export/${id}`, {
    responseType: 'blob'
  });

  download(res.data, '报价单.xlsx');
}

/**
 * 销售订单变更
 */
export async function orderChange(data) {
  const res = await request.post(`/eom/saleorder/change`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 提交
 */
export async function submit(data) {
  const res = await request.post(`/bpm/salesOrderApprove/submit`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
