import request from '@/utils/request';

// 生成编码
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 workorderPage(data) {
  const res = await request.post('/pda/mes/workorder/page', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 工单列表
export async function workorderPage2(data) {
  const res = await request.post('/mes/workorder/taskReportPage2', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 工单列表

export async function pickTaskReportPage(data) {
  const res = await request.post('/mes/workorder/pickTaskReportPage', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询 工序的工步列表
export async function listByParam(params) {
  const res = await request.get('/main/categoryparamstep/listByWorkerOrder', {
    params: params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 工步生产时间
 * @param data
 * @returns {Promise<*>}
 */
export async function addStepWorkTime(data) {
  const res = await request.post(
    '/main/categoryparamstep/produceStepWorkTime',
    data
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取工步工时记录
 * @param produceStepWorkTimeId
 * @returns {Promise<*>}
 */
export async function listStepWorkTimeRecord(produceStepWorkTimeId) {
  const res = await request.get(
    `/main/categoryparamstep/listStepWorkTimeRecord/${produceStepWorkTimeId}`
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询库存台账首页列表

export async function pageeLedgerMain(data) {
  const res = await request.get('/wms/outInDetailPda/page', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 资产
export async function assetPage(data) {
  const res = await request.get('/main/asset/pdaPage', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 在制品
export async function listInProduct(data) {
  const res = await request.post('/pda/mes/feed/listInProduct', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 父级ID查询分类树
export async function treeByPid(data) {
  const res = await request.get('/pda/main/categoryLevel/pdaTreeByPid', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 根据工单ids获取工单列表
export async function workorderList(data) {
  const res = await request.post('/mes/workorder/list', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 中能根据工单ids获取工单列表
export async function znworkorderList(data) {
  const res = await request.post('/mes/workorder/znList', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// pda报工保存

export async function jobSave(data) {
  const res = await request.post('/mes/workreport/save', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// pda报工保存缓存

export async function saveCache(data) {
  const res = await request.post('/mes/workreport/saveCache', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// pda报工查缓存

export async function getCache(data) {
  const res = await request.post('/mes/workreport/getCache', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 清空缓存
export async function removeCache(data) {
  const res = await request.post('/mes/workreport/removeCache', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// PDA  碳谷 入库查询

export async function listPcToWarehouseTG(data) {
  const res = await request.post('/mes/workreport/listPCToWarehouseTG', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function listPCToWarehouse(data) {
  const res = await request.post('/mes/workreport/listPCToWarehouse', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// pda根据工单id和工序id查询报工详情
export async function listWorkReport(data) {
  const res = await request.post('/pda/mes/workreport/listWorkReport', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// pda根据工单id和工序id查询报工详情  (入库)
export async function listApplystorage(data) {
  const res = await request.get('/mes/applystorage/list', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取配置信息
export async function packageDisposition(data) {
  const res = await request.get(
    '/main/category/packageDisposition/' + data,
    {}
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function packingReport(data) {
  const res = await request.post('/pda/mes/workreport/packingReport', data);

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function qualityParam(data) {
  const res = await request.post('/pda/mes/workorder/qualityParam', data);

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function batchSave(data) {
  const res = await request.post('/mes/feed/batchSave', data);

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function mesWorkorderList(data) {
  const res = await request.post('/mes/workorder/list', data);

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function createInProduct(data) {
  const res = await request.post('/pda/mes/workreport/createInProduct', data);

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function createInProductBatchTG(data) {
  const res = await request.post(
    '/pda/mes/workreport/createInProductBatchTG',
    data
  );

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function createInProductBatch(data) {
  const res = await request.post(
    '/pda/mes/workreport/createInProductBatch',
    data
  );

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function getInventoryTotal(data) {
  const res = await request.post('/wms/stocktwo/getInventoryTotal', data);

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function craftFiles(data) {
  const res = await request.post('/mes/workorder/craftFiles', data);

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//选择仓库
export async function getWarehouseList() {
  const res = await request.post('/wms/warehouse/getWarehouseList');

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取包装信息列表
export async function getPackingList(data) {
  const res = await request.post(
    '/pda/mes/workreport/packingReportRework',
    data
  );

  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取工艺文件
export async function filePageAPI(data) {
  const res = await request.post('/fm/file/queryIds', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
