/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-03-03 16:31:27
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2023-07-27 18:02:51
 * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */



import { request } from 'umi';

//获取table列表数据

export type ReportListTableDataType = {
  id: number,
  hospId: number,
  code: number,
  name: string,
  headerText: string,
  dataSource: number,
  columnType: string,
  columnTypeName: string,
  sql: string,
  indicatorCode: string,
  indicatorCodeName: string,
  childColumnList: any[],
}


export const getReportListTableData = (params?: any) => {
  return request<{
    current: number;
    list: ReportListTableDataType[];
    pageSize: number;
    totalCount: number;
    totalPage: number;
  }>('/performance/report/getColumnList', {
    method: 'GET',
    params: { ...params }
  });
};


//新增报表
export type AddTableDataType = {
  name: string,
  headerText: string,
  dataSource: number,
  columnType: string,
  sql?: string,
  indicatorCode?: string,
  indicatorCodeName?: string
}

export const addData = (data: any) => {
  return request('/performance/report/addColumn', {
    method: 'POST',
    data
  });
};



//获取报表类型

export const getReportListType = () => {
  return request('/performance/dict/getDictDataList?current=1&pageSize=10&typeCode=9', {
    method: 'GET',
  });
};

//获取管理指标

export const getManaIndic = () => {
  return request('/performance/report/getIndicatorList', {
    method: 'GET',
  });
};


//编辑表格数据

export type ManaIndicItemTableRowEditType = {
  id: number;
} & AddTableDataType

export const editData = (data: any) => {
  return request('/performance/report/editColumn', {
    method: 'POST',
    data
  });
};

//删除表格操作
export const delData = (id: string) => {
  return request('/performance/report/deleteColumn', {
    method: 'POST',
    params: { id }
  });
};


//添加报表列
export const addReportTableList = (data: any) => {
  return request('/performance/report/addReportColumn', {
    method: 'POST',
    data
  });
};



//获取子列报表列

export const getChildReportList = (columnCode: string) => {
  return request('/performance/report/getChildColumnList', {
    method: 'GET',
    params: { columnCode }
  });
};

//添加子列报表列

export type AddChildReportListDataType = {
  parentCode: string,
  childColumnList: {
    "code": string, //流转功能code
    "columnType":string, //报表列类型
    "dataSource":number, //数据类型
    "dataType": number, //数据格式 0 未知 1 文本 2金额 3 数值 4百分比
    "headerText":string,
    "indicatorCode": number, //指标代码
    "indicatorCodeName":string,
    "name":string, //功能名称
    "sql": string //sql
  }[]
}

export const addChildReportList = (data: AddChildReportListDataType) => {
  return request('/performance/report/addChildColumn', {
    method: 'POST',
    data: { ...data }
  });
};

//获取报表列类型
export const getReportListTypeFromDic = () => {
  return request('/performance/dict/getDictDataList?current=1&pageSize=500&typeCode=11', {
    method: 'GET',
  });
};









