/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-03-03 16:31:27
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2023-11-02 15:03:09
 * @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 = {
  permil: string;
  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;
  }>('/costAccount/report/getColumnList', {
    method: 'GET',
    params: { ...params },
  });
};

//新增报表
export type AddTableDataType = {
  name: string; //列名称
  headerText: string; //列标题
  type: string; //报表列类型 取字典类型
  dataType: number; //0 未知 1 文本 3 数值 2百分比
  dataSource: number; //数据来源 1 计算公式 2自定义SQL
  formula?: string; //计算公式
  sql?: string; //自定义SQL
  decimalPlace?: number; //小数位
  permil?: string; //是否有千分号
};

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

//编辑表格数据

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

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

//删除表格操作
export const delData = (id: string) => {
  return request('/costAccount/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('/costAccount/report/getChildColumnList', {
    method: 'GET',
    params: { columnCode },
  });
};

//添加子列报表列

export type AddChildReportListDataType = {
  parentCode: string;
  childColumnList: {
    id: number; //主键
    hospId: number; //医院id
    parentColumnCode: number; //主列代码
    code: number; //列代码
    name: string; //列名
    headerText: string; //列标题
    createUser: string; //创建人
    createTime: string; //创建时间
    updateUser: string; //更新人
    updateTime: string; //更新时间
    deleteUser: string; //删除人
    deleteTime: string; //删除时间
    delFlag: number; //删除标志  0正常 1作废
  }[];
};

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

//获取报表列类型
export const getReportListType = () => {
  return request('/costAccount/report/getColumnType', {
    method: 'GET',
  });
};
