import request from '@/utils/request';

/**
 * 获取客户信息详情
 */
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));
}

//根据ID查询分类详情系信息
export async function getInfoById(id) {
  const res = await request.get(`/main/categoryLevel/getById/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//客户申请列表
export async function contactApplyList(id) {
  const res = await request.get(`/eom/contactlistapply/getById/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//客户申请主管审批
// 创建用户组
export async function managerApprove(data) {
  const res = await request({
    url: '/bpm/contactlistapply/managerApprove',
    method: 'post',
    data: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取客户信息列表
 */
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 getProductList(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 getProduceTreeByPid() {
  const res = await request.get(
    //`/main/categoryLevel/getTreeByPid/9`,
    `/main/categoryLevel/getProduceTreeByPid?type=1`,
    {}
  );
  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.type}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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