import request from '@/utils/request';

export function getList(data) {
  let param = '?page=' + data.page + '&size=' + data.size;
  if (data.title != undefined && data.title != '') {
    param += '&title=' + data.title;
  }
  if (data.date != undefined && data.date != '') {
    param += '&date=' + data.date;
  }
  return request({
    url: '/knowledge/list' + param,
    method: 'get',
    data,
  });
}

export function doDelete(data) {
  return request({
    url: '/knowledge/remove',
    method: 'post',
    data,
  });
}

export function doEdit(data) {
  return request({
    url: '/knowledge/update',
    method: 'post',
    data,
  });
}

export function doAdd(data) {
  return request({
    url: '/knowledge/insert',
    method: 'post',
    data,
  });
}
export function getCategoryDict(data) {
  return request({
    url: '/knowledge/categoryDict',
    method: 'get',
    data,
  });
}

// 知识库分类树
export function getTypeCategoryTree(data) {
  return request({
    url: '/knowledgeCategory/categoryTree',
    method: 'get',
    data,
  });
}

// 知识库分类
export function getTypeList(data) {
  return request({
    url: '/knowledgeCategory/list',
    method: 'get',
    data,
  });
}

// 添加分类
export function doTypeAdd(data) {
  return request({
    url: '/knowledgeCategory/add',
    method: 'post',
    data,
  });
}

// 编辑分类
export function doTypeEdit(data) {
  return request({
    url: '/knowledgeCategory/update',
    method: 'post',
    data,
  });
}

// 删除分类
export function doTypeDel(data) {
  return request({
    url: '/knowledgeCategory/delete?categoryId=' + data.categoryId,
    method: 'post',
    data,
  });
}

// 知识库查询
export function getKnowledgeList(data) {
  let param = '?page=' + data.page + '&size=' + data.size;
  if (data.title != undefined && data.title != '') {
    param += '&title=' + data.title;
  }
  if (data.category != undefined && data.category != '') {
    param += '&category=' + data.category;
  }
  return request({
    url: '/knowledge/list' + param,
    method: 'get',
    data,
  });
}

// 附件上传
export function upload(data) {
  return request({
    url: '/file/upload',
    method: 'post',
    data,
  });
}

// 附件删除
export function fileDel(data) {
  return request({
    url: '/file/del',
    method: 'post',
    data,
  });
}

// 类型字典查询
export function getTypeDict(data) {
  return request({
    url: '/knowledge/typeDict',
    method: 'get',
    data,
  });
}

