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

// 根据ids查询物品分类
export async function getTreeByIds(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));
}

// 根据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 getListByUserId() {
  const res = await request.get(`/wms/warehouse/getListByUserId`);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 获取产品维度列表
export async function quantityDelivery(data) {
  const res = await request.post(`wms/outin/quantityDelivery`, data);
  if (res.data.code == 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
