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

/**
 * 获取 进度统计 --表格列表（存到仓库
 */
export const B1_APIgetlistArea = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('cms/schedule/report/region', data)
    if (res.code === 0) {
      const arr: any = res.data.region || []

      const arr2: any = []

      arr.forEach((v: any, i: number) => {
        const cityTxt = `${v.province}${v.city ? '/' + v.city : ''}${
          v.region ? '/' + v.region : ''
        }`
        arr2.push({
          ...v,
          cityAll: cityTxt,
          id: cityTxt ? cityTxt : i
        })
      })

      const obj = {
        list: arr2,
        total: arr.length,
        time: res.data.cacheTime
      }
      dispatch({ type: 'B1/getListArea', payload: obj })
    }
  }
}

/**
 *  获取 进度统计 --表格列表
 */
export const B1_APIgetlistAreaSon = (data: { province: string }) => {
  return http.post('cms/schedule/report/region', data)
}

/**
 * 获取 进度统计 按日期查看 列表
 */
export const B1_APIgetTimeList = (data: any) => {
  return http.post('cms/schedule/report/trend', data)
}
