import request from '@/utils/request';

/**
 * 列表
 */
export async function getList(data) {
  const res = await request.post('/aps/batchingplan/page', 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 saveAndSubmit(data) {
  const res = await request.post('/aps/batchingplan/saveAndSubmit', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}


/**
 * 保存并发布
 */
export async function submitAndPublish(data) {
  const res = await request.post('/aps/batchingplan/submitAndPublish', 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));
// }

//根据bom 版本的id获取对应的物料
export async function listBomByBomVersionId(data) {
  const res = await request.post(
    `/aps/batchingplandetail/listBomByBomVersionId`,
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 销售订单
export async function listBomBySalesOrderIdsOverride(data) {
  const res = await request.post(
    `/aps/batchingplandetail/listBomBySalesOrderIdsOverride`,
    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;
  }
  if (res.data.message) {
    return Promise.reject(new Error(res.data.message));
  }
}

// 提交
export async function submit(data) {
  const res = await request.post(`/bpm/apspurchaseplan/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));
}

// 领用页面提交
export async function addUserPlan(data) {
  const res = await request.post(`/aps/batchingplan/submitOutInStock`, data);
  if (res.data.code == 0) {
    return res.data.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));
}
