import http from '@/utils/http'
import { AppDispatch } from '..'
import { TypeZ4Tree } from '@/pages/Z_system/Z4organization/type'

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

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

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

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

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