import http from '@/utils/http'
import { AppDispatch } from '..'
import { A6tableType } from '@/pages/A6record/type'

/**
 * 课程预约记录-列表
 */

export const A6_APIgetList = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('cms/apply/pageList', data)
    if (res.code === 0) {
      const arr: A6tableType[] = res.data.records
      arr.forEach(v => {
        v.cityStr = v.province + '-' + v.city
        v.myIdNum = `${v.papers ? v.papers + '/' : ''}${v.identity}`
      })
      const obj = {
        list: arr,
        total: res.data.total
      }
      dispatch({ type: 'A6/getList', payload: obj })
    }
  }
}

/**
 * 课程预约记录-删除
 */
export const A6_APIdel = (id: number) => {
  return http.get(`cms/apply/removes/${id}`)
}

/**
 * 课程预约记录-审核
 */
export const A6_APIauth = (id: number, status: number) => {
  return http.get(`cms/apply/update/${id}/${status}`)
}

/**
 * 地区统计
 */
export const Loc_APIlist = (data: any, type: '课程' | '展馆') => {
  const url = type === '课程' ? 'cms/apply/groupBy' : 'cms/applyExhibition/groupBy'

  return http.post(url, data)
}

/**
 * 课程预约记录-总人数
 */
export const A6_APIgetNumAll = (data: any) => {
  return http.post('cms/apply/count', data)
}
