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

/**
 *根据Type获取预约记录列表 1-展馆预约记录 2-活动预约记录
 */
export const B_APIgetList = (data: {
  pageNum: number
  pageSize: number
  type: number
  name?: string
  startTime?: string
  endTime?: string
  appointmentServiceId?: number
  status?: number
}): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('museum/appointment/page', data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }
      dispatch({ type: 'B/getList', payload: obj })
    }
  }
}

/**
 * 预约记录-获取详情
 */
export const B_APIgetInfo = (id: number) => {
  return http.post(`museum/appointment/info/${id}`)
}

/**
 * 预约记录-删除
 */
export const B_APIdel = (id: number) => {
  return http.post(`museum/appointment/del/${id}`)
}

/**
 * 导出Excel Type 1-展馆预约记录 2-活动预约记录
 */
export const B_APIexportExcel = (data: {
  type: number
  name?: string
  startTime?: string
  endTime?: string
  appointmentServiceId?: number
  status?: number
}) => {
  // return `baseURL/api/museum/appointment/exportExcel?type=${type}`
  return http.post(`${baseURL}/api/museum/appointment/exportExcel`, data, {
    responseType: 'blob'
  })
}

/**
 * 导出Excel Type 1-展馆预约记录 2-活动预约记录
 */
// export const B_APIexportExcel = (type: number) => {
//   return `baseURL/api/museum/appointment/exportExcel?type=${type}`
// }

/**
 * 预约记录-设置讲解服务-新增/编辑
 */
export const B_APIsetServe = (data: { context: string; id?: number; remark: string }) => {
  return http.post('museum/appointmentService/saveOrEdit', data)
}

/**
 * 预约记录-设置讲解服务-查询
 */
export const B_APIgetServe = () => {
  return http.post(`museum/appointmentService/list`)
}

/**
 * 预约记录-设置讲解服务-删除
 */
export const B_APIdelServe = (id: number) => {
  return http.post(`museum/appointmentService/del/${id}`)
}
