import request from '@/utils/request';

/**
 * 列表
 */
export async function getList(data) {
  const res = await request.post('/aps/batchingplan/page2', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 保存
 */
export async function save(data) {
  const res = await request.post('/aps/batchingplan/save', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改
 */
export async function del(data) {
  const res = await request.delete('/aps/batchingplan/delete', { data });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 发布信息返显
 */
export async function getById(id) {
  const res = await request.get(`/aps/batchingplan/getById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 详情
 */
export async function getPlanInfoById(id) {
  const res = await request.get(`/aps/batchingplan/getPlanInfoById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 发布信息返显
 */
export async function getReleaseInfoById(id) {
  const res = await request.get(`/aps/batchingplan/getReleaseInfoById/${id}`);
  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(`/wms/outin/getRealTimeInventory`, {
  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));
}

// 批量根据生产计划计算bom列表信息
// export async function listBomBySalesOrderIds(data) {
//   const res = await request.post(`/aps/batchingplandetail/listBomBySalesOrderIds`,data);
//   if (res.data.code == 0) {
//     return res.data.data;
//   }
//   return Promise.reject(new Error(res.data.message));
// }

// 销售订单
export async function baitingListBomBySalesOrderIds(data) {
  const res = await request.post(
    `/aps/batchingplandetail/baitingListBomBySalesOrderIds`,
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 生产订单
export async function listBomByPlanIdsOverride(data) {
  const res = await request.post(
    `/aps/batchingplandetail/listBomByPlanIdsOverride`,
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 根据销售订单计算bom列表信息
export async function listBomBySalesOrderId(data) {
  const res = await request.post(
    `/aps/batchingplandetail/listBomBySalesOrderId`,
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

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

// 根据工艺路线返回工序

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

// 配料计划选择生产工单分页
export async function dosingPage(data) {
  const res = await request.post(`/mes/workorder/dosingPage`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
