| | |
| | | } |
| | | |
| | | return editing ? ( |
| | | <Form.Item style={{ margin: 0 }}> |
| | | <Form.Item style={{ margin: '0 -5px 0 -5px' }}> |
| | | {form.getFieldDecorator(dataIndex, { |
| | | rules: [ |
| | | { |
| | |
| | | class EditTable extends Component { |
| | | static propTpyes = { |
| | | type: PropTypes.string, // 表单类型 |
| | | module: PropTypes.string, // 元素类型 |
| | | linkSubFields: PropTypes.array, // 关联字段 |
| | | transfield: PropTypes.object, // 表单字段名称 |
| | | onChange: PropTypes.func // 数据变化 |
| | |
| | | _data.splice(index + 1, 0, record) |
| | | } |
| | | |
| | | this.setState({ |
| | | dataSource: _data |
| | | }, () => { |
| | | this.props.onChange(_data) |
| | | }) |
| | | } |
| | | |
| | | handleHide = (record) => { |
| | | let _data = this.state.dataSource.map(item => { |
| | | if (item.key === record.key) { |
| | | item.Hide = !item.Hide |
| | | } |
| | | return item |
| | | }) |
| | | this.setState({ |
| | | dataSource: _data |
| | | }, () => { |
| | |
| | | <div style={{fontSize: '15px'}}> |
| | | <span className="operation-btn" onClick={() => this.handleUpDown(record, 'up')} style={{color: '#1890ff'}}><ArrowUpOutlined /></span> |
| | | <span className="operation-btn" onClick={() => this.handleUpDown(record, 'down')} style={{color: '#ff4d4f'}}><ArrowDownOutlined /></span> |
| | | <span className="operation-btn" title="显示/隐藏" onClick={() => this.handleHide(record)} style={{color: 'rgb(142, 68, 173)'}}><SwapOutlined /></span> |
| | | <Popconfirm |
| | | title="确定删除吗?" |
| | | overlayClassName="popover-confirm" |
| | |
| | | } |
| | | } |
| | | |
| | | handleEmpty = (e) => { |
| | | e.stopPropagation() |
| | | const { linkSubFields, module } = this.props |
| | | const { dataSource } = this.state |
| | | |
| | | if (dataSource.filter(item => item.Value === '').length > 0) { |
| | | message.warning('Value为空已存在!') |
| | | return |
| | | } |
| | | const newData = { |
| | | key: Utils.getuuid(), |
| | | Value: '', |
| | | Text: module === 'form' ? '空' : '全部', |
| | | ParentID: '' |
| | | } |
| | | |
| | | linkSubFields.forEach(m => { |
| | | newData[m] = newData[m] || '' |
| | | }) |
| | | |
| | | let _data = [newData, ...dataSource] |
| | | |
| | | this.setState({ |
| | | dataSource: _data, |
| | | }, () => { |
| | | this.props.onChange(_data) |
| | | }) |
| | | } |
| | | |
| | | resetColumn = (type, linkSubFields) => { |
| | | const { columns, dataSource } = this.getColumns(type, linkSubFields, this.state.dataSource) |
| | | |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { module } = this.props |
| | | const { dataSource } = this.state |
| | | const components = { |
| | | body: { |
| | |
| | | }) |
| | | return ( |
| | | <div className="common-modal-edit-table"> |
| | | <span className="add-row add-row-empty" onClick={this.handleEmpty}>{module === 'form' ? '空' : '全部'}</span> |
| | | <PlusOutlined className="add-row" onClick={this.handleAdd} /> |
| | | <Table |
| | | components={components} |
| | | rowClassName={() => 'editable-row'} |
| | | rowClassName={(record) => record.Hide ? 'editable-row hide' : 'editable-row'} |
| | | bordered |
| | | dataSource={dataSource} |
| | | columns={columns} |