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

class RiskService {
  // 根据ids获取到风险列表数据
  getFxlist(ids) {
    return axios
      .get('api/xcoa-mobile/v1/riskevent/getRiskEventEntitys?ids=' + ids)
      .then(function(res) {
        return res.data
      })
  }

  // 获取审计事项列表信息
  findIcIcmatrix(id) {
    return axios
      .get('api/xcoa-mobile/v1/riskcategory/findIamAuditMatters?id=', id)
      .then(function(res) {
        return res.data
      })
  }

  fngetsortNum(id) {
    return axios
      .post('api/xcoa-mobile/v1/riskevent/getsortNum?catalogId=' + id)
      .then(function(res) {
        return res.data
      })
  }

  // 获取审计事项分类树
  findIcIcmatrixCategoryTree(parentId, orgId, versionId) {
    if (versionId !== null) {
      const url =
        'api/xcoa-mobile/v1/riskcategory/findIamAuditMattersCategoryTree?parentId=' +
        parentId +
        '&auditOrgId=' +
        orgId +
        '&versionId=' +
        versionId
      return axios.post(url).then(function(res) {
        return res
      })
    } else {
      const url =
        'api/xcoa-mobile/v1/riskcategory/findIamAuditMattersCategoryTree?parentId=' +
        parentId +
        '&auditOrgId=' +
        orgId +
        '&versionId=-1'
      return axios.post(url).then(function(res) {
        return []
      })
    }
  }

  // 获取分类path
  findupcatinfo(categoryId) {
    const url = 'api/xcoa-mobile/v1/riskcategory/findupcatinfo?categoryId=' + categoryId
    return axios.post(url).then(function(res) {
      return res
    })
  }

  // 删除时检查分类
  deleteCheckCategory(ids) {
    return axios
      .get('api/xcoa-mobile/v1/riskcategory/delete-check-category?ids=' + ids)
      .then(function(res) {
        return res.data
      })
  }

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

  // 删除事项
  deleteIcIcmatrix(ids) {
    return axios
      .delete('api/xcoa-mobile/v1/riskcategory/delete-iamAuditMatters?ids=' + ids)
      .then(function(res) {
        return res.data
      })
  }

  // 获取分级授权下拉列表
  getManagedHierarchyOrg(formId) {
    return axios({
      url: `api/xcoa-mobile/v1/iam-page/getHavePermissionOrg/${formId}`,
      method: 'post',
    }).then((res) => {
      return res
    })
  }

  // 导出风险库
  exportItem(id, versionId) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/riskevent/exportItem',
      params: { id: Number(id), versionId: Number(versionId) },
      responseType: 'blob',
    })
  }

  // 导出模板
  exportItemTemplate(level) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/riskevent/exportItemTemplate',
      params: { level: Number(level) },
      responseType: 'blob',
    })
  }

  // 导入数据
  importItemTemplate(importType, groupId, mtxVersionId, orgId) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/riskevent/importItemTemplate',
      params: {
        importType: importType,
        groupId: groupId,
        mtxVersionId: mtxVersionId,
        auditOrgId: orgId,
      },
    })
  }

  // 拖拽功能
  dragNode(data) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/riskcategory/drage',
      data: data,
    })
  }

  // 获取版本ID
  getversion(belongUnitId) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/risklibraryversion/getMtxVersion',
      params: { belongUnitId: belongUnitId },
    })
  }

  // 检查分类
  CheckCategory(ids) {
    return axios({
      method: 'get',
      url: 'api/xcoa-mobile/v1/riskcategory/check-category?ids=' + ids,
    }).then((res) => {
      return res.data
    })
  }

  // 检查编号唯一
  checkMeasurecode(eventCode, id, versionId, auditOrgId) {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/riskevent/checkMeasureCode',
      params: {
        eventCode: eventCode,
        id: id,
        versionId: versionId,
        auditOrgId: auditOrgId,
      },
    })
  }

  // 获取用户单位
  getUserDept() {
    return axios({
      method: 'post',
      url: 'api/xcoa-mobile/v1/risklibraryversion/getBelongUnit',
    })
  }
}

export default new RiskService()
