import http from '@/utils/http'
import { AppDispatch } from '..'
import { TypeZ1dict } from '@/pages/Z_system/Z1dict/type'
/**
 * 获取对应表格列表(传id就是列表，从第三级开始)
 */
export const Z1_APIgetDict = (id?: string, backFu?: (data: TypeZ1dict[]) => void): any => {
  return async (dispatch: AppDispatch) => {
    let url = 'cms/dict/getTree'
    if (id) url = url + `?parentId=${id}`
    const res = await http.get(url)
    if (res.code === 0) {
      const caseStr = id ? 'Z1/getList' : 'Z1/getDictAll'
      dispatch({ type: caseStr, payload: res.data })
      backFu && backFu(res.data)
    }
  }
}

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

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

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

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