import request from '@/utils/request';

// 查询仓库下拉列表
export async function getWarehouseList() {
  const res = await request.post(`/wms/warehouse/getWarehouseList`, {});
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function getWarehouseLists(data) {
  const res = await request.post(`/wms/warehouse/select/warehouseList`, {
    params: { status: 1 }
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 根据当前用户id查询他的负责工序
export async function listTask(data) {
  const res = await request.get('/main/producetask/listTaskByUserId', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 单独报工获取工序列表
export async function singleListTask(data) {
  const res = await request.post('/main/producetask/listTaskByWindow', data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// bom 信息

export async function getByTaskId(data) {
  const res = await request.get(`/main/categoryparam/getByTaskId`, {
    params: data
  });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function pcCheckOutsource(data) {
  const res = await request.get(`/mes/applyoutsource/pcCheckOutsource`, {
    params: data
  });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function getTaskInstanceById(data) {
  const res = await request.get(
    `/pda/mes/workorder/getTaskInstanceById/${data}`
  );
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function checkOutsourceMaterial(data) {
  const res = await request.get(`/mes/applyoutsource/checkOutsourceMaterial`, {
    params: data
  });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//请托申请单
export async function checkPleaseEntrust(data) {
  const res = await request.get(
    `/mes/please_entrust_management/checkPleaseEntrustMaterial`,
    {
      params: data
    }
  );
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

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

export async function outInDetailPdaPage(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 producerouting(data) {
  const res = await request.get(`/main/producerouting/page`, { params: data });
  if (res.data.code == '0') {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function categoryGetList(data) {
  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));
}
export async function factoryworkstationPage(data) {
  const res = await request.get(`/main/factoryworkstation/page`, {
    params: data
  });
  if (res.data.code == '0') {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

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

//判断是否是聚仁环境
export async function isJuRen(data) {
  const res = await request.get(`/pda/mes/us/printStyle`, {
    params: data
  });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

//检查是否重复领料
export async function checkRepeatPick(data) {
  const res = await request.post(`/mes/workorder/pickCheck`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//检查是否重复投料
export async function checkRepeatFeed(data) {
  const res = await request.post(`/mes/workorder/feedCheck`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//查询产品许可证信息
export async function queryProductLicense(data) {
  const res = await request.post(
    `/main/identityphoto/getIdentityPhotoByCategoryId`,
    data
  );
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取任务报工的报工数和损耗数
export async function getTaskReport(data) {
  const res = await request.get(`/aps/assign/allReportQt`, {
    params: data
  });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//获取过程监控的报工数和损耗数
export async function getProcessMonitoring(data) {
  const res = await request.post(`/mes/workreport/checkCourseReport`, data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
