import request from '@/utils/request';

export async function getSubPage(data) {
  const res = await request.get('/main/categoryLevel/getSubPage', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function saveOrUpdate(data) {
  const res = await request.post('/main/categoryLevel/saveOrUpdate', data);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 根据父级id查分类树
export async function getTreeByPid(parentId) {
  const res = await request.get(`/main/categoryLevel/getTreeByPid/${parentId}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询所有物品分类
export async function allCategoryLevel() {
  const res = await request.get(`/main/categoryLevel/allCategoryLevel`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 根据type查分类树组
export async function getTreeByGroup(data) {
  const res = await request.get(`/main/categoryLevel/getProduceTreeByPid`, {
    params: data
  });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 根据类型查分类树
export async function getTreeByType(type) {
  const res = await request.get(`/main/categoryLevel/getTreeByType/${type}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 删除分类
export async function deleteCategory(id) {
  const res = await request.get(`/main/categoryLevel/delete/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
//根据ID查询分类详情系信息
export async function getInfoById(id) {
  const res = await request.get(`/main/categoryLevel/getById/${id}`);
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 批次明细

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

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

// 来源id查入库详情
export async function getOutInBySourceBizNo(id) {
  const res = await request.get(`/wms/outin/getOutInBySourceBizNo/${id}`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 来源id查入库详情(error)
export async function getOutInBySourceBizNoOrError(id) {
  const res = await request.get(`/wms/outin/getOutInBySourceBizNo/${id}`);
  console.log('code-------', res.data.code);
  if (res.data.code == 0) {
    return Promise.resolve(res.data.data);
  } else {
    return Promise.reject('error');
  }
}

// 质检
export async function updateOutInRecord(data) {
  const res = await request.post(`wms/outin/updateOutInRecord`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 质检wuliao
export async function updateMaterialById(data) {
  const res = await request.post(`wms/outin/updateMaterialById`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 质检员反馈
export async function uploadQualityFile(data) {
  const res = await request.post(`wms/outin/uploadQualityFile`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 根据code查询detail
export async function getDetailByCode(data) {
  const res = await request.post(`wms/outin/getDetailByCode`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
