import http from '@/utils/http'
import { AppDispatch } from '..'
import { A3DictType, A3ObjType } from '@/pages/A3dict/data'
/**
 * 字典管理-获取列表
 */
export const A3_APIgetList = (): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.get('cms/dict/getList')
    if (res.code === 0) {
      // const obj = {
      //   list: res.data.records,
      //   total: res.data.total
      // }

      const list: A3DictType[] = res.data || []

      const obj = {} as A3ObjType

      list.forEach(v => {
        if (obj[v.type]) obj[v.type].push(v)
        else obj[v.type] = [v]
      })
      dispatch({ type: 'A3/getList', payload: obj })
    }
  }
}

/**
 * 字典管理-删除
 */
export const A3_APIdel = (id: number) => {
  return http.get(`cms/dict/remove/${id}`)
}

/**
 * 字典管理-新增
 */
export const A3_APIsave = (data: any) => {
  return http.post('cms/dict/save', data)
}
