import request from '@/utils/request'

import Vue from 'vue'
export const api = '/bi-api'
export const getDatasourceDetail = (params) => {
  return request({
    url: api + '/report/reportdatasource/detail',
    method: 'get',
    params
  })
}
export const getList = (current, size, params) => {
  return request({
    url: api + '/blade-report/report/rest/list',
    method: 'get',
    params: {
      ...params,
      current,
      size
    }
  })
}
export const remove = (ids) => {
  return request({
    url: api + '/blade-report/report/rest/remove',
    method: 'post',
    params: {
      ids
    }
  })
}

//数据源管理
export const reportdatasourceList = () => {
  return request({
    url: api + '/report/reportdatasource/list',
    method: 'get'
  })
}

export const reportdatasourceSave = (params) => {
  return request({
    url: api + '/report/reportdatasource/save',
    method: 'post',
    data: params
  })
}

export const reportdatasourceUpdate = (params) => {
  return request({
    url: api + '/report/reportdatasource/update',
    method: 'post',
    data: params
  })
}

export const reportdatasourceDetail = () => {
  return request({
    url: api + '/report/reportdatasource/list',
    method: 'get'
  })
}

export const reportdatasourceRemove = (ids) => {
  return request({
    url: api + '/report/reportdatasource/remove',
    method: 'post',
    params: {
      ids
    }
  })
}

export const baseInfoListViews = (id) => {
  return request({
    url: api + '/report/baseInfo/listViews',
    method: 'get',
    params: {
      dataSourceId: id
    }
  })
}

export const listViewsByDataSource = (id) => {
  return request({
    url: api + '/report/baseInfo/listViewsByDataSource',
    method: 'get',
    params: {
      datasourceId: id
    }
  })
}

export const reportBaseInfoListColumns = (params) => {
  return request({
    url: api + '/report/baseInfo/listColumns',
    method: 'get',
    params: params
  })
}

export const listColumnsByDatasource = (params) => {
  return request({
    url: api + '/report/baseInfo/listColumnsByDatasource',
    method: 'get',
    params: params
  })
}

export const baseInforemoveBaseInfoCache = (params) => {
  return request({
    url: api + '/report/baseInfo/removeBaseInfoCache',
    method: 'get',
    params: params
  })
}

// 报表指标分类接口
export const indexcategorySubmit = (params) => {
  return request({
    url: api + '/indexcategory/submit',
    method: 'post',
    data: params
  })
}

export const indexcategoryList = (params) => {
  return request({
    url: api + '/indexcategory/list',
    method: 'get',
    params: params
  })
}
// 报表指标信息接口
export const indexinfoSubmit = (params) => {
  return request({
    url: api + '/indexinfo/submit',
    method: 'post',
    data: params
  })
}

export const indexinfoList = (params) => {
  return request({
    url: api + '/indexinfo/list',
    method: 'get',
    params: params
  })
}

export const indexinfoDetail = (params) => {
  return request({
    url: api + '/indexinfo/detail',
    method: 'get',
    params: params
  })
}

export const reportdatasourceTestDs = (params) => {
  return request({
    url: api + '/report/reportdatasource/testDs',
    method: 'post',
    data: params
  })
}

//报表管理接口
export const reportList = (params) => {
  return request({
    url: api + '/report/report/list',
    method: 'get',
    params: params
  })
}

