import { TypeI5Tree } from '@/pages/Isystem/I5organization/data'
import { AppDispatch } from '@/store'
import http from '@/utils/http'
/**
 * 获取对应表格列表(传id就是列表，从第三级开始)
 */
export const I2_APIgetDict = (backFu?: (data: TypeI5Tree[]) => void): any => {
  return async (dispatch: AppDispatch) => {
    let url = 'cms/dict/getTree'
    const res = await http.get(url)
    if (res.code === 0) {
      dispatch({ type: 'I2/getDictAll', payload: res.data || [] })
      backFu && backFu(res.data || [])
    }
  }
}

// 根据指定id返回树结构
export const I2_APIgetDictZhi = (id: string) => {
  return http.get(`cms/dict/getTree?parentId=${id}`)
}

/**
 * 获取详情
 */
export const I2_APIgetInfo = (id: string) => {
  return http.get(`cms/dict/detail/${id}`)
}

/**
 * 新增、编辑
 */
export const I2_APIsave = (data: any) => {
  return http.post('cms/dict/save', { ...data, type: 'dict' })
}

/**
 * 删除
 */
export const I2_APIdel = (id: string) => {
  return http.get(`cms/dict/remove/${id}`)
}
