import React, { Component } from "react";
import { Menu, message } from "antd";
import "../index.less";

class ExportMenu extends Component {
  componentDidMount() {
  }

  handleClick = ({ key }) => this[key]();
  handleExportAll = () => {
    const { selectedKey } = this.props;
    let runStatusList = _.upperCase(selectedKey);
    switch (selectedKey) {
      case "pending":
        runStatusList = _.upperCase(selectedKey);
        break;
      case "fixed":
        runStatusList = "FIXED,SUSPEND";
        break;
      case "suspend":
        runStatusList = _.upperCase(selectedKey);
        break;
      case "stop":
        runStatusList = "STOP_FROM_PENDING,STOP_FROM_SUSPEND";
        break;
      default:
        break;
    }
    let url = `${window.location.origin}/api/bs/hrmsalary/salaryArchive/exportList?ids=&runStatusList=${runStatusList}`;
    const { searchItemsValue } = this.props;
    const fileds = Object.keys(searchItemsValue);
    _.forEach(fileds, it => {
      url = `${url}&${it}=${searchItemsValue[it]}`;
    });
    window.open(url, "_self");
  };
  handleExportSelect = () => {
    const { selectedRowKeys } = this.props;
    if (selectedRowKeys.length === 0) {
      message.warning("未选择条目");
      return;
    }
    const url = `${window.location.origin}/api/bs/hrmsalary/salaryArchive/exportList?ids=${selectedRowKeys.join(",")}`;
    window.open(url, "_self");
  };

  render() {
    return (
      <Menu className="dropdownMenuWrapper" onClick={this.handleClick}>
        <Menu.Item key="handleExportAll">导出全部</Menu.Item>
        <Menu.Item key="handleExportSelect">导出选中</Menu.Item>
      </Menu>
    );
  }
}

export default ExportMenu;
