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


// 根据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));
}



// 根据类型查分类树
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));
}

// 根据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));
}