import axios from '@/common/services/axios-instance'
class IcTreeService {
  // 业务类型分类树
  getCategoryTree(parentId, params, types) {
    const auditOrgId = params.auditOrgId
    const versionId = params.versionId
    let url = `api/xcoa-mobile/v1/icmtxprocess/findIamAuditMattersCategoryTree?parentId=${parentId}&auditOrgId=${auditOrgId}&versionId=${versionId}`
    if (types === 'FK') {
      url = `api/xcoa-mobile/v1/riskcategory/findIamAuditMattersCategoryTree?parentId=${parentId}&auditOrgId=${auditOrgId}&versionId=${versionId}`
    }
    return axios({
      url: url,
      method: 'post',
    }).then((res) => {
      res.data.forEach((item) => (item.isLeaf = item.leaf))
      return res
    })
  }

  // 获取措施节点
  getMeasureTree(parentId, params, types) {
    const auditOrgId = params.auditOrgId
    const versionId = params.versionId
    let url = `api/xcoa-mobile/v1/icmtxprocess/findIcIcmeasureCategoryTree?parentId=${parentId}&auditOrgId=${auditOrgId}&versionId=${versionId}`
    if (types === 'FK') {
      url = `api/xcoa-mobile/v1/riskcategory/findIcIcmeasureCategoryTree?parentId=${parentId}&auditOrgId=${auditOrgId}&versionId=${versionId}&isAbandonment=${params.isAbandonment}`
    }
    return axios({
      url: url,
      method: 'post',
    }).then((res) => {
      res.data.forEach((item) => (item.isLeaf = item.leaf))
      return res
    })
  }

  // 拖拽功能
  dragNode(params) {
    return axios({
      url: `api/xcoa-mobile/v1/iam-tree/moveTreeNode/${params.configId}/${params.id}/${params.targetId}/${params.position}`,
      method: 'post',
      data: null,
    }).then((res) => {
      res.data.forEach((item) => (item.isLeaf = item.leaf))
      return res
    })
  }

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