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

/**
 * 故事 - 获取分页列表
 */
export const E2_APIgetList = (data: any, res?: boolean): any => {
  if (res) return http.post('cms/story/page', data)
  else {
    return async (dispatch: AppDispatch) => {
      const res = await http.post('cms/story/page', data)
      if (res.code === 0) {
        const obj = {
          list: res.data.records,
          total: res.data.total
        }

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

/**
 * 故事 - 获取全部数据
 */
export const E2_APIgetListAll = () => {
  return http.post('cms/story/page', {
    pageSize: 9999,
    pageNum: 1,
    businessStartTime: '',
    businessEndTime: '',
    searchKey: '',
    startTime: '',
    endTime: '',
    status: ''
  })
}

/**
 * 故事 - 删除
 */
export const E2_APIdel = (id: string | string[]) => {
  const ids = Array.isArray(id) ? id : [id]
  return http.post('/cms/story/removes', ids) // 直接传数组
}

/**
 * 故事 - 获取详情
 */
export const E2_APIgetInfo = (id: number) => {
  return http.get(`cms/story/detail/${id}`)
}

/**
 * 故事 - 新增或修改
 */
export const E2_APIsave = (data: any) => {
  return http.post('cms/story/save', data)
}
