/* eslint-disable no-trailing-spaces */ import React, { Component } from 'react'; import { Form } from '@ant-design/compatible'; // import '@ant-design/compatible/assets/index.css'; import { Input } from 'antd-v4'; import styles from '../../index.less'; const FormItem = Form.Item; class ShowTableEditComponent extends Component { constructor(props) { super(props); this.state = { value: this.props.value, gdsformconst: this.props.gdsformconst, editable: this.props.editable || false, must: this.props.must, }; } componentWillReceiveProps(nextProps) { const { value, must } = nextProps; if (value !== '') { this.setState({ value, must }); } if (nextProps.editable !== this.state.editable) { this.setState({ editable: nextProps.editable }); if (nextProps.editable) { this.cacheValue = this.state.value; } } if (nextProps.status && nextProps.status !== this.props.status) { if (nextProps.status === 'save') { this.props.onChange(this.state.value); } else if (nextProps.status === 'cancel') { this.setState({ value: this.cacheValue, validateStatus: 'success', errorMsg: null }); this.props.onChange(this.cacheValue); } } } shouldComponentUpdate(nextProps, nextState) { if (nextState.value !== nextProps.value) return true; return nextProps.editable !== this.state.editable || nextState.value !== this.state.value; } handlevalidate = (value) => { if (value !== '') { return { validateStatus: 'success', errorMsg: null, }; } const textName = this.state.gdsformconst.filter(item => (item.sName === 'required'))[0].showName; return { validateStatus: 'error', errorMsg: textName, }; }; handleChange(e) { const { value } = e.target; this.setState({ value }); // if (this.props.must === false) { // return; // } this.setState({ validateStatus: this.handlevalidate(value).validateStatus, errorMsg: this.handlevalidate(value).errorMsg, }); this.props.onChange(value); } render() { const { editable, value, must } = this.state; const textName = this.state.gdsformconst.filter(item => (item.sName === 'required'))[0].showName; return (