import request from '@/config/axios';
import type { TableData } from './types';

/** 获取表格数据 */
export const getRepIndexSetListApi = (data: any) => {
  return request.postJson({ url: '/RepIndexSet/spi/dataset/RepIndexSet/RepIndexSetQueryPage', data });
};

/** 获取指标查询数据 */
export const getRepIndexSearchListApi = (data: any) => {
  return request.postJson({ url: '/RepIndexSet/spi/dataset/RepIndexSet/RepIndexSetSearchPage', data });
};

/** 批量删除 */
export const delRepIndexSetListApi = (list: string[] | number[]): Promise<IResponse> => {
  const _list = list.map(v => {
    return {
      indexsetCode: v.indexsetCode,
      beginDate: v.beginDate,
      endDate: v.endDate,
    };
  });
  return request.postJson({
    url: '/RepIndexSet/spi/dataset/RepIndexSet/RepIndexSetBatchDelete',
    data: {
      list: _list,
    },
  });
};

/** 删除 */
export const delRepIndexSetApi = (indexsetCode?: string, beginDate?: string, endDate?: string): Promise<IResponse> => {
  return request.postJson({ url: '/RepIndexSet/spi/dataset/RepIndexSet/RepIndexSetDelete', data: { indexsetCode, beginDate, endDate } });
};

/** 保存 */
export const saveRepIndexSetApi = (data: Partial<TableData>): Promise<IResponse> => {
  return request.postJson({ url: '/RepIndexSet/spi/dataset/RepIndexSet/RepIndexSetSave', data });
};

/** 查询单条数据 */
export const queryRepIndexSetApi = (indexsetCode?: string, beginDate?: string, endDate?: string): Promise<IResponse> => {
  return request.postJson({ url: '/RepIndexSet/spi/dataset/RepIndexSet/RepIndexSetQueryOne', data: { indexsetCode, beginDate, endDate } });
};

/** 同步导入 */
export const importExcelApiUrl = '/RepIndexSet/sui/dataset/RepIndexSet/RepIndexSetImportExcel';

/** 异步导入 */
export const importExcelAsyncApiUrl = '/RepIndexSet/sui/dataset/RepIndexSet/RepIndexSetImportAsyncExcel';

/** 导出 */
export const exportExcelApi = (params: any) => {
  return request.doExport({ url: '/RepIndexSet/sdi/dataset/RepIndexSet/RepIndexSetExportXls', params });
};

/** 获取参数 */
export const getIndexType = ({ paramName, systemCode }): Promise<IResponse> => {
  return request.postJson({
    url: '/param/spi/param/systemparam',
    data: {
      paramName: paramName,
      systemCode: systemCode,
    },
  });
};

