/**
 * 禅道 30031 已处理的页面增加导出按钮
 * */
import { message } from 'antd';
import React from 'react';
import { downloadFile } from '@/webPublic/one_stop_public/Table/globalFunction';
import { getToken } from '@/webPublic/one_stop_public/utils/token';
import { giveBase16EnCode } from '@/webPublic/one_stop_public/Base16';

export default function exportHandledInfo({
                                            columns = [],
                                            appId = '1492048888356405248',
                                            type = 'handled',
                                          }) {
  const headers = columns.filter((g) => {
    return g.dataIndex !== 'operationDiy';
  })
    .map((g) => {
      if (g.title === '流程审核状态') {
        return {
          key: 'formStatusName',
          title: g.title,
        };
      }
      return {
        key: g.dataIndex,
        title: g.title,
      };
    });
  const data = {
    appId,
    type,
    headers: JSON.stringify(headers),
    token: getToken(),
  };
  if (appId) {
    message.info('正在导出文件,请耐心等待');
    let url = window.CONFIG.OAUTH_ACTION_PATH + '/UnifiedAppFormApi/exportData';
    // uaaRequest('/UnifiedAppFormApi/getHandledPage', data);
    // downloadFile(url, data);
    console.log(data, url);
    giveBase16EnCode(data, url)
      .then((newData) => {
        if (typeof newData === 'object' && newData.url && newData.datas) {
          // newData.datas.rbin = true;
          newData.datas.token = getToken();
          return downloadFile(newData.url, newData.datas);
        }
        // downloadFile(url, data);
      });

  }
}
