/**
 * Created by mar105 on 2019-02-13.
 */
/* eslint-disable no-undef,import/first,prefer-destructuring,jsx-a11y/alt-text */
import React, { Component } from 'react';
import { Input } from 'antd-v4';
import * as commonUtils from '../../utils/utils';
import * as commonFunc from './commonFunc'; /* 通用方法 */
import AntdDraggableModal from '../Common/AntdDraggableModal';

const { TextArea } = Input;

export default class SlavesInfo extends Component {
  /**   构造函数   */
  constructor(props) {
    super(props);
    // this.handleTextareaChange = this.handleTextareaChange.bind(this);
    this.state = { textareaValue: '' };
    this.max = 200;
    this.min = 0;
  }
  componentWillReceiveProps(nextProps) {
    const { sInfoArr } = nextProps;
    /*   state和this属性赋值   */
    let textareaValue = '';
    if (commonUtils.isNotEmptyArr(sInfoArr)) {
      sInfoArr.forEach((item) => {
        textareaValue += item.sInfo;
      });
    }
    this.setState({ textareaValue });
    this.max = commonUtils.convertStrToNumber(commonUtils.isNotEmptyObject(nextProps.sMemoConfig) && commonUtils.isNotEmptyObject(nextProps.sMemoConfig.sMaxValue) ? nextProps.sMemoConfig.sMaxValue : 100); /*   最大值(数据格式:数字)   */
    this.min = commonUtils.convertStrToNumber(commonUtils.isNotEmptyObject(nextProps.sMemoConfig) && commonUtils.isNotEmptyObject(nextProps.sMemoConfig.sMinValue) ? nextProps.sMemoConfig.sMinValue : 0); /*   最小值(数据格式:数字)   */
  }
  handleOk = () => {
    this.props.onSaveState({
      bVisiblesInfo: false,
    });
  };

  handleCancel = () => {
    this.props.onSaveState({
      bVisiblesInfo: false,
    });
  };
  // /* 设置textareaValue */
  // handleTextareaChange(e) {
  //   this.setState({
  //     textareaValue: e.target.value,
  //   });
  // }
  /**   渲染   */
  render() {
    const { bVisiblesInfo, sInfoArr } = this.props;
    const sInfoTitle = commonFunc.showMessage(this.props.app.commonConst, 'sInfo');/* sInfo信息 */
    return (
      <div>
        {
          bVisiblesInfo ?
            <AntdDraggableModal
              width={1200}
              zIndex={1000}
              title={sInfoTitle}
              visible={bVisiblesInfo}
              onOk={this.handleOk}
              onCancel={this.handleCancel}
            >
              <div>
                {commonUtils.isNotEmptyArr(sInfoArr) ? (
                  <TextArea
                    value={this.state.textareaValue}
                    maxLength={this.max}
                    minLength={this.min}
                    rows={20}
                  />) : null}
              </div>
            </AntdDraggableModal>
          : ''
        }
      </div>
    );
  }
}
