import React, { Component } from "react";
import * as API from "../../../apis/payrollFiles";
import { Menu, message, Modal } from "antd";
import "../index.less";

class AllWithoutPay extends Component {
  handleClick = ({ key }) => {
    const { selectedRowKeys = [], refreshList } = this.props;
    if (key === "batchWithoutpay") {
      if (selectedRowKeys.length === 0) {
        message.warning("未选择条目");
        return;
      }
      API.gotoStop(selectedRowKeys).then(({ status, data, errormsg }) => {
        if (status) {
          const { msg } = data;
          message.info(msg || "操作成功!");
          refreshList();
        } else {
          message.error(errormsg || "操作失败!");
        }
      });
    } else {
      const { pageInfo } = this.props;
      if (pageInfo.total === 0) {
        message.warning("您没有需要处理的待停薪人员！");
        return;
      }
      Modal.warning({
        title: "信息确认",
        content: `确定要将所有待停薪人员（共${pageInfo.total}条数据）设为停薪人员吗？`,
        onOk: () => {
          API.allGotoStop({}).then(({ status, data, errormsg }) => {
            if (status) {
              const { msg } = data;
              message.info(msg || "操作成功!");
              refreshList();
            } else {
              message.error(errormsg || "操作失败!");
            }
          });
        }
      });
    }
  };

  render() {
    return (
      <Menu className="dropdownMenuWrapper" onClick={this.handleClick}>
        <Menu.Item key="allWithoutpay">全部停薪</Menu.Item>
        <Menu.Item key="batchWithoutpay">批量停薪</Menu.Item>
      </Menu>
    );
  }
}

export default AllWithoutPay;
