/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-03-03 16:31:27
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2024-03-22 17:57:15
 * @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';
import axios from 'axios';

//获取table列表数据

export const getData = (params) => {
  return request('/costAccount/computeImport/getPatientInfoList', {
    method: 'GET',
    params: { ...params },
  });
};

//导入数据
export const importPatientInfoDataPost = (data) => {
  return request('/costAccount/computeImport/importPatientInfo', {
    method: 'POST',
    data,
  });
};

//下载模板

export const downloadTemplateReq = () => {
  let path = '/gateway/costAccount/computeImport/exportPatientInfo';

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

  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);
  });
};
