import request from '@/utils/request';

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

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

/**
 * 获取信息详情
 */
export async function getOpportunityDetail(id) {
  const res = await request.get(`/eom/businessopportunity/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/businessopportunity/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/businessopportunity/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/businessopportunity/delete', {data});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 商机是否生成过报价单
 */
export async function isHasGeneratedQuoteAPI(id) {
  const res = await request.get(`/eom/businessopportunity/hasGeneratedQuote/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.resolve(0);
}
/**
 * 商机是否生成过合同
 */
export async function isHasGeneratedContractAPI(id) {
  const res = await request.get(`/eom/businessopportunity/hasGeneratedContract/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return  Promise.resolve(0);
}




/**
 * 更新状态
 */
export async function updateStatus(id, status) {
  const res = await request.get(`/eom/businessopportunity/updateStatus?id=` + id + '&status=' + status);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 提交
 */
export async function submit(data) {
  const res = await request.post(`/bpm/businessOpportunityApprove/submit`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

