/*
 * Author: 黎永顺
 * Description:
 * Date: 2022-06-20 13:53:14
 * LastEditTime: 2022-06-21 13:30:00
 */
import React from "react";
import { Button, Col, Modal, Row } from "antd";
import { WeaError, WeaInput, WeaSelect, WeaDialog } from "ecCom";
import "./index.less";

export default class CopyFormModal extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      name: "",
      taxAgentId: ""
    };
  }

  render() {
    const { taxAgentStore } = this.props;
    const { taxAgentAdminOption } = taxAgentStore;
    return (
      <WeaDialog
        style={{width: 600}}
        visible={this.props.visible}
        title="复制账套"
        initLoadCss
        onCancel={() => this.props.onCancel()}
        className="copyModalWrapper"
        buttons={[
          <Button
            type="primary"
            onClick={() => {
              if (!this.state.name && !this.state.taxAgentId) {
                this.refs.weaNameError.showError();
                this.refs.weaTaxAgentError.showError();
                return;
              }
              if (!this.state.name) {
                this.refs.weaNameError.showError();
                return;
              }
              if (!this.state.taxAgentId) {
                this.refs.weaTaxAgentError.showError();
                return;
              }
              this.props.onSave({
                name: this.state.name,
                taxAgentId: this.state.taxAgentId
              });
            }}>
            保存
          </Button>
        ]}>
        <Row style={{ display: "flex", alignItems: "center" }}>
          <Col span={6}>账套名称</Col>
          <Col span={18}>
            <WeaError tipPosition="bottom" ref="weaNameError" error="账套名称不能为空">
              <WeaInput
                style={{ width: "200px" }}
                value={this.state.name}
                viewAttr={3}
                placeholder="请输入"
                onChange={value => {
                  this.setState({ name: value });
                  !value && this.refs.weaNameError.showError();
                }}
              />
            </WeaError>
          </Col>
        </Row>
        <Row style={{ display: "flex", alignItems: "center", marginTop: 20 }}>
          <Col span={6}>个税扣缴义务人</Col>
          <Col span={18}>
            <WeaError
              tipPosition="bottom"
              ref="weaTaxAgentError"
              error="请选择个税扣缴义务人">
              <WeaSelect
                viewAttr={3}
                showSearch // 设置select可搜索
                options={taxAgentAdminOption}
                value={this.state.taxAgentId}
                placeholder="请选择"
                onChange={value => {
                  this.setState({ taxAgentId: value });
                  !value && this.refs.weaTaxAgentError.showError();
                }}
              />
            </WeaError>
          </Col>
        </Row>
      </WeaDialog>
    );
  }
}
