/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-03-03 16:31:27
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2024-12-11 14:16:08
 * @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 axios from 'axios';
import { downloadExcel } from '@/utils/download';
import { request } from 'umi';

//获取table列表数据

export const getCalcPageTableData = (params: any) => {
  const { calcPageKey, ...next } = params;

  if (calcPageKey == 'unitPersonnelCostCalc') {
    return request('/costAccount/calculate/empCostCalculateList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'patientCostCalc') {
    return request('/costAccount/calculate/patientCostCalculateList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'chargeItemCostCalc') {
    return request('/costAccount/calculate/itemCostCalculateList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'diseaseCostCalculation') {
    return request('/costAccount/calculate/diseaseCostCalculateList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'DRG_DIPCostCalc') {
    return request('/costAccount/calculate/groupCostCalculateList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'clinicalPathway') {
    return request('/costAccount/calculate/clinicalPathwayCostCalculateList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'medicalOrderItem') {
    return request('/costAccount/calculate/orderCostCalculateList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'beforeCollectionSearch') {
    return request('/costAccount/costincomegroup/list', {
      method: 'GET',
      params: { ...next, dateTime: next.computeDate, computeDate: null },
    });
  }
  if (calcPageKey == 'incomeCollection') {
    return request('/costAccount/incomeCollection/getCollections', {
      method: 'GET',
      params: {
        ...next,
        date: next.computeDate.replace('-', ''),
        computeDate: null,
      },
    });
  }
  if (calcPageKey == 'afterCollectionSearch') {
    return request('/costAccount/incomeCollection/collectList', {
      method: 'GET',
      params: {
        ...next,
        date: next.computeDate.replace('-', ''),
        computeDate: null,
      },
    });
  }
  if (calcPageKey == 'beforeCostShareSearch') {
    return request('/costAccount/costcostinggroup/queryStartAllocation', {
      method: 'GET',
      params: { ...next, date: next.computeDate, computeDate: null },
    });
  }
  if (calcPageKey == 'costShare') {
    return request('/costAccount/costcostinggroup/allocationList', {
      method: 'GET',
      params: { ...next, date: `${next.computeDate}-01`, computeDate: null },
    });
  }
  if (calcPageKey == 'afterCostShareSearch') {
    return request('/costAccount/costcostinggroup/queryAfterAllocation', {
      method: 'GET',
      params: { ...next, year: `${next.computeDate}-01`, computeDate: null },
    });
  }
  if (calcPageKey == 'departmentCostCalculate') {
    return request('/costAccount/costdepartmentprofit/list', {
      method: 'GET',
      params: { ...next, date: `${next.computeDate}-01`, computeDate: null },
    });
  }
  if (calcPageKey == 'wholeHospCostCalculate') {
    return request('/costAccount/hospProfitAndLoss/getHospProfitList', {
      method: 'GET',
      params: { ...next, computeDate: `${next.computeDate}-01` },
    });
  }
  if (calcPageKey == 'costShareReportTable') {
    return request('/costAccount/costcostinggroup/afterAllocationFormList', {
      method: 'GET',
      params: { ...next, date: `${next.computeDate}-01`, computeDate: null },
    });
  }
  if (calcPageKey == 'wholeHospOperatingReport') {
    return request('/costAccount/hospProfitAndLoss/hospReports', {
      method: 'GET',
      params: { ...next, date: `${next.computeDate}-01`, computeDate: null },
    });
  }
  if (calcPageKey == 'departmentOperatingReport') {
    return request('/costAccount/departmentprofitfile/list', {
      method: 'GET',
      params: { ...next, date: `${next.computeDate}-01`, computeDate: null },
    });
  }
  if (calcPageKey == 'medicalMaterialCostCalc') {
    return request('/costAccount/calculate/drugMaterialCostCalculateList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'projectShareParamsCalc') {
    return request('/costAccount/calculate/getShareParamCostList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'projectCostCalc') {
    return request('/costAccount/calculate/getItemCostList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'patientItemCalc') {
    return request('/costAccount/calculate/getPatientItemCostList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'standardItemCostCalc') {
    return request('/costAccount/calculate/getStandItemCostList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'patientStandItemCostCalc') {
    return request('/costAccount/calculate/getPatientStandItemCostList', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'standItemShareCostCalc') {
    return request('/costAccount/calculate/getStandShareParamCostList', {
      method: 'GET',
      params: { ...next },
    });
  }
  // 医院科室直接成本表（医疗成本）
  if (calcPageKey == 'deptDirectMedicalCost') {
    return request('/costAccount/standardReport/getDeptDirectMedicalCost', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'deptFullDirectCost') {
    return request('/costAccount/standardReport/getDeptFullDirectCost', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'clinicalDeptMedicalCost') {
    return request('/costAccount/standardReport/getClinicalDeptMedicalCost', {
      method: 'GET',
      params: { ...next },
    });
  }
  if (calcPageKey == 'clinicalDeptFullCost') {
    return request('/costAccount/standardReport/getClinicalDeptFullCost', {
      method: 'GET',
      params: { ...next },
    });
  }
  // 临床服务类科室全成本构成分析表
  if (calcPageKey == 'clinicalDeptFullCostAnalysis') {
    return request(
      '/costAccount/standardReport/getClinicalDeptFullCostAnalysis',
      {
        method: 'GET',
        params: { ...next },
      },
    );
  }
  // 医院科室成本分摊汇总表
  if (calcPageKey == 'deptCostAllocationSummary') {
    return request(
      '/costAccount/standardReport/getHospitalDeptCostAllocation',
      {
        method: 'GET',
        params: { ...next },
      },
    );
  }
  // 医院诊次成本构成表
  if (calcPageKey == 'hospitalVisitCostComposition') {
    return request(
      '/costAccount/standardReport/getHospitalVisitCostComposition',
      {
        method: 'GET',
        params: { ...next },
      },
    );
  }
  // 医院科室诊次成本表
  if (calcPageKey == 'hospitalDeptVisitCost') {
    return request('/costAccount/standardReport/getHospitalDeptVisitCost', {
      method: 'GET',
      params: { ...next },
    });
  }
  // 医院床日成本构成表
  if (calcPageKey == 'hospitalBedDayCostComposition') {
    return request(
      '/costAccount/standardReport/getHospitalBedDayCostComposition',
      {
        method: 'GET',
        params: { ...next },
      },
    );
  }
  // 医院科室床日成本表
  if (calcPageKey == 'hospitalDeptBedDayCost') {
    return request('/costAccount/standardReport/getHospitalDeptBedDayCost', {
      method: 'GET',
      params: { ...next },
    });
  }
  // 医院医疗服务项目成本汇总表
  if (calcPageKey == 'hospitalServiceProjectCost') {
    return request(
      '/costAccount/standardReport/getHospitalServiceProjectCost',
      {
        method: 'GET',
        params: { ...next },
      },
    );
  }
  // 医院医疗服务项目成本明细表
  if (calcPageKey == 'medicalServiceCostDetail') {
    return request('/costAccount/standardReport/getMedicalServiceCostDetail', {
      method: 'GET',
      params: { ...next },
    });
  }
  // 医院病种成本明细表
  if (calcPageKey == 'diseaseCostDetail') {
    return request('/costAccount/standardReport/getDiseaseCostDetailByPage', {
      method: 'GET',
      params: { ...next },
    });
  }
  // 医院DRG成本明细表
  if (calcPageKey == 'drgCostDetail') {
    return request('/costAccount/standardReport/getDrgCostDetail', {
      method: 'GET',
      params: { ...next },
    });
  }
  // 医院DRG成本构成明细表
  if (calcPageKey == 'drgCostCompositionDetail') {
    return request('/costAccount/standardReport/getDrgCostCompositionDetail', {
      method: 'GET',
      params: { ...next },
    });
  }
  // 病种成本构成明细表
  if (calcPageKey == 'diseaseCostCompositionDetail') {
    return request(
      '/costAccount/standardReport/getDiseaseCostCompositionDetailByPage',
      {
        method: 'GET',
        params: { ...next },
      },
    );
  }
  // 服务单元病种成本构成明细表
  if (calcPageKey == 'deptDiseaseCostCompositionDetail') {
    return request(
      '/costAccount/standardReport/getDeptDiseaseCostCompositionDetailByPage',
      {
        method: 'GET',
        params: { ...next },
      },
    );
  }
  // 医院服务单元DRG成本构成明细表
  if (calcPageKey == 'deptDrgCostCompositionDetail') {
    return request(
      '/costAccount/standardReport/getDeptDrgCostCompositionDetail',
      {
        method: 'GET',
        params: { ...next },
      },
    );
  }
};

//计算
export const calculateReq = (
  computeDate: string,
  calcPageKey: string | undefined,
  type?: string,
) => {
  if (calcPageKey == 'unitPersonnelCostCalc') {
    return request('/costAccount/calculate/empCostCalculate', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'patientCostCalc') {
    return request('/costAccount/calculate/patientCostCalculate', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'patientItemCalc') {
    return request('/costAccount/calculate/computePatientItemCost', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'chargeItemCostCalc') {
    return request('/costAccount/calculate/itemCostCalculate', {
      method: 'POST',
      params: { computeDate, type },
    });
  }
  if (calcPageKey == 'diseaseCostCalculation') {
    return request('/costAccount/calculate/diseaseCostCalculate', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'DRG_DIPCostCalc') {
    return request('/costAccount/calculate/groupCostCalculate', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'clinicalPathway') {
    return request('/costAccount/calculate/clinicalPathwayCostCalculate', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'medicalOrderItem') {
    return request('/costAccount/calculate/orderCostCalculate', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'departmentCostCalculate') {
    return request('/costAccount/costdepartmentprofit/setDepartmentProfit', {
      method: 'POST',
      params: { date: `${computeDate}-01` },
    });
  }
  if (calcPageKey == 'wholeHospCostCalculate') {
    return request('/costAccount/hospProfitAndLoss/calc', {
      method: 'POST',
      params: { date: `${computeDate}-01`, reportType: type },
    });
  }
  if (calcPageKey == 'medicalMaterialCostCalc') {
    return request('/costAccount/calculate/drugMaterialCostCalculate', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'projectShareParamsCalc') {
    return request('/costAccount/calculate/computeShareParamCost', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'projectCostCalc') {
    return request('/costAccount/calculate/computeItemCost', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'standardItemCostCalc') {
    return request('/costAccount/calculate/computeStandItemCost', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'patientStandItemCostCalc') {
    return request('/costAccount/calculate/computeStandPatientItemCost', {
      method: 'POST',
      params: { computeDate },
    });
  }
  if (calcPageKey == 'standItemShareCostCalc') {
    return request('/costAccount/calculate/computeStandShareParamCost', {
      method: 'POST',
      params: { computeDate },
    });
  }
};

//获取科室列表
export const getCostProjecttList = (params: any) => {
  const { productName, current, pageSize } = params;
  return request('/costAccount/product/list', {
    method: 'GET',
    params: {
      name: productName,
      current,
      pageSize,
    },
  });
};

//开始归集
export const startIncomeCollection = (params: any) => {
  const { year, month } = params;
  return request('/costAccount/incomeCollection/collect', {
    method: 'POST',
    params: { year, month },
  });
};

//撤销归集
export const cancelIncomeCollection = (body: any) => {
  const { year, month } = body;
  return request('/costAccount/incomeCollection/cancelCollect', {
    method: 'POST',
    params: { year, month },
  });
};

//开始分摊
export const startAllocation = (body: any) => {
  return request('/costAccount/costcostinggroup/startAllocation', {
    method: 'POST',
    data: body,
  });
};

//撤销分摊
export const cancelAllocation = (body: any) => {
  return request('/costAccount/costcostinggroup/cancelAllocation', {
    method: 'POST',
    params: body,
  });
};

//获取报表数据列表
export const getAfterCostShareSearchTableData = (params: any) => {
  return request('/costAccount/costcostinggroup/queryAfterAllocationForm', {
    method: 'GET',
    params: { ...params },
  });
};

//获取收入归集后报表数据列表
export const getAfterIncomeCollectionTableData = (params: any) => {
  return request('/costAccount/incomeCollection/collectDataForm', {
    method: 'GET',
    params: { ...params },
  });
};

//下载报表
export const downloadReportHandle = (params: any) => {
  return request('/costAccount/excel/getShareReportTemplate', {
    method: 'GET',
    params: { ...params },
  });
};

//生成报表数据
export const generateReportHandle = (params: any, path: string) => {
  return request(path, {
    method: 'POST',
    params: { ...params },
  });
};

//查询用户有权限的损益报表
export const getUserHasReports = () => {
  return request('/costAccount/userReportRight/getUserReports', {
    method: 'GET',
    // params:{...params},
  });
};

//下载excel
export const downloadTemplateReq = async (pathStr: string, data: any) => {
  // 统一封装下载，减少页面内样板
  return downloadExcel({ path: pathStr, params: data });
};
