| | |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Table, Typography, Switch, Modal, Input, InputNumber, Tooltip, Button, notification, message, Select } from 'antd' |
| | | import { ExclamationCircleOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons' |
| | | import { ExclamationCircleOutlined, EditOutlined, PlusOutlined, PlusCircleOutlined, DeleteOutlined } from '@ant-design/icons' |
| | | import moment from 'moment' |
| | | |
| | | import Api from '@/api' |
| | |
| | | tdFocus = (id) => { |
| | | const { col, record } = this.props |
| | | |
| | | if (id !== col.uuid + record.$Index) return |
| | | if (id !== col.uuid + record.$$uuid) return |
| | | this.focus() |
| | | } |
| | | |
| | |
| | | this.setState({editing: false}) |
| | | setTimeout(() => { |
| | | if (col.enter === '$next') { |
| | | MKEmitter.emit('nextLine', col, record.$Index) |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else { |
| | | MKEmitter.emit('tdFocus', col.enter + record.$Index) |
| | | MKEmitter.emit('tdFocus', col.enter + record.$$uuid) |
| | | } |
| | | }, 50) |
| | | |
| | |
| | | |
| | | if (col.editType === 'switch' || col.editType === 'select') { |
| | | this.setState({editing: true}, () => { |
| | | let node = document.getElementById(col.uuid + record.$Index) |
| | | let node = document.getElementById(col.uuid + record.$$uuid) |
| | | node && node.click() |
| | | }) |
| | | } else { |
| | |
| | | } |
| | | |
| | | this.setState({editing: true, value: val, err}, () => { |
| | | let node = document.getElementById(col.uuid + record.$Index) |
| | | let node = document.getElementById(col.uuid + record.$$uuid) |
| | | node && node.select() |
| | | }) |
| | | } |
| | |
| | | |
| | | setTimeout(() => { |
| | | if (col.enter === '$next') { |
| | | MKEmitter.emit('nextLine', col, record.$Index) |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else { |
| | | MKEmitter.emit('tdFocus', col.enter + record.$Index) |
| | | MKEmitter.emit('tdFocus', col.enter + record.$$uuid) |
| | | } |
| | | }, 50) |
| | | |
| | |
| | | |
| | | setTimeout(() => { |
| | | if (col.enter === '$next') { |
| | | MKEmitter.emit('nextLine', col, record.$Index) |
| | | MKEmitter.emit('nextLine', col, record.$$uuid) |
| | | } else { |
| | | MKEmitter.emit('tdFocus', col.enter + record.$Index) |
| | | MKEmitter.emit('tdFocus', col.enter + record.$$uuid) |
| | | } |
| | | }, 50) |
| | | |
| | |
| | | if (editing) { |
| | | if (!col.editType || col.editType === 'text') { |
| | | return (<td className="editing_table_cell"> |
| | | <Input id={col.uuid + record.$Index} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | <Input id={col.uuid + record.$$uuid} defaultValue={value} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | {err ? <Tooltip title={err}><ExclamationCircleOutlined /></Tooltip> : null} |
| | | </td>) |
| | | } else if (col.editType === 'switch') { |
| | |
| | | <Select |
| | | showSearch |
| | | defaultValue={_value} |
| | | id={col.uuid + record.$Index} |
| | | id={col.uuid + record.$$uuid} |
| | | onBlur={() => this.setState({editing: false})} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onSelect={this.onSelectChange} |
| | |
| | | if (col.editable === 'true') { |
| | | if (editing) { |
| | | return (<td className="editing_table_cell"> |
| | | <InputNumber id={col.uuid + record.$Index} defaultValue={value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | <InputNumber id={col.uuid + record.$$uuid} defaultValue={value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | {err ? <Tooltip title={err}><ExclamationCircleOutlined /></Tooltip> : null} |
| | | </td>) |
| | | } else { |
| | |
| | | ) |
| | | } |
| | | |
| | | // return (<td className={className} style={style}>{col.addable ? <PlusCircleOutlined className="mk-editable mk-plus"/> : null}{children}{col.delable ? <DeleteOutlined className="mk-editable mk-del"/> : null}</td>) |
| | | return (<td className={className} style={style}>{children}</td>) |
| | | return (<td className={className} style={style}>{col.addable ? <PlusCircleOutlined onClick={() => MKEmitter.emit('addRecord', col.tableId, {...record})} className="mk-editable mk-plus"/> : null}{children}{col.delable ? <DeleteOutlined onClick={() => MKEmitter.emit('delRecord', col.tableId, {...record})} className="mk-editable mk-del"/> : null}</td>) |
| | | // return (<td className={className} style={style}>{children}</td>) |
| | | } |
| | | } |
| | | |
| | |
| | | _columns.push(_item) |
| | | }) |
| | | |
| | | // if (setting.delable !== 'false') { |
| | | // edColumns.push({ |
| | | // align: 'center', |
| | | // dataIndex: 'mkoperation', |
| | | // title: '操作', |
| | | // sorter: false, |
| | | // width: 100, |
| | | // onCell: record => ({ |
| | | // record, |
| | | // col: {type: 'operation', tableId: setting.tableId}, |
| | | // }) |
| | | // }) |
| | | // } |
| | | if (setting.delable !== 'false' && setting.operType !== 'buoyMode') { |
| | | edColumns.push({ |
| | | align: 'center', |
| | | dataIndex: 'mkoperation', |
| | | title: '操作', |
| | | sorter: false, |
| | | width: 100, |
| | | onCell: record => ({ |
| | | record, |
| | | col: {type: 'operation', tableId: setting.tableId}, |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | if (setting.borderColor) { // 边框颜色 |
| | | let style = `#${setting.tableId} table, #${setting.tableId} tr, #${setting.tableId} th, #${setting.tableId} td {border-color: ${setting.borderColor}}` |
| | |
| | | } |
| | | |
| | | MKEmitter.addListener('nextLine', this.nextLine) |
| | | MKEmitter.addListener('addRecord', this.addLine) |
| | | MKEmitter.addListener('delRecord', this.delRecord) |
| | | MKEmitter.addListener('resetTable', this.resetTable) |
| | | MKEmitter.addListener('changeRecord', this.changeRecord) |
| | |
| | | return |
| | | } |
| | | MKEmitter.removeListener('nextLine', this.nextLine) |
| | | MKEmitter.removeListener('addRecord', this.addLine) |
| | | MKEmitter.removeListener('delRecord', this.delRecord) |
| | | MKEmitter.removeListener('resetTable', this.resetTable) |
| | | MKEmitter.removeListener('changeRecord', this.changeRecord) |
| | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (!is(fromJS(this.props.data), fromJS(nextProps.data))) { |
| | | this.setState({data: nextProps.data || []}) |
| | | if (this.state.editable === 'true') { |
| | | if (this.state.editable === 'true' && !this.state.pickup) { |
| | | setTimeout(() => { |
| | | this.pickupChange() |
| | | }, 200) |
| | |
| | | MKEmitter.emit('tdFocus', initEditLine.uuid + (index + 1)) |
| | | } else if (col.footEnter === 'add' && setting.addable === 'true') { |
| | | setTimeout(() => { |
| | | this.plusLine(initEditLine) |
| | | this.plusLine() |
| | | }, 10) |
| | | } else if (col.footEnter === 'sub') { |
| | | setTimeout(() => { |
| | |
| | | } |
| | | } |
| | | |
| | | plusLine = (initEditLine) => { |
| | | const { edData, fields } = this.state |
| | | plusLine = () => { |
| | | const { edData, fields, initEditLine } = this.state |
| | | |
| | | let item = {...edData[edData.length - 1]} |
| | | |
| | | item.key = item.key + 1 |
| | | item.$$uuid = '$new' |
| | | item.$Index = item.key + 1 + '' |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$Index = '' |
| | | |
| | | fields.forEach(col => { |
| | | if (col.initval !== '$copy') { |
| | |
| | | }) |
| | | |
| | | this.setState({edData: [...edData, item]}, () => { |
| | | MKEmitter.emit('tdFocus', initEditLine.uuid + item.$Index) |
| | | MKEmitter.emit('tdFocus', initEditLine.uuid + item.$$uuid) |
| | | }) |
| | | } |
| | | |
| | |
| | | |
| | | let _data = [] |
| | | |
| | | if (record.$$uuid === '$new') { |
| | | _data = edData.filter(item => item.$Index !== record.$Index) |
| | | _data = _data.map((item, index) => { |
| | | item.key = index |
| | | item.$Index = 1 + index + '' |
| | | return item |
| | | }) |
| | | if (record.$type === 'add') { |
| | | _data = edData.filter(item => item.$$uuid !== record.$$uuid) |
| | | } else { |
| | | _data = edData.map(item => { |
| | | if (item.$Index === record.$Index) { |
| | | if (item.$$uuid === record.$$uuid) { |
| | | record.$deleted = true |
| | | record.$origin = false |
| | | record.$type = 'del' |
| | | return record |
| | | } else { |
| | | return item |
| | |
| | | if (id !== tableId) return |
| | | |
| | | let _data = this.state.edData.map(item => { |
| | | if (item.$Index === record.$Index) { |
| | | if (item.$$uuid === record.$$uuid) { |
| | | record.$origin = false |
| | | return record |
| | | } else { |
| | | return item |
| | |
| | | this.setState({edData: _data}) |
| | | } |
| | | |
| | | addLine = () => { |
| | | addLine = (id, record) => { |
| | | const { BID } = this.props |
| | | const { edData, fields } = this.state |
| | | const { edData, fields, tableId } = this.state |
| | | |
| | | let item = {} |
| | | if (edData.length > 0) { |
| | | item = {...edData[edData.length - 1]} |
| | | item.key = item.key + 1 |
| | | item.$$uuid = '$new' |
| | | item.$Index = item.key + 1 + '' |
| | | } else { |
| | | item.key = 0 |
| | | item.$$uuid = '$new' |
| | | item.$Index = item.key + 1 + '' |
| | | if (id) { |
| | | if (id !== tableId) return |
| | | let _edData = fromJS(edData).toJS() |
| | | let index = _edData.findIndex(item => record.$$uuid === item.$$uuid) |
| | | |
| | | let item = {} |
| | | |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$Index = '' |
| | | item.$$BID = BID || '' |
| | | } |
| | | |
| | | fields.forEach(col => { |
| | | if (col.initval !== '$copy') { |
| | | item[col.field] = col.initval |
| | | } |
| | | if (col.type === 'number') { |
| | | item[col.field] = +item[col.field] |
| | | if (isNaN(item[col.field])) { |
| | | item[col.field] = 0 |
| | | |
| | | fields.forEach(col => { |
| | | if (col.initval !== '$copy') { |
| | | item[col.field] = col.initval |
| | | } |
| | | } |
| | | if (col.type === 'number') { |
| | | item[col.field] = +item[col.field] |
| | | if (isNaN(item[col.field])) { |
| | | item[col.field] = 0 |
| | | } |
| | | } |
| | | |
| | | if (item[col.field] === undefined) { |
| | | item[col.field] = '' |
| | | } |
| | | }) |
| | | |
| | | if (item[col.field] === undefined) { |
| | | item[col.field] = '' |
| | | } |
| | | }) |
| | | _edData.splice(index, 0, item) |
| | | |
| | | this.setState({edData: [...edData, item]}) |
| | | this.setState({edData: _edData}) |
| | | } else { |
| | | let item = {} |
| | | if (edData.length > 0) { |
| | | item = {...edData[edData.length - 1]} |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$Index = '' |
| | | } else { |
| | | item.$$uuid = Utils.getguid() |
| | | item.$type = 'add' |
| | | item.$Index = '' |
| | | item.$$BID = BID || '' |
| | | } |
| | | |
| | | fields.forEach(col => { |
| | | if (col.initval !== '$copy') { |
| | | item[col.field] = col.initval |
| | | } |
| | | if (col.type === 'number') { |
| | | item[col.field] = +item[col.field] |
| | | if (isNaN(item[col.field])) { |
| | | item[col.field] = 0 |
| | | } |
| | | } |
| | | |
| | | if (item[col.field] === undefined) { |
| | | item[col.field] = '' |
| | | } |
| | | }) |
| | | |
| | | this.setState({edData: [...edData, item]}) |
| | | } |
| | | } |
| | | |
| | | checkData = () => { |
| | |
| | | return |
| | | } |
| | | let err = '' |
| | | let Index = 1 |
| | | let data = fromJS(edData).toJS().map(item => { |
| | | let line = [] |
| | | fields.forEach(col => { |
| | |
| | | }) |
| | | |
| | | if (line.length > 0) { |
| | | err += `第${item.$Index}行:` + line.join(',') + ';' |
| | | err += `第${Index}行:` + line.join(',') + ';' |
| | | } |
| | | if (!item.$deleted) { |
| | | Index++ |
| | | } |
| | | |
| | | return item |
| | |
| | | } |
| | | |
| | | submit = (data) => { |
| | | const { submit, BID } = this.props |
| | | const { submit, BID, setting } = this.props |
| | | const { fields } = this.state |
| | | |
| | | if (setting.commit === 'change') { |
| | | data = data.filter(item => !item.$origin) |
| | | } |
| | | |
| | | if (data.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '数据未修改,不可提交!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let result = getEditTableSql(submit, data, fields) |
| | | |
| | |
| | | let height = setting.height || false |
| | | |
| | | return ( |
| | | <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}> |
| | | <Switch title="编辑" className="main-pickup" checkedChildren="开" unCheckedChildren="关" checked={pickup} onChange={this.pickupChange} /> |
| | | <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${setting.operType || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}> |
| | | <Switch title="编辑" className="main-pickup" checkedChildren="开" unCheckedChildren="关" disabled={loading || this.props.loading} checked={pickup} onChange={this.pickupChange} /> |
| | | {pickup ? <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">提交</Button> : null} |
| | | <Table |
| | | rowKey="$$uuid" |
| | | components={components} |
| | | style={setting.style} |
| | | size={setting.size || 'middle'} |
| | |
| | | pagination={_pagination} |
| | | /> |
| | | {_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null} |
| | | {pickup && setting.addable === 'true' ? <Button onClick={this.addLine} style={{display: 'block', width: '100%', color: '#26C281', border: '1px solid #dddddd', borderRadius: 0}} type="link"><PlusOutlined /></Button> : null} |
| | | {pickup && setting.addable === 'true' ? <Button className="mk-add-line" onClick={() => this.addLine()} disabled={this.props.loading} type="link"><PlusOutlined /></Button> : null} |
| | | </div> |
| | | ) |
| | | } |