import request from '@/utils/request';

/**
 * 获取产品所有库存
 */
export async function getInventoryTotalAPI(data) {
  if (data.length == 0) {
    return[]
  }
  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 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));
}

/**
 * 产品列表
 */
export async function getProductList(params) {
  const res = await request.get(`/main/category/getList`, { params });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

//库存台账-库存明细-物料维度

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

//库存台账-库存明细

export async function getInventoryDetails(params) {
  const res = await request.get(`/wms/outInDetailRecordTwo/page`, {
    params
  });
  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;
  }
  return Promise.reject(new Error(res.data.message));
}

// 查询出入库详情
//sourceBizNo
export async function getInfoBySourceBizNoAPI(sourceBizNo) {
  const res = await request.get(
    `/wms/outintwo/getInfoBySourceBizNo/${sourceBizNo}`,
    {}
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.resolve({});
}
// 查询出入库详情
//sourceBizNo
export async function getInfoBySourceBizNoAll(sourceBizNo) {
  const res = await request.get(
    `/wms/outintwo/getInfoBySourceBizNoAll/${sourceBizNo}`,
    {}
  );
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.resolve({});
}
// 仓库树
export async function getWarehouseTrees(data) {
  const res = await request.get('/wms/warehouse/getTrees', {
    params: data
  });
  if (res.data.code == 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 物品维度台账列表
export async function getOutindetailtwoList(params) {
  const res = await request.get(`/wms/outindetailtwo/page`, {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 批次维度台账列表
export async function getBatchList(params) {
  const res = await request.get(`/wms/outindetailtwo/batchPage`, {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
// 获取物料维度台账列表
export async function getMaterialList(params) {
  const res = await request.get(`/wms/materialDetail/page`, {
    params
  });
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
