/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-03-03 16:31:27
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2023-06-06 18:00:24
 * @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 { request } from 'umi';

//获取table列表数据

export type BilingProjectTableItemDataType = {
  id:number;
  hospId:number;
  code:string;
  itemCode:string;
  itemName:string;
  itemTypeCode:string,
  itemType:string,
  orderPointValue:number,
  coreFlag:number,
  coreFlagName:string,
  source:number,
  sourceName:string
}


export const getBillProjectData = (params?:any) => {
  return request<{
       current:number;
       list:BilingProjectTableItemDataType[];
       pageSize:number;
       totalCount:number;
       totalPage:number;
  }>('/performance/item/getItemList', {
    method: 'GET',
    params:{...params}
  });
};

export const gainData = (data:any) => {
  return request('/performance/item/auto', {
    method: 'POST',
    data:{...data}
  });
};




//新增表格数据
export type AddTableDataType = {
  "itemCode":string, //收费项目代码
  "itemName":string, //收费项目名称
  "itemTypeCode":string, //收费项目类型代码
  "itemType":string, //收费项目类型名称
  "coreFlag": number, //是否核心项目 0 否 1 是 2不计
  "orderPointValue":number //点值
}
export const addData = (data:AddTableDataType) => {
  return request('/performance/item/addItem', {
    method: 'POST',
    data
  });
};



//编辑表格数据

export const editData = (data:AddTableDataType&{id:number}) => {
  return request('/performance/item/editItem', {
    method: 'POST',
    data
  });
};

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

//导入excel
export const importBillingProjectRelaFiles = (data:any) => {
  return request('/performance/item/importItem', {
    method: 'POST',
    data
  });
};



//获取excel导入模板
export const downloadTemplateReq = (compute_date:string) => {

  let path = `/gateway/performance/item/exportItem`;

  const userData = localStorage.getItem('userData');
  const { token = '' } = JSON.parse(userData as any);

  axios({
      method: 'get',
      url: path,
      responseType: 'blob',
      headers: { token },
  })
      .then(function (response) {
          //console.log({ 'chunk': response });
          const filename = decodeURI(response.headers["content-disposition"]);
          const objectUrl = URL.createObjectURL(
              new Blob([response.data], {
                  type: 'application/vnd.ms-excel',
              })
          )
          const link = document.createElement('a')
          // 设置导出的文件名称
          link.download = `${filename}` + '.xls'
          link.style.display = 'none'
          link.href = objectUrl
          link.click()
          document.body.appendChild(link)

      });



}