//接口分类
export const dataapicategoryList = (params) => {
  return request({
    url: api + '/dataapicategory/list',
    method: 'get',
    params: params
  })
}
export const dataapicategorySubmit = (params) => {
  return request({
    url: api + '/dataapicategory/submit',
    method: 'post',
    data: params
  })
}
export const dataapicategoryRemove = (ids) => {
  return request({
    url: api + '/dataapicategory/remove',
    method: 'post',
    params: {
      ids
    }
  })
}
//接口管理
export const dataapiList = (params) => {
  return request({
    url: api + '/report/dataapi/list',
    method: 'get',
    params: params
  })
}
export const dataapiPage = (params) => {
  return request({
    url: api + '/report/dataapi/page',
    method: 'get',
    params: params
  })
}
export const dataapiSubmit = (data) => {
  return request({
    url: api + '/report/dataapi/submit',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}
export const dataapiExecute = (params) => {
  return request({
    url: api + '/report/dataapi/execute',
    method: 'post',
    data: params
  })
}

export const dataapiDetail = (id) => {
  return request({
    url: api + '/report/dataapi/detail',
    method: 'get',
    params: {
      id: id
    }
  })
}

export const dataapiRemove = (ids) => {
  return request({
    url: api + '/report/dataapi/remove',
    method: 'post',
    params: {
      ids
    }
  })
}

export const dataapiDetailKey = (key) => {
  return request({
    url: api + '/report/dataapi/detail',
    method: 'get',
    params: {
      apiKey: key
    }
  })
}

export const dataapicheck = (apiKey) => {
  return request({
    url: api + '/report/dataapi/check?apiKey=' + apiKey,
    method: 'post'
  })
}

export const openurl = (key, params = '', method = 'get') =>
  request({
    url: api + '/report/dataapi/' + key,
    method: method,
    params: params
  })

export const openapi = (url, params = {}, method = 'get') =>
  request({
    url: url,
    method: method,
    params: params
  })
export const reportApi = (apiKey, params = {}, method = 'post') =>
  request({
    url: api + '/report/reportApi/' + apiKey,
    method: method,
    data: params
  })
export const getReportData = (params) => {
  return request({
    url: api + '/report/reportApi/getReportData',
    method: 'post',
    data: params
  })
}

export const dataQuerydoing = (params) => {
  return request({
    url: api + '/report/dataQuery/doing',
    method: 'post',
    data: params
  })
}

// //数据源查看 分类列表接口
// export const classList = (params) => {
//   return request({
//     url: api + '/indexcategory/list',
//     method: 'get',
//     params: params
//   })
// }

// //数据源查看 分类接口 page
// export const classListPage = (params) => {
//   return request({
//     url: api + '/indexcategory/page',
//     method: 'get',
//     params: params
//   })
// }

// //数据源查看 添加分类
// export const addClassList = (params) => {
//   return request({
//     url: api + '/indexcategory/submit',
//     // url: api + '/indexcategory/save',
//     method: 'post',
//     data: params
//   })
// }
// //数据源查看 分类编辑
// export const editClassList = (params) => {
//   return request({
//     url: api + '/indexcategory/update',
//     method: 'post',
//     data: params
//   })
// }

// //数据源查看 分类删除
// export const delClassList = (ids) => {
//   return request({
//     url: api + '/indexcategory/remove',
//     method: 'post',
//     params: {
//       ids,
//     }
//   })
// }

//报表维度管理接口 批量提交 batCreate

export const dimensionList = (params) => {
  return request({
    url: api + '/report/dimension/list',
    method: 'get',
    params: params
  })
}
export const dimensionsubmit = (params) => {
  return request({
    url: api + '/report/dimension/submit',
    method: 'post',
    data: params
  })
}
export const dimensionremove = (params) => {
  return request({
    url: api + '/report/dimension/remove',
    method: 'post',
    params: params
  })
}
export const dimensionbatCreate = (param) => {
  return request({
    url: api + '/report/dimension/batCreate',
    method: 'post',
    data: param
  })
}
export const batSaveDimension = (param) => {
  return request({
    url: api + '/report/dimension/batSaveDimension',
    method: 'post',
    data: param
  })
}

export const getDetailList = (param) => {
  return request({
    url: api + '/bigdata/visual/detailList',
    method: 'get',
    params: param
  })
}

export const saveHistoryReport = (param) => {
  return request({
    url: api + '/historyreportinfo/save',
    method: 'post',
    data: param
  })
}

export const updateHistoryReport = (param) => {
  return request({
    url: api + '/historyreportinfo/update',
    method: 'post',
    data: param
  })
}

export const deleteHistoryReport = (param) => {
  return request({
    url: api + '/historyreportinfo/remove',
    method: 'post',
    params: {
      ids: param
    }
  })
}

export const getHistoryreportFolder = (param) => {
  return request({
    url: api + '/historyreportfolder/list',
    method: 'get',
    params: param
  })
}

export const saveHistoryreportFolder = (param) => {
  return request({
    url: api + '/historyreportfolder/save',
    method: 'post',
    data: param
  })
}

export const updateHistoryreportFolder = (param) => {
  return request({
    url: api + '/historyreportfolder/update',
    method: 'post',
    data: param
  })
}

export const removeHistoryreportFolder = (param) => {
  return request({
    url: api + '/historyreportfolder/remove',
    method: 'post',
    params: {
      ids: param
    }
  })
}

export const getHistoryreportList = (param) => {
  return request({
    url: api + '/historyreportinfo/list',
    method: 'get',
    params: param
  })
}

export const getHistoryreportDetail = (param) => {
  return request({
    url: api + '/historyreportinfo/detail',
    method: 'get',
    params: {
      id: param
    }
  })
}

export const invorkComApi = (url, method, params) => {
  const vueRequest = new Vue().$request
  if (method == 'get') {
    let paramUrl = ''
    if (params) {
      for (const key in params) {
        if (Object.hasOwnProperty.call(params, key)) {
          const value = params[key]
          paramUrl += `&${key}=${value}`
        }
      }
      if (paramUrl) {
        //替换第一个字符为?
        paramUrl = paramUrl.replace('&', '?')
        url += paramUrl
      }
    }
    return vueRequest.get(url)
  } else {
    return request({
      url: url,
      method: 'post',
      params: params
    })
  }
}

export const getMapGeoJson = (url) => {
  return request({
    url: url,
    method: 'get'
  })
}
export const permSave = (params) => {
  return request({
    url: api + '/report/perm/save',
    method: 'post',
    data: params
  })
}
export const permUpdate = (params) => {
  return request({
    url: api + '/report/perm/update',
    method: 'post',
    data: params
  })
}
export const permDetail = (datasourceId) => {
  return request({
    url: api + '/report/perm/detail',
    method: 'get',
    params: {
      datasourceId
    }
  })
}
export const tableBlood = (tableName) => {
  return request({
    url: api + '/visual/bloodRelation/treeByTable',
    params: {
      tableName
    }
  })
}

// 获取根据表单ID查询列表
export const getDataPermList = (params) => request.get('/visual-api/paas/visualdev/dataPerm/list', { params })
//添加表单操作权限
export const BtnDataPermSubmit = (params) => {
  return request({
    url: '/visual-api/paas/visualdev/dataPerm/submit',
    method: 'post',
    headers: { 'Content-Type': 'application/xml;charset=UTF-8' },
    data: params
  })
}
