import request from '@/utils/request';

/**
 * 获取信息详情
 */
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 UpdateInformation(data) {
  const res = await request.put(`/eom/businessopportunity/update`, data);
  return res.data;
}

/**
 * 查询客户联系人列表
 */
export async function getcontactlink(params) {
  const res = await request.get(`/eom/contactlink/list/`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 生产主管指派技术员
export async function assignTechnician(data) {
  const res = await request({
    url: '/bpm/businessOpportunityApprove/assignTechnician',
    method: 'post',
    data: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 更新信息
 */
export async function updateProduct(data) {
  const res = await request.post(`/eom/businessopportunity/updateProduct`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 生产主管复核
 */
export async function productionSupervisorReApprove(data) {
  const res = await request.put(
    `/bpm/businessOpportunityApprove/productionSupervisorReApprove`,
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 销售主管审批
 */
export async function salesManagerApprove(data) {
  const res = await request.put(
    `/bpm/businessOpportunityApprove/salesManagerApprove`,
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 销售员补充
 */
export async function salesmanApprove(data) {
  const res = await request.put(
    `/bpm/businessOpportunityApprove/salesmanApprove`,
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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