import { TypeI5Tree } from '@/pages/Isystem/I5organization/data'
import { AppDispatch } from '@/store'
import http from '@/utils/http'

/**
 * 组织管理 - 获取树列表
 */
export const I5_APIgetTree = (callFu?: (data: TypeI5Tree[]) => void): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.get('sys/dept/getTree')
    if (res.code === 0) {
      callFu && callFu(res.data || [])
      dispatch({ type: 'I5/getTree', payload: res.data || [] })
    }
  }
}

/**
 * 组织管理 - 删除
 */
export const I5_APIdel = (id: string) => {
  return http.get(`sys/dept/remove/${id}`)
}

/**
 * 组织管理 - 获取详情
 */
export const I5_APIgetInfo = (id: string) => {
  return http.get(`sys/dept/detail/${id}`)
}

/**
 * 组织管理 - 新增或修改
 */
export const I5_APIsave = (data: any) => {
  return http.post('sys/dept/save', data)
}

/**
 * 组织管理 - 获取相关成员
 */
export const I5_APIgetUserById = (id: string) => {
  return http.get(`sys/dept/user/list/${id}`)
}
