import request from '@/utils/request';

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

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

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

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

/**
 * 客户证书资质信息分页
 */
export async function contactQcPackPageAPI(params) {
  const res = await request.get(
    `/main/professionCertification/selectByRelationIdAndType`,
    { params }
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 新增客户证书资质信息
 */
export async function contactQcPackSaveAPI(data) {
  const res = await request.post(`/main/professionCertification/save`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 修改客户证书资质信息
 */
export async function contactQcPackUpdateAPI(data) {
  const res = await request.put(`/main/professionCertification/update`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取客户证书资质信息详情
 */
export async function contactQcPackDetailAPI(id) {
  const res = await request.get(
    `/main/professionCertification/getById/${id}`,
    {}
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 删除客户证书资质包
 */
export async function contactQcPackDeleteAPI(data) {
  const res = await request.delete(`/main/professionCertification/delete`, {
    data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 提交客户证书资质信息  开启流程
 */
export async function contactQcSubmit(data) {
  const res = await request.post(`/bpm/ProfessionCertification/submit`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

/**
 * 获取客户分类树
 */
export async function contactTypeTree(data) {
  const res = await request.get(`/main/categoryLevel/getTreeByPid/${data.id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 更新用户状态
 */
export async function updateStatus(id, status) {
  const res = await request.get(
    `/eom/contact/updateStatus?id=` + id + '&status=' + status
  );
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 指派
 */
export async function assign(data) {
  const res = await request.post('/eom/contact/assign', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 释放
 */
export async function free(data) {
  const res = await request.post('/eom/contact/free', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 申请
 */
export async function applySave(data) {
  const res = await request.post('/eom/contactlistapply/save', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 供应商维护供货产品
 */
export async function contactProductSaveAPI(data) {
  const res = await request.post('/main/contactproduct/save', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 供应商维护供货产品
 */
export async function contactProductUpdateAPI(data) {
  const res = await request.post('/main/contactproduct/update', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 通过产品查供应商
 */
export async function contactQueryByCategoryIdsAPI(data) {
  const res = await request.post('/eom/contact/queryByCategoryIds', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 发布动态
 */
export async function updateContactDynamics(data) {
  const res = await request.put('/eom/contact/updateContactDynamics', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 回复动态
 */
export async function updateContactComment(data) {
  const res = await request.put('/eom/contact/updateContactComment', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 摘要卡片
 */
export async function queryContactIdCount(id) {
  const res = await request.get(`eom/contact/queryContactIdCount/` + id);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 更新客户关联状态
 */
export async function updateRelationStatus(data) {
  const res = await request.post('/eom/contact/updateRelationStatus', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取供应商最小订购数量
 */
export async function listByContactId(data) {
  const res = await request.post('/eom/contactproduct/listByContactId',  data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 跟进记录统计
 */
export async function groupByContact(params) {
  const res = await request.get(`/eom/businessopportunityfollowup/groupByContact`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


/**
 * 客户资质证照
 */
export async function identityphotoList(data) {
  const res = await request.post(`/main/identityphoto/list`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 保存or更新
export async function saveOrEdit (data) {
  const res = await request.post(`/main/identityphoto/saveOrUpdate`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}



// 获取证照信息详情
export async function getPhotoInfo (id) {
  const res = await request.get(`/main/identityphoto/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 物品信息列表
export async function getList(params) {
  const res = await request.get('/main/category/getList', { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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