/**
 * 薪资代发下载模板
 */
import React, { Component } from "react";
import "../financialWallet.less";
import { withRouter } from "dva/router";
import { host } from "../../../services/api";
import axios from "axios";
import store from "store";
@withRouter
export default class Download extends Component {
  constructor(props, context) {
    super(props, context);
    this.state = {};
  }
  download() {
    axios({
      method: "get",
      url: `${host}/task/com/grant/export-offline-grant-temp`, //【薪资代发】导出薪资线下代发模板
      responseType: "blob",
      headers: {
        access_token: store.get("saas")["access_token"],
        Accesstoken: store.get('saas')['access_token']|| sessionStorage.userV5Token,

      }
    }).then(data => {
      if (!data) {
        return;
      }
      let url = window.URL.createObjectURL(data.data);
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = url;
      link.setAttribute("download", `薪资代发数据模板.xls`);
      document.body.appendChild(link);
      link.click();
    });
  }
  render() {
    return <a onClick={() => this.download()}>《薪资代发数据模板》下载</a>;
  }
}
