/*
 * Author: 黎永顺
 * Description: 起始编号及预留编号设置
 * Date: 2022-05-17 15:51:41
 * LastEditTime: 2022-06-14 18:29:38
 */
import React, { Component, Fragment } from "react";
import { Button, Modal } from "antd";
import StartNumberSetting from "./startNumberSetting";
import ReservedNumberSetting from "./reservedNumberSetting";
import { WeaFormItem, WeaDialog, WeaMoreButton } from "ecCom";
import { i18n } from "../../../../public/i18n";
class StartReservedNumberSet extends Component {
  constructor() {
    super();
    this.state = {
      reservedAddVisible: true,
      dialogProps: {
        type: "start",
        visible: false,
        title: "",
      },
    };
  }
  handleClickStartNumber = (type) => {
    const { onSet } = this.props;
    const { dialogProps } = this.state;
    onSet && onSet(type);
    this.setState({
      dialogProps: {
        ...dialogProps,
        type,
        visible: true,
        title: type === "start" ? "起始编号" : "预留编号",
      },
    });
  };
  handleChangeTable = (newColumns, datas) => {
    const { onChange } = this.props;
    onChange && onChange(newColumns, datas);
  };
  handleSave = () => {
    const { onSaveStartNumber } = this.props;
    Modal.confirm({
      title: "信息确认",
      content: `是否保存数据？`,
      onOk: () => {
        onSaveStartNumber && onSaveStartNumber();
      },
      onCancel: () => { },
    });
  };
  handleClose = () => {
    this.setState({
      dialogProps: {
        ...this.state.dialogProps,
        visible: false,
      },
    });
  };
  handleCloseReservedModal = () => {
    this.setState({
      reservedAddVisible: false,
    });
  };

  render() {
    const { dialogProps, reservedAddVisible } = this.state;
    const { type } = dialogProps;
    const {
      onSet,
      companyInfo,
      startNumberInfo,
      onDeleteReservedNumber,
      onAddReservedNumber,
      onSubmitReservedNumber,
      onSearchReservedNumberset,
      loading,
    } = this.props;
    return (
      <Fragment>
        <WeaFormItem
          label="起始编号"
          labelCol={{ span: 8 }}
          wrapperCol={{ span: 16 }}>
          <i
            className="icon-coms-Flow-setting"
            onClick={() => this.handleClickStartNumber("start")}></i>
        </WeaFormItem>
        <WeaFormItem
          label="预留编号"
          labelCol={{ span: 8 }}
          wrapperCol={{ span: 16 }}>
          <i
            className="icon-coms-Flow-setting"
            onClick={() => this.handleClickStartNumber("reserved")}></i>
        </WeaFormItem>
        {/* 起始/预留编号设置 */}
        <WeaDialog
          onCancel={this.handleClose}
          icon="icon-coms-hrm"
          iconBgcolor="#217346"
          {...dialogProps}
          hasScroll
          style={{ width: 900, height: 480 }}
          buttons={
            type === "start"
              ? [
                <Button
                  ecId={`${(this && this.props && this.props.ecId) || ""
                    }_Button@jd6baw`}
                  onClick={this.handleSave}
                  type="primary">
                  {i18n.button.save()}
                </Button>,
                <WeaMoreButton
                  ecId={`${(this && this.props && this.props.ecId) || ""
                    }_WeaMoreButton@e4f4n1`}
                />,
              ]
              : [
                <WeaMoreButton
                  ecId={`${(this && this.props && this.props.ecId) || ""
                    }_WeaMoreButton@e4f4n1`}
                />,
              ]
          }>
          {type === "start" ? (
            <StartNumberSetting
              onSet={onSet}
              companyInfo={companyInfo}
              startNumberInfo={startNumberInfo}
              onChange={this.handleChangeTable}
            />
          ) : (
            <ReservedNumberSetting
              addVisible={reservedAddVisible}
              onDeleteReservedNumber={onDeleteReservedNumber}
              onAddReservedNumber={onAddReservedNumber}
              onSubmitReservedNumber={onSubmitReservedNumber}
              onSearchReservedNumberset={onSearchReservedNumberset}
              loading={loading}
              onChangeAddVisible={() =>
                this.setState({ reservedAddVisible: true })
              }
            />
          )}
        </WeaDialog>
      </Fragment>
    );
  }
}

export default StartReservedNumberSet;
