import axios from '@/common/services/axios-instance'

class DataService {
  // 删除时分类
  deleteCategory(ids) {
    return axios
      .delete('api/xcoa-mobile/v1/iamdatacategory/delete-category?ids=' + ids)
      .then(function(res) {
        return res.data
      })
  }

  findIamAuditMaintainCategoryTree(parentId) {
    const url =
      'api/xcoa-mobile/v1/iamdatacategory/findIamAuditMattersCategoryTree?parentId=' +
      parentId +
      '&auditOrgId=1'
    return axios.post(url).then(function(res) {
      return res
    })
  }

  // 获取单个授权模型信息
  findIamAuditMaintain(id) {
    return axios({
      url: `api/xcoa-mobile/v1/iamdatacategory/findIamDataCategory/?id=${id}`,
      method: 'post',
    }).then((res) => {
      return res.data
    })
  }

  // 获取角色列表
  rolesList() {
    return axios({
      url: `api/xcoa-mobile/v1/iamdatacategory/findRoles`,
      method: 'get',
    }).then((res) => {
      return res.data
    })
  }

  // 获取项目列表
  projectList(params) {
    return axios({
      url: `api/xcoa-mobile/v1/iam-page/businessList`,
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 保存授权模型 iamModelMaintainSqSave
  saveIamAuditMaintain(params) {
    return axios({
      url: `api/xcoa-mobile/v1/iamdatacube/iamDataCubeSqSave`,
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  setShareStatus(data) {
    return axios({
      method: 'post',
      url: `api/framework/v1/page/handleData`,
      data: data,
    })
  }

  // 获取索引列表
  findIndexList(params) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/iam-page/businessList',
      data: params,
    })
  }

  // 解除绑定索引
  unbindIndex(ids) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/iamsearchindex/unbind?ids=' + ids,
    })
  }

  // 获取索引列表
  findIndexListDatas(categoryIds) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/iamsearchindex/getByCategoryIds?categoryIds=' + categoryIds,
    })
  }

  // 我的空间保存分类
  saveMySpaceCategory(params) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/classify-manager/save-update',
      data: params,
    })
  }

  // 我的空间删除分类
  deleteMySpaceCategory(ids) {
    return axios({
      method: 'get',
      url: 'api/xcoa-mobile/v1/classify-manager/delete?ids=' + ids,
    })
  }

  // 我的空间查询根节点
  findMySpaceCategoryRoot() {
    return axios({
      method: 'get',
      url: 'api/xcoa-mobile/v1/classify-manager/root-node',
    })
  }

  // 我的空间查询子节点
  findMySpaceCategoryChild(parentId) {
    return axios({
      method: 'get',
      url: 'api/xcoa-mobile/v1/classify-manager/child-node?parentId=' + parentId,
    })
  }

  // 我的空间分类全量查询
  findMySpaceCategoryTree(params) {
    return axios({
      method: 'get',
      url: 'api/xcoa-mobile/v1/classify-manager/all',
      params: params,
    })
  }

  // 查看分类文件列表
  findMySpaceCategoryFileList(data) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/file-upload/view-data',
      data,
    })
  }

  // 保存文件信息
  saveMySpaceFile(data) {
    return axios({
      method: 'post',
      url: 'api/framework/v1/page/handleData',
      data,
    })
  }

  // 预览excel
  previewExcel(data) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/file-upload/view-data',
      headers: {
        'Content-Type': 'multipart/form-data',
      },
      data,
    })
  }

  // 根据文件创建表
  createTable(data) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/file-upload/create-table',
      headers: {
        'Content-Type': 'multipart/form-data',
      },
      data,
    })
  }

  // 根据文件查看
  queryData(id) {
    return axios({
      method: 'get',
      url: 'api/xcoa-mobile/v1/file-upload/query-data?id=' + id,
    })
  }

  categoryListSync(params) {
    return axios.post('api/xcoa-mobile/v1/iamdatacube/findTree', {}, { params })
  }

  categoryDel(params) {
    return axios.delete('api/xcoa-mobile/v1/iamdatacube/delete-category', { params })
  }

  categoryListWhole(params) {
    return axios.post('api/xcoa-mobile/v1/iamdatacube/all', {}, { params })
  }

  // 获取分类列表-数据授权
  findclassList(id) {
    return axios({
      url: `api/xcoa-mobile/v1/iamdatacube/findIamDataCube/?id=${id}`,
      method: 'post',
    }).then((res) => {
      return res.data
    })
  }

  // 根据分类id-查询分类下所有表
  findOutsideAll(id) {
    return axios({
      method: 'get',
      url: `api/xcoa-mobile/v1/server-info/findByClassifyId?classifyId=${id}`,
    }).then((res) => {
      return res.data
    })
  }

  // 获取表列表-数据授权
  findoutside(ids) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/server-info/findByIds?ids=' + ids,
    })
  }

  // 获取表列表-数据授权分类
  iamDataCubeQueryList(data) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/iamdatacube/iamDataCubeQueryList',
      data: data,
    })
  }

  // 宽表数据查看
  findDataList(id) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/server-info/dataList?id=' + id,
      data: {
        id,
      },
    })
  }

  // 宽表数据导出
  exportData(id) {
    return axios({
      method: 'get',
      url: 'api/xcoa-mobile/v1/server-info/export?id=' + id,
      data: {},
      headers: {
        'Content-Type': 'application/json;charset=UTF-8',
      },
      responseType: 'blob',
    })
  }

  // 财务所属公司列表
  userGrouplist() {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/document-record/userGroup-list',
      data: {},
    })
  }

  // 财务分类列表
  financeClassifyList() {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/document-record/reportType-list ',
      data: {},
    })
  }

  // 保存数据表
  saveDataTable(params) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/server-info/save-update',
      data: params,
    })
  }

  // 授权修改
  exitRecord(params) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/iamdatacube/iamDataCubeSqSave',
      data: params,
    })
  }
}

export default new DataService()
