/*
  * 薪酬迁入结果展示
  *
  * @Author:    黎永顺
  * @Date:      2024/8/16
  * @Wechat:
  * @Email:     971387674@qq.com
  * @description:
*/
import React, { Component } from "react";
import { WeaLocaleProvider, WeaTable } from "ecCom";

const getLabel = WeaLocaleProvider.getLabel;

class MoveInResult extends Component {
  downloadTxtfile = (value, type) => {
    if (!value) return;
    const element = document.createElement("a");
    const file = new Blob([value], { type: "text/plain" });
    element.href = URL.createObjectURL(file);
    element.download = `导入${type}信息.txt`;
    document.body.appendChild(element);
    element.click();
  };

  render() {
    const { dataSource } = this.props;
    return (
      <WeaTable
        columns={[
          { title: getLabel(111, "导入信息"), dataIndex: "message" },
          {
            title: getLabel(111, "下载信息"), dataIndex: "download", width: 250,
            render: (text, record) => (<React.Fragment>
              <span
                style={{ marginRight: 16, color: "#0BB746", cursor: "pointer", display: "inline-block", minWidth: 60 }}
                onClick={() => this.downloadTxtfile(record.success.join("\n"), getLabel(111, "成功"))}>
                <i className="iconfont icon-successful"/><span
                style={{ marginLeft: 8 }}>{record.success.length}</span></span>
              <span
                style={{ marginRight: 16, color: "#E6960C", cursor: "pointer", display: "inline-block", minWidth: 60 }}
                onClick={() => this.downloadTxtfile(record.warning.join("\n"), getLabel(111, "警告"))}><i
                className="iconfont icon-warning"/><span style={{ marginLeft: 8 }}>{record.warning.length}</span></span>
              <span style={{ color: "#CF3736", cursor: "pointer", display: "inline-block", minWidth: 60 }}
                    onClick={() => this.downloadTxtfile(record.error.join("\n"), getLabel(111, "错误"))}><i
                className="iconfont icon-error"/><span style={{ marginLeft: 8 }}>{record.error.length}</span></span>
            </React.Fragment>)
          }
        ]}
        dataSource={dataSource} pagination={false} bordered scroll={{ y: `calc(100vh - 333px)` }}
      />
    );
  }
}

export default MoveInResult;
