/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-03-03 16:31:27
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2024-06-12 11:26:39
 * @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 { Key } from 'react';
import { request } from 'umi';

//获取table列表数据

export type TableDataType = {
  id: number;
  hospId: number;
  code: number;
  name: string;
  type: string;
  price: number;
  kcCodeName: string;
  kcCode: string;
  nationalCode: string;
  standItemCode: string;
  standItemName: string;
};

export const getTableDataReq = (params?: any) => {
  return request<{
    current: number;
    list: TableDataType[];
    pageSize: number;
    totalCount: number;
    totalPage: number;
  }>('/costAccount/setting/getItemList', {
    method: 'GET',
    params: { ...params },
  });
};

//新增
export type AddTableDataType = {
  code: string;
  name: string;
  type: string;
  price: number;
  nationalCode: string;
  standItemCode: string;
  standItemName: string;
};

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

//导入数据
export const importDataPost = (data: any) => {
  return request('/costAccount/setting/importItem', {
    method: 'POST',
    data,
  });
};

//编辑表格数据

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

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

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

//对照
export const mapItemAndStandItem = () => {
  return request(
    '/costAccount/setting/matchItemAndStandItem?progressKey=ITEM_BATCH_MATCH',
    {
      method: 'POST',
    },
  );
};

//获取对照列表
export const getEmpsByItemCode = (itemCode: string, departmentCode: string) => {
  return request('/costAccount/setting/getItemEmpMap', {
    method: 'GET',
    params: { itemCode, departmentCode },
  });
};
export const getEquipByItemCode = (
  itemCode: string,
  departmentCode: string,
) => {
  return request('/costAccount/setting/getItemEquipmentMap', {
    method: 'GET',
    params: { itemCode, departmentCode },
  });
};
export const getSpaceByItemCode = (
  itemCode: string,
  departmentCode: string,
) => {
  return request('/costAccount/setting/getItemSpaceMap', {
    method: 'GET',
    params: { itemCode, departmentCode },
  });
};
export const getNoValuationDrugByItemCode = (
  itemCode: string,
  departmentCode: string,
) => {
  return request('/costAccount/setting/getItemNoValuationDrugMaterialMap', {
    method: 'GET',
    params: { itemCode, departmentCode },
  });
};
export const getValuationDrugByItemCode = (
  itemCode: string,
  departmentCode: string,
) => {
  return request('/costAccount/setting/getItemValuationDrugMaterialMap', {
    method: 'GET',
    params: { itemCode, departmentCode },
  });
};

//添加抽屉表格数据

export const addDrawerTableData = (data: any, tabKey: number) => {
  let url: string = '';
  if (tabKey == 1) {
    url = '/costAccount/setting/addItemEmpMap';
  }
  if (tabKey == 2) {
    url = '/costAccount/setting/addItemEquipmentMap';
  }
  if (tabKey == 3) {
    url = '/costAccount/setting/addItemSpaceMap';
  }

  return request(url, {
    method: 'POST',
    data,
  });
};

//编辑抽屉表格数据

export const editDrawerTableData = (data: any, tabKey: number) => {
  let url: string = '';
  if (tabKey == 1) {
    url = '/costAccount/setting/editItemEmpMap';
  }
  if (tabKey == 2) {
    url = '/costAccount/setting/editItemEquipmentMap';
  }
  if (tabKey == 3) {
    url = '/costAccount/setting/editItemSpaceMap';
  }
  if (tabKey == 4) {
    url = '/costAccount/setting/editItemValuationDrugMaterialMap';
  }
  if (tabKey == 5) {
    url = '/costAccount/setting/editItemNoValuationDrugMaterialMap';
  }

  return request(url, {
    method: 'POST',
    data,
  });
};

//删除抽屉表格数据

export const delDrawerTableData = (id: Key, tabKey: number) => {
  let url: string = '';
  if (tabKey == 1) {
    url = '/costAccount/setting/deleteItemEmpMap';
  }
  if (tabKey == 2) {
    url = '/costAccount/setting/deleteItemEquipmentMap';
  }
  if (tabKey == 3) {
    url = '/costAccount/setting/deleteItemSpaceMap';
  }
  if (tabKey == 4) {
    url = '/costAccount/setting/deleteItemValuationDrugMaterialMap';
  }
  if (tabKey == 5) {
    url = '/costAccount/setting/deleteItemNoValuationDrugMaterialMap';
  }

  return request(url, {
    method: 'POST',
    params: { id },
  });
};

//获取可添加药材列表
export const getAddableTableData = (
  type: number,
  itemCode: string,
  name?: string,
) => {
  return request('/costAccount/setting/getItemData', {
    method: 'GET',
    params: { type, itemCode, name },
  });
};

//添加不计价/计价药材对照
export const addDrugTableData = (data: any, type: number) => {
  let url = undefined;
  if (type == 4) {
    url = '/costAccount/setting/addItemValuationDrugMaterialMap';
  }
  if (type == 5) {
    url = '/costAccount/setting/addItemNoValuationDrugMaterialMap';
  }
  return request(url as string, {
    method: 'POST',
    data: data,
  });
};

// //编辑不计价/计价药材对照
// export const editDrugTableData = (data:any,type:number) => {
//   let url = undefined;
//   if(type == 4){
//     url = '/costAccount/setting/editItemValuationDrugMaterialMap'
//   }
//   if(type == 5){
//     url = '/costAccount/setting/editItemNoValuationDrugMaterialMap'
//   }
//   return request(url as string, {
//     method: 'POST',
//     data:data
//   });
// };

//批量删除不计价/计价药材对照
export const batchDelDrugTableData = (data: number[], type: number) => {
  let url = undefined;
  if (type == 4) {
    url = '/costAccount/setting/batchDeleteItemValuationDrugMaterialMap';
  }
  if (type == 5) {
    url = '/costAccount/setting/batchDeleteItemNoValuationDrugMaterialMap';
  }
  return request(url as string, {
    method: 'POST',
    data: data,
  });
};

//获取单个收费项目信息
export const getSingleItem = (itemCode: string, departmentCode: string) => {
  return request('/costAccount/setting/getSingleItem', {
    method: 'GET',
    params: { itemCode, departmentCode },
  });
};

//获取所有需要匹配的项
export const getAllNeedMatchItems = () => {
  return request('/costAccount/setting/getSingleItemList', {
    method: 'GET',
  });
};

//获取标准项目及推荐项目
export const getReferralMatch = (itemCode: string, departmentCode: string) => {
  return request('/costAccount/setting/getReferralMatch', {
    method: 'GET',
    params: { itemCode, departmentCode },
  });
};

//获取对照计数数据
export const getMatchCount = () => {
  return request('/costAccount/setting/getMatchCount', {
    method: 'GET',
  });
};

//匹配
export const matchRequest = (
  itemCode: string,
  standItemCode: string,
  type: number,
  departmentCode: string,
) => {
  return request('/costAccount/setting/matchItem', {
    method: 'POST',
    params: { itemCode, standItemCode, type, departmentCode },
  });
};

//获取科室列表
export const getDepartmentListsReq = (params: any) => {
  return request('/centerSys/sysdepartment/getList', {
    method: 'GET',
    params: { ...params },
  });
};
