import request from '@/utils/request';

/**
 * aps计划工单
 */
export async function getList(data) {
  const res = await request.post('/aps/productionplan/page', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
/**
 * 工单发布
 */
export async function getDeviceList({ productionId }) {
  const res = await request.get(
    `/aps/batchingworkorder/getDeviceList/${productionId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 生产计划添加工单列表
export async function getPlanDeviceList({ produceVersionId }) {
  const res = await request.get(
    `/aps/workorder/getDeviceList/${produceVersionId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 选择工艺路线
export async function routeList(params) {
  const res = await request.get('/main/producerouting/page', { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
}
// 工序
export async function getProduceTaskList(params) {
  const res = await request.post(
    '/main/producerouting/taskinstance/page',
    params
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
}

/**
 * 生产订单
 */
export async function workOrder(params) {
  const res = await request.post('/aps/workorder/page', params);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 生产工单
 */
export async function produceOrder(params) {
  const res = await request.post('/mes/workorder/page', params);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 获取计划详情
export async function getUpdateInfoById(id) {
  const res = await request.get(`/aps/productionplan/getUpdateInfoById/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 生产计划
 */
export async function getPlanList(data) {
  const res = await request.post('/aps/productionplan/page', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 入库申请
 */
export async function warehousing(data) {
  const res = await request.get('/mes/applystorage/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

// aps生产计划获取产品的多个bom版本
export async function bomListByPlan(params) {
  const res = await request.get(`/main/bomCategory/bomListByPlan`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 根据bom 获取工艺路线

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

// 保存返工返修
export async function temporaryPlanSave(data) {
  const res = await request.post(`/aps/productionplan/temporaryPlanSave`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 生成编码
export async function getCode(code) {
  const res = await request.get(`/main/codemanage/getCode/` + code, {});
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询工厂列表-分页
export async function getFactoryarea(params) {
  const res = await request.get(`/main/factoryarea/page`, {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改处置状态
 */
export async function updateDisposalStatus(data) {
  const res = await request.post(
    '/qms/qmsreturnrepairwork/updateDisposalStatus',
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
