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

class WorkbenchService {
  // 删除流程
  removeFlowById(params) {
    return axios({
      url: 'api/framework/v1/process-manager/process-instance/remove',
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 暂停流程
  pauseFlowById(params) {
    return axios({
      url: 'api/framework/v1/process-manager/process-instance/suspend',
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 回复流程
  recodeFlowById(params) {
    return axios({
      url: 'api/framework/v1/process-manager/process-instance/resume',
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 终止流程
  terminateFlowById(params) {
    return axios({
      url: 'api/framework/v1/process-manager/process-instance/terminate',
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 返回可选择的流程结果
  findStepsByFlowId(instId) {
    return axios({
      url: 'api/framework/v1/process-manager/intervene/steps/' + instId,
      method: 'post',
    }).then((res) => {
      return res.data
    })
  }

  // 可干预环节的后继操作操作列表
  toActions(params) {
    return axios({
      url: `api/framework/v1/process-manager/intervene/actions`,
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 干预到指定流转操作
  interToActions(params) {
    return axios({
      url: `api/framework/v1/process-manager/intervene/to-action`,
      method: 'post',
      data: params,
    })
  }

  // 干预到指定流转环节
  toSteps(params) {
    return axios({
      url: `api/framework/v1/process-manager/intervene/to-step`,
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 异常统计列表
  getExpection(params) {
    return axios({
      url: `api/framework/v1/workflow-statistics/flow-abnormal`,
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 流程数量统计
  getFlowStatistics(params) {
    return axios({
      url: `api/framework/v1/workflow-statistics/flow-count`,
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 流程时效统计
  getFlowSignStatistics(params) {
    return axios({
      url: `api/framework/v1/workflow-statistics/flow-aging`,
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 流程会签时效统计
  getFlowAgtinStatistics(params) {
    return axios({
      url: `api/framework/v1/workflow-statistics/flow-sign`,
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 取得表单数量
  getTotalCount(params) {
    return axios({
      url: 'api/framework/v1/workflow-statistics/total-count',
      method: 'get',
      params: params,
    }).then((res) => {
      return res.data
    })
  }

  // 单条系统提醒设为已读
  haveReadMessage(params) {
    return axios({
      url: `api/mobile/v1/person/message/${params}/1`,
      method: 'put',
    })
  }

  // 批量系统提醒设为已读
  haveReadMessages(params) {
    return axios({
      url: `api/mobile/v1/person/messages/ids/1`,
      method: 'put',
      data: params.ids,
    })
  }

  // 系统提醒删除
  delete(params) {
    return axios({
      url: `api/framework/v1/person/messages/sys-with-trustor/delete`,
      method: 'delete',
      params: {
        ids: params.ids,
      },
    })
  }

  // 获取业务类型分类
  getCategories(id) {
    return axios({
      url: `api/framework/v1/businesstype-manage/categories/children-list-by-id?parentId=${id}`,
      method: 'get',
    }).then((res) => {
      return res.data
    })
  }

  // 获取业务类型
  getBusinesstypes(categoryCode) {
    return axios({
      url: `api/framework/v1/businesstype-manage/businesstypes/list-auth-with-sub?categoryCode=${categoryCode}`,
      method: 'get',
    }).then((res) => {
      return res.data
    })
  }

  // 获取业务类型（应用+业务类型）
  getAllAppYwlx() {
    return axios({
      url: 'api/framework/v1/newflow/auth-businesstypes',
      method: 'get',
    })
  }

  // 流程查询
  getWorkFlowSearch(params) {
    return axios({
      url: `api/framework/v1/workflow-search-center/workflow-List`,
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 获取流程实例的当前活动环节信息
  activeSteps(instId) {
    return axios({
      url: `api/framework/v1/process-instance-query/active-steps/` + instId,
      method: 'get',
    }).then((res) => {
      return res.data
    })
  }

  // 流程处理意见
  optionList(params) {
    return axios({
      url: `api/framework/v1/flows/opinion-list`,
      method: 'get',
      params,
    }).then((res) => {
      return res.data
    })
  }

  // 修改流程意见
  updateOptions(params) {
    return axios({
      url: `api/framework/v1/flows/update-opinion`,
      method: 'post',
      data: params,
    }).then((res) => {
      return res.data
    })
  }

  // 一屏预览初始化获取配置
  getPreviewControl() {
    return axios({
      url: `api/framework/v1/doc-preview/system-config-details`,
      method: 'get',
    }).then((res) => {
      return res.data
    })
  }

  // 一屏预览保存
  savePreviewControl(params) {
    return axios({
      url: `api/framework/v1/page/handleData`,
      method: 'post',
      data: params,
    })
  }

  // 水印配置管理
  getWatermarkConfig() {
    return axios({
      url: 'api/framework/v1/watermark/watermark-config-details',
      method: 'get',
    }).then((res) => {
      return res.data
    })
  }

  // 水印配置保存
  saveWatermarkConfig(params) {
    return axios({
      url: `api/framework/v1/page/handleData`,
      method: 'post',
      data: params,
    })
  }

  //  获取 groupId
  getGroupCode() {
    return axios({
      url: 'api/framework/v1/attachment-extend/attachments-create-group-code',
      method: 'get',
    })
  }

  // 打印模板批量导入
  batchImport(data) {
    let params = ''
    if (data.appId) {
      params += '&appId=' + data.appId
    }
    params += data.belongedOrgId ? `&belongedOrgId=${data.belongedOrgId}` : ''
    return axios({
      url: `api/framework/v1/print-template/batch-upload?groupCode=${data.groupId}&status=1${params}`,
      method: 'post',
    })
  }

  // 业务类型导入
  importTreeData(data) {
    return axios({
      url: `api/framework/v1/import/tree?formId=${data.formId}&fileId=${data.fileId}`,
      method: 'post',
    })
  }

  // 配置数据导入
  importListData(data) {
    return axios({
      url: `api/framework/v1/import/list?formId=${data.formId}&fileId=${data.fileId}`,
      method: 'post',
    })
  }

  // 清除缓存-获取页面
  cacheListData(params) {
    return axios({
      url: 'api/framework/v1/page/xml/pagelist',
      method: 'get',
      params,
    }).then((res) => {
      res.data.forEach((item) => (item.isLeaf = item.leaf))
      return res
    })
  }

  // 清除缓存-根据id清除缓存
  clearnCache(params) {
    return axios({
      url: `api/framework/v1/page/xml/clear/${params}`,
      method: 'post',
    }).then((res) => {
      return res
    })
  }

  // 清除缓存-全部清除
  clearnAllCache() {
    return axios({
      url: 'api/framework/v1/page/xml/clearall',
      method: 'post',
    }).then((res) => {
      return res
    })
  }

  // 获取系统管理配置项
  getSysmanageConfig() {
    return axios({
      url: 'api/framework/v1/sys-manage-config/page-details',
      method: 'get',
    }).then((res) => {
      return res.data
    })
  }

  // 系统管理配置保存
  saveSysmanageConfig(params) {
    return axios({
      url: 'api/framework/v1/page/handleData',
      method: 'post',
      data: params,
    })
  }

  // 获取应用类型
  getappTypeList() {
    return axios.post('api/framework/v1/navigator/appType/query').then((res) => {
      return res.data
    })
  }

  // 保存应用
  saveApps(params) {
    return axios.post('api/framework/v1/navigator/appInfos/create', params)
  }

  // 删除应用
  deleteApps(params) {
    return axios.delete(`api/framework/v1/navigator/appInfos/deleteBatch/${params.join(',')}`)
  }

  // 数据清理
  clearData(params) {
    return axios
      .get(`api/framework/v1/oadatamaintenance-dbconfig/startaction?id=${params}`)
      .then((res) => {
        return res
      })
  }

  // 删除日志记录
  delLogRecord(params) {
    return axios.delete(`api/framework/v1/weremotecalllog/${params.join()}`)
  }

  // 获取审核要素左侧树节点
  getReviewTree(id) {
    return axios.get(`api/framework/v1/audit-element/flows/list/?parentCatId=${id}`)
  }

  // 获取流程对应环节
  getFlowlink(id) {
    return axios.get(`api/framework/v1/audit-element/get-all-step?flowId=${id}`)
  }

  // 获取默认处理人
  getDefaultUser(userParams) {
    return axios.post(
      'api/framework/v1/process-drive/task-candidate-users/replace-his-users',
      userParams
    )
  }

  getDefaultStep(params) {
    return axios.post('api/flow-mobile/v1/process-manager/step-buttons', params)
  }

  // 获取根节点
  getRootNode(params) {
    return axios.get(`api/framework/v1/group-manager/group/root-node`, { params })
  }

  // 删除文本校验规则
  deleteVerify(params) {
    return axios({
      url: 'api/xcoa-mobile/v1/page/weStrValidRule',
      method: 'DELETE',
      params,
    }).then((res) => {
      return res
    })
  }
}

export default new WorkbenchService()
