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));
}