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

/** 获取表格数据 */
export const getRepTemplateListApi = (data: any) => {
  return request.postJson({ url: '/RepTemplate/spi/reporting/RepTemplate/RepTemplateQueryPage', data });
};

/** 批量删除 */
export const delRepTemplateListApi = (list: string[] | number[]): Promise<IResponse> => {
  const _list = list.map(v => {
    return {
      tId: v.tId,
    };
  });
  return request.postJson({
    url: '/RepTemplate/spi/reporting/RepTemplate/RepTemplateBatchDelete',
    data: {
      list: _list,
    },
  });
};

/** 删除 */
export const delRepTemplateApi = (tId?: string): Promise<IResponse> => {
  return request.postJson({ url: '/RepTemplate/spi/reporting/RepTemplate/RepTemplateDelete', data: { tId } });
};

/** 保存 */
export const saveRepTemplateApi = (data: Partial<TableData>): Promise<IResponse> => {
  return request.doImport({ url: '/RepTemplate/sui/reporting/RepTemplate/RepTemplateSave', data });
};

/** 查询单条数据 */
export const queryRepTemplateApi = (tId?: string): Promise<IResponse> => {
  return request.postJson({ url: '/RepTemplate/spi/reporting/RepTemplate/RepTemplateQueryOne', data: { tId } });
};

/** 查询文件流 */
export const queryFileFlowRepTemplateApi = (pId?: string): Promise<IResponse> => {
  return request.doPreviewFile({ url: '/RepDataProblem/sdi/reporting/RepDataProblem/RepDataProblemPreview', data: { pId } });
};

/** 同步导入 */
export const importExcelApiUrl = '/RepTemplate/sui/reporting/RepTemplate/RepTemplateImportExcel';

/** 异步导入 */
export const importExcelAsyncApiUrl = '/RepTemplate/sui/reporting/RepTemplate/RepTemplateImportAsyncExcel';

/** 下载word */
export const exportTemplateApi = (params: any) => {
  return request.doExport({ url: '/RepDataProblem/sdi/reporting/RepDataProblem/RepDataProblemPreview', params});
};

/** 获取报告分类 */
export const getCategory = ({ paramName, systemCode }): Promise<IResponse> => {
  return request.postJson({
    url: '/param/spi/param/systemparam',
    data: {
      paramName: paramName,
      systemCode: systemCode,
    },
  });
};

