import request from '@/utils/request';
import { download } from '@/utils/file';
/**
 * 获取信息列表
 */
export async function getTableList(params) {
  const res = await request.get(`/eom/purchaseorder/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取信息详情
 */
export async function getpurchaseorderDetail(id) {
  const res = await request.get(`/eom/purchaseorder/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/purchaseorder/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/purchaseorder/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/purchaseorder/delete', { 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/purchaseOrderApprove/submit`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取采购询价表信息
 */
export async function getPurchaseinquiryAPI(id) {
  const res = await request.get(`/eom/purchaseinquiry/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 通过合同ID获取采购计划
 */
export async function getPurchasePlanByContractIdAPI(id) {
  const res = await request.get(`/eom/purchaseplan/getByContractId/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
