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/outin/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);
  return res.data;
}

/**
 * 导出报价单
 */
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 getSendSaleOrderrecordDetail(id) {
  const res = await request.get(`/eom/saleordersendrecord/getById/${id}`, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 更新发货单信息
 */
export async function UpdateSendInformation(data) {
  const res = await request.put(`/eom/saleordersendrecord/update`, data);
  return res.data;
}

/**
 * 获取仓库信息
 */
export async function getWarehouseListByIds(data) {
  const res = await request.post(`wms/warehouse/getWarehouseListByIds`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取信息详情
 */
export async function getReturnSaleOrderrecordDetail(id) {
  const res = await request.get(`/eom/saleorderreturnrecord/getById/${id}`, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 获取信息列表
 */
export async function getSendTableList(params) {
  const res = await request.get(`/eom/saleordersendrecord/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 更新信息
 */
export async function UpdateReturnInformation(data) {
  const res = await request.put(`/eom/saleorderreturnrecord/update`, data);
  return res.data;
}
/**
 * 获取信息详情
 */
export async function gettAccountstatementDetail(id) {
  const res = await request.get(`/eom/accountstatement/getById/${id}`, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 更新信息
 */
export async function UpdatetAccountstatement(data) {
  const res = await request.put(`/eom/accountstatement/update`, data);
  return res.data;
}

/**
 * 查询待导入的账单明细
 */
export async function getsearchDetailListByType(params) {
  const res = await request.get(
    `/eom/accountstatement/searchDetailListByType`,
    { params }
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 退货审批
 */
export async function approve(params) {
  const res = await request.post(
    `/bpm/salesOrderReturnApprove/approve`,
    params
  );
  return res.data;
}

// 选择工艺路线
export async function routeList(params) {
  const res = await request.get('/main/producerouting/page', { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
}
// // // 生产版本列表
export async function versionPage(params) {
  let par = new URLSearchParams(params);
  const res = await request.get(`/main/produceversion/page?` + par);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 根据退货单编码获取出库单详情
 */
export async function getOutInByIdAPI(id) {
  const res = await request.get(`/wms/outin/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 客户退货处理单-保存
 */
export async function saleReturnSaveAPI(data) {
  const res = await request.post(`/eom/salereturnhandle/save`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 客户退货处理单-修改
 */
export async function saleReturnUpdateAPI(data) {
  const res = await request.post(`/eom/salereturnhandle/update`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 客户退货处理单-详情
 */
export async function saleReturnGetByIdAPI(id) {
  const res = await request.get(`/eom/salereturnhandle/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 客户退货处理单-提交开启流程
 */
export async function salesOrderReturnSubmit(data) {
  const res = await request.post(`/bpm/salesOrderReturnHandle/submit`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 客户退货处理单-审核流程
 */
export async function approveTaskWithVariablesAPI(data) {
  const res = await request.put(`/bpm/task/approveTaskWithVariables`, data);
  return res.data;
}
/**
 * 对账单 获取信息列表
 */
export async function getAccountstatementList(params) {
  const res = await request.post(`/eom/accountstatement/page`, params);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 对账单 查询待导入的账单明细
 */
export async function getSearchMergeListByTypeAPI(data) {
  const res = await request.post(
    `/eom/accountstatement/searchOrderListByTypeForImport`,
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 对账单 保存
 */
export async function saveAccountStatementAPI(data) {
  const res = await request.post(`/eom/accountstatement/save`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 对账单 修改
 */
export async function updateAccountStatementAPI(data) {
  const res = await request.put(`/eom/accountstatement/update`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 对账单 修改更新收付款信息(财务主管审核流程)
 */
export async function updateReceiveAndPayInfoAPI(data) {
  const res = await request.post(
    `/eom/accountstatement/updateReceiveAndPayInfo`,
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 对账单 更新回执(上传回执)
 */
export async function updateAccountReceiptAPI(data) {
  const res = await request.post(`/eom/accountstatement/updateReceipt`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 对账单 详情
 */
export async function infoAccountStatementAPI(id) {
  const res = await request.get(`/eom/accountstatement/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


/**
 * 对账单 提交发起流程
 */
export async function submitAccountStatementApproveAPI(data) {
  const res = await request.post(`/bpm/accountStatementApprove/submit`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 更新各种单据字段
 */
export async function updateReceiptAPI(data) {
  const res = await request.post(`/eom/salereturnhandle/updateReceipt`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}


/**
 * 对账单 流程作废
 */
export async function accountStatementProcessCancel(data) {
  const res = await request.put(`/bpm/accountStatementApprove/notPass`, data);
  if (res.data.code == 0) {
    return Promise.resolve(res.data);
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 销售订单 流程作废
 */
export async function saleOrderProcessCancel(data) {
  const res = await request.put(`/bpm/salesOrderApprove/notPass`, data);
  if (res.data.code == 0) {
    return Promise.resolve(res.data);
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 销售退货处理单 流程作废
 */
export async function returnHandleProcessCancel(data) {
  const res = await request.put(`/bpm/salesOrderReturnHandle/notPass`, data);
  if (res.data.code == 0) {
    return Promise.resolve(res.data);
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 销售发货单 流程作废
 */
export async function saleSendProcessCancel(data) {
  const res = await request.put(`/bpm/salesOrderSendApprove/notPass`, data);
  if (res.data.code == 0) {
    return Promise.resolve(res.data);
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 销售退货单 流程作废
 */
export async function saleReturnProcessCancel(data) {
  const res = await request.put(`/bpm/salesOrderReturnApprove/notPass`, data);
  if (res.data.code == 0) {
    return Promise.resolve(res.data);
  }
  return Promise.reject(new Error(res.data.message));
}
