import http from '@/utils/http'
import { AppDispatch } from '..'
import { A1AddType } from '@/types'
/**
 *轮播图-列表
 */

export const A1_APIgetList = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('museum/carousel/page', data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }
      dispatch({ type: 'A1/getList', payload: obj })
    }
  }
}

/**
 *轮播图-更新排序
 *A1_moveUp 上移
 *A1_moveDown 下移
 */

export const A1_moveUp = (index: number): any => ({ type: 'A1/moveUp', payload: index })
export const A1_moveDown = (index: number): any => ({ type: 'A1/moveDown', payload: index })
export const A1_APIsort = (data: any) => {
  return http.post(`museum/carousel/sort`, data)
}
/**
 * 轮播图-删除
 */
export const A1_APIdel = (id: number) => {
  return http.post(`museum/carousel/del/${id}`)
}

/**
 * 轮播图-获取详情
 */
export const A1_APIgetInfo = (id: number) => {
  return http.post(`museum/carousel/info/${id}`)
}

/**
 * 轮播图 新增
 */
export const A1_APIadd = (data: A1AddType) => {
  return http.post('museum/carousel/add', data)
}

/**
 * 轮播图 修改
 */
export const A1_APIedit = (data: A1AddType) => {
  return http.post('museum/carousel/edit', data)
}

/**
 * 轮播图-发布
 */
export const A1_APIpublish = (id: number) => {
  return http.post(`museum/carousel/publish`, { carouselId: id })
}
