import axios from '@/common/services/axios-instance'
class AuditMattersTreeService {
  // 审计事项树
  findIamAuditMattersTree(orgId, parentId, treeDataType) {
    var urlM = ''
    if (treeDataType === '') {
      urlM =
        `api/xcoa-mobile/v1/iam-audit-matters/findIamAuditMattersTree?orgId=` +
        orgId +
        `&parentId=` +
        parentId
    } else if (treeDataType === 'templateTree') {
      if (parentId != null) {
        urlM =
          `api/xcoa-mobile/v1/iam-auditmatters-template/findIamAuditTemplateTree?templateId=` +
          orgId +
          `&id=` +
          parentId
      } else {
        urlM =
          `api/xcoa-mobile/v1/iam-auditmatters-template/findIamAuditTemplateTree?templateId=` +
          orgId +
          `&id=`
      }
    }
    return axios({
      url: urlM,
      method: 'post',
      data: null,
    }).then((res) => {
      res.data.forEach((item) => {
        item.isLeaf = item.props.isItem
      })
      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
    })
  }

  // 获取节点下所有节点信息
  getAllNodeInfo(parentId, frameId) {
    return axios({
      url: `api/xcoa-mobile/v1/iam-audit-frame-category/findIamAuditFrameCategoryAll`,
      method: 'get',
      params: {
        parentId,
        frameId,
      },
    }).then((res) => {
      return res
    })
  }

  // 获取用户所在机构
  getCurrentUserGroup() {
    return axios({
      url: `api/xcoa-mobile/v1/iamorg/getCurrentUserGroup`,
      method: 'get',
    }).then((res) => {
      return res
    })
  }
}
export default new AuditMattersTreeService()
