import request from '@/utils/request';

// 根据分类组编码查询分类树信息
export async function getTreeByPid (pid) {
  const res = await request.get(`/main/categoryLevel/getTreeByPid/${pid}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 新增物料
export async function addMaterial (data) {
  const res = await request.post(`/main/category/add`, data);
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

// 编辑物料
export async function editMaterial (data) {
  const res = await request.post(`/main/category/edit`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取列表
export async function getMaterialList (data) {
  const res = await request.get(`/main/category/getList`, {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取详情
export async function getDetailInfo (id) {
  const res = await request.get(`/main/category/info/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//删除
export async function removeMaterial (id) {
  const res = await request.get(`/main/category/remove/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//根据产品ID获取bom列表、工艺路线列表【产品管理】
export async function getBomRoutingList (categoryId) {
  const res = await request.get(`/main/category/getSourceList/${categoryId}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
