import request from '@/utils/request';

// 分页
export async function getPage (params) {
  const res = await request.get(`/main/bom/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 保存
export async function bomSave (data) {
  const res = await request.post(`/main/bom/save`, data);
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

// 编辑
export async function bomUpdate (data) {
  const res = await request.put(`main/bom/update`, data);
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}


// 详情
export async function getById (id) {
  const res = await request.get(`/main/bom/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 删除
export async function bomDelete (pid) {
  const res = await request.get(`/main/bom/delete`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 详情分页
export async function detailPage (params) {
  const res = await request.get(`/main/bom/detail/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//SAP-bom同步 
export async function syncBom () {
  const res = await request.get(`/sap/sync/syncBom`);
  if (res.data.code == 0) {
    return res.data.code;
  }
  return Promise.reject(new Error(res.data.message));
}


// 物料BOM新增- 获取版本号
export async function getVersionCode (categoryId) {
  const res = await request.get(`/main/bom/getVersionCode/${categoryId}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}




