/*
 * Author: 黎永顺
 * name: 新增校验规则
 * Description:
 * Date: 2022-07-04 11:53:34
 */
import React, {Component} from "react";
import {Button, Col, message, Row} from "antd";
import {WeaDialog, WeaFormItem, WeaInput, WeaTextarea} from "ecCom";
import "./index.less";

class AddValidRuleModal extends Component {
  constructor(props) {
    super(props);
    this.state = {
      value: "",
      name: ""
    };
  }

  handleChange = (value) => {
    this.setState({
      value
    });
  };
  handleSubmit = () => {
    if (!this.validateForm()) return;
    console.log(111);
  };
  validateForm = () => {
    const {name, value} = this.state;
    if (_.isEmpty(name)) {
      message.error("请填写公式名称");
      return false;
    }
    if (_.isEmpty(value)) {
      message.error("请填写公式内容");
      return false;
    }
    return true;
  };

  render() {
    const {value, name} = this.state;
    return (
      <WeaDialog
        className="addRule-wrapper"
        initLoadCss
        resize
        destroyBodyOnClose
        onCancel={() => this.props.onCancel()}
        title={"函数公式"}
        visible={this.props.visible}
        style={{width: 800, maxHeight: "70vh", overflow: "auto"}}
        hasScroll
        buttons={[
          <Button type="primary" onClick={this.handleSubmit}>保存</Button>,
          <Button type="ghost" onClick={() => this.props.onCancel()}>取消</Button>
        ]}
      >
        <Row className="addRule-top-row">
          <Col span={8}>
            <WeaFormItem labelCol={{span: 8}} wrapperCol={{span: 16}} className="iteamClass" label={"公式名称"}>
              <WeaInput hasBorder={true} value={name} onChange={(name) => this.setState({name})}
                        placeholder={"请输入公式名称"}/>
            </WeaFormItem>
          </Col>
        </Row>
        <Row>
          <Col span={24}>
            <WeaTextarea
              ref={(input) => this.contentProps = input}
              minRows={8}
              maxRows={8}
              value={value}
              onChange={(value) => this.handleChange(value)}
              noResize={true}
              style={{fontSize: "14px", lineHeight: 1.2}}
            />
          </Col>
        </Row>
        <Row>
          <Col span={12}>
          </Col>
          <Col span={12}>
          </Col>
        </Row>
      </WeaDialog>
    );
  }
}

export default AddValidRuleModal;