import http from '@/utils/http'
import { AppDispatch } from '..'
import { B2tableType } from '@/pages/B2exhiLog/type'

/**
 * 展馆预约记录-列表
 */

export const B2_APIgetList = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('cms/applyExhibition/pageList', data)
    if (res.code === 0) {
      const arr: B2tableType[] = res.data.records
      arr.forEach(v => {
        v.cityStr = v.province + '-' + v.city
      })

      const obj = {
        list: arr,
        total: res.data.total
      }
      dispatch({ type: 'B2/getList', payload: obj })
    }
  }
}

/**
 * 展馆预约记录-用于导出
 */

export const B2_APIgetListAll = async (
  data: any,
  backFu: (arr: B2tableType[]) => void
) => {
  const res = await http.post('cms/applyExhibition/pageList', {
    ...data,
    pageNum: 1,
    pageSize: 99999
  })
  if (res.code === 0) {
    const arr: B2tableType[] = res.data.records
    arr.forEach(v => {
      v.cityStr = v.province + '-' + v.city
    })

    backFu(arr)
  }
}

/**
 * 展馆预约记录-删除
 */
export const B2_APIdel = (id: number) => {
  return http.get(`cms/applyExhibition/removes/${id}`)
}

/**
 * 展馆预约记录-核销
 */
export const B2_APIupdate = (id: number, status: 0 | 1) => {
  return http.get(`cms/applyExhibition/update/${id}/${status}`)
}

/**
 * 展馆预约记录-详情
 */
export const B2_APIgetInfo = (id: number) => {
  return http.get(`cms/applyExhibition/detail/${id}`)
}

/**
 * 展馆预约记录-总人数统计
 */
export const B2_APIgetNumAll = (data: any) => {
  return http.post('cms/applyExhibition/count', data)
}
