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(data) {
  const res = await request.delete(`/main/bom/delete`, { data });
  if (res.data.code == 0) {
    return res.data.message;
  }
  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));
}

// 工序列表  保存

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

// 工序列表

export async function bomTaskList(categoryId) {
  const res = await request.get(`/main/bomtask/list/${categoryId}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//  bom工序信息 删除
export async function bomTaskDelete(data) {
  const res = await request.delete(`/main/bomtask/delete`, { data });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取工序下的产品bom信息

export async function getByTaskId(categoryId, taskId) {
  const res = await request.get(
    `main/category/getCategoryBomByTaskId/${categoryId}/${taskId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询BOM树
export async function getBomTreeList(params) {
  const res = await request.get(`/eam/deviceBom/getList`, { params });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询BOM树 详情
export async function getBomGetById(id) {
  const res = await request.get(`/eam/deviceBom/getById/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询BOM 版本
export async function versionList(params) {
  const res = await request.get(`/eam/deviceBom/versionList`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 新增BOM树节点
export async function saveBomTreeList(data) {
  const res = await request.post(`/main/bomCategory/save`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 删除BOM树节点
export async function deleteBomTreeList(data) {
  const res = await request.delete(`/main/bomCategory/delete`, { data });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

// 保存BOM树节点
export async function updateBatchBOM(data) {
  const res = await request.post(`/main/bomCategory/updateBatchBOM`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取产品BOM列表
export async function getBomPageList(params) {
  const res = await request.get(`/main/bomCategory/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取产品BOM列表
export async function getBomPageCategoryId(params) {
  const res = await request.get(`/eam/deviceBom/pageByCategoryId`, {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 修改BOM属性
export async function bomCategoryUpdate(data) {
  const res = await request.post(`/main/bomCategory/update`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// PBom转换 MBOM
export async function convert(data) {
  const res = await request.post(`/main/bomCategory/convert`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// PBom转换 ABOM
export async function convertABom(data) {
  const res = await request.post(`/main/bomCategory/convertABom`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//PBom转换为EBom
export async function convertEBOM(data) {
  const res = await request.post(`/main/bomCategory/convertEBOM`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// EBom转换为PBom
export async function convertEBomToPBOM(data) {
  const res = await request.post(`/main/bomCategory/convertEBomToPBOM`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 文档
export async function getBomFilePageList(params) {
  const res = await request.get(`/main/bomfile/page`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 启用
export async function startAndStop(data) {
  const res = await request.post(`/main/bomCategory/startAndStop`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 发布

export async function bomSubmit(data) {
  const res = await request.post(`/bpm/bom/submit`, data);
  if (res && res.data.code == 0) {
    return res.data;
  }
}

// 嘉实医药提交
export async function jsBomSubmit(data) {
  const res = await request.post(`/bpm/jsbom/submit`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 嘉实设备提交

export async function deviceBomSubmit(data) {
  const res = await request.post(`/bpm/jsbom/deviceSubmit`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 新增工序
export async function workingProcedureSave(data) {
  const res = await request.post(`/main/categoryparam/save`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 修改工序
export async function workingProcedureUpdate(data) {
  const res = await request.put(`/main/categoryparam/update`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 修改工步
export async function workingStepUpdate(data) {
  const res = await request.post(`/main/categoryparamstep/update`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

// 删除工步
export async function workingStepDelete(data) {
  const res = await request.delete(`/main/categoryparamstep/delete`, { data });
  if (res.data.code == 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

// 工序列表
export async function getMbomPage(params) {
  const res = await request.get(`/main/categoryparam/mBomPage`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 通过工序获取工步列表
export async function getStepListById(params) {
  const res = await request.get(`/main/categoryparamstep/list`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

// 供应商列表
export async function contactList(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));
}

// 检查bom  (里面有几个草稿)

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