import http from '@/utils/http'
import { AppDispatch } from '..'

/**
 *首页管理-获取通知管理详情
 */

export const A0_APIgetTinfo = (id = 1): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.get(`cms/notice/detail/${id}`)
    if (res.code === 0) {
      dispatch({ type: 'A0/getTinfo', payload: res.data })
    }
  }
}

/**
 * 首页管理-通知管理-新增、编辑
 */
export const A0_APIswitch = (id: number, display: 0 | 1) => {
  return http.get(`cms/notice/open/${id}/${display}`)
}

/**
 * 首页管理-通知管理-新增、编辑
 */
export const A0_APIsaveT = (data: any) => {
  return http.post('cms/notice/save', data)
}

// -----------------轮播图管理----------------------

/**
 * 首页管理-获取轮播图列表
 */
export const A0_APIgetList = (): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.get('cms/banner/getList')
    if (res.code === 0) {
      dispatch({ type: 'A0/getList', payload: res.data || [] })
    }
  }
}

/**
 * 首页管理-轮播图-新增、编辑
 */
export const A0_APIsaveI = (data: any) => {
  return http.post('cms/banner/save', data)
}

/**
 * 首页管理-轮播图-删除
 */
export const A0_APIdel = (id: number) => {
  return http.get(`cms/banner/removes/${id}`)
}
