import http from '@/utils/http'
import { AppDispatch } from '..'
/**
 * 烈士信息-获取列表
 */
export const A1_APIgetList = (data: any, flag = false): any => {
  if (flag) return http.post('cms/martyr/pageList', data)
  else {
    return async (dispatch: AppDispatch) => {
      const res = await http.post('cms/martyr/pageList', data)
      if (res.code === 0) {
        const obj = {
          list: res.data.records,
          total: res.data.total
        }

        dispatch({ type: 'A1/getList', payload: obj })
      }
    }
  }
}

/**
 * 烈士信息-删除
 */
export const A1_APIdel = (id: number) => {
  return http.get(`cms/martyr/remove/${id}`)
}

/**
 * 烈士信息-新增
 */
export const A1_APIsave = (data: any) => {
  return http.post('cms/martyr/save', data)
}

/**
 * 烈士信息-获取详情
 */
export const A1_APIgetInfo = (id: number) => {
  return http.get(`cms/martyr/detail/${id}`)
}

// --------------牺牲时所在单位管理--------------------
export const A1_APIgetNumList = (type = 'pan'): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.get(`cms/martyr/dict/getDict/${type}`)
    if (res.code === 0) {
      dispatch({ type: 'A1/getNumList', payload: res.data || [] })
    }
  }
}

export const A1_APINumdel = (id: number) => {
  return http.get(`cms/dict/remove/${id}`)
}

export const A1_APINumSave = (data: any) => {
  return http.post('cms/dict/save', data)
}

// --------------人物关系图--------------------
export const A1_APIgetRRlist = (id: number) => {
  return http.get(`cms/martyr/relation/${id}`)
}

export const A1_APIsaveRR = (data: any) => {
  return http.post('cms/martyr/relation/save', data)
}

// --------------生平信息--------------------
export const A1_APIgetTab1List = (id: number) => {
  return http.get(`cms/life/getList/${id}`)
}

export const A1_APIsaveTab1 = (data: any) => {
  return http.post('cms/life/save', data)
}

export const A1_APIdelTab1 = (id: number) => {
  return http.get(`cms/life/remove/${id}`)
}
