| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Table, Modal, Input, InputNumber, notification, message, AutoComplete } from 'antd' |
| | | import { Table, Modal, Input, InputNumber, notification, message, AutoComplete, Select } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | | import Utils from '@/utils/utils.js' |
| | |
| | | if (col.field === 'creditor') { |
| | | MKEmitter.emit('nextLine', col, record) |
| | | } else { |
| | | let cl = {remark: 'subject', subject: 'debtor', debtor: 'creditor'} |
| | | let cl = {remark: 'subjectscode', subjectscode: 'debtor', debtor: 'creditor'} |
| | | MKEmitter.emit('tdFocus', cl[col.uuid] + record.uuid) |
| | | } |
| | | }, 50) |
| | |
| | | |
| | | if (record.type === 'total') return |
| | | |
| | | this.setState({editing: true, value: record[col.field]}, () => { |
| | | let node = document.getElementById(col.uuid + record.uuid) |
| | | node && node.select() |
| | | }) |
| | | if (col.field === 'subjectscode') { |
| | | this.setState({editing: true}, () => { |
| | | try { |
| | | let node = document.getElementById(col.uuid + record.uuid) |
| | | node.click() |
| | | } catch(e) {} |
| | | }) |
| | | } else { |
| | | this.setState({editing: true, value: record[col.field]}, () => { |
| | | let node = document.getElementById(col.uuid + record.uuid) |
| | | node && node.select() |
| | | }) |
| | | } |
| | | } |
| | | |
| | | onBlur = () => { |
| | |
| | | const { value } = this.state |
| | | |
| | | this.setState({editing: false}) |
| | | |
| | | if (col.field === 'subjectscode') return |
| | | |
| | | if (value !== record[col.field]) { |
| | | let line = {...record, [col.field]: value} |
| | |
| | | this.setState({value: val}) |
| | | } |
| | | |
| | | complete = (key, option) => { |
| | | this.setState({value: option.props.value}) |
| | | complete = (val) => { |
| | | this.setState({value: val}, () => { |
| | | this.onBlur() |
| | | }) |
| | | } |
| | | |
| | | onSelectChange = (val, option) => { |
| | | const { col, record } = this.props |
| | | |
| | | this.setState({editing: false}) |
| | | |
| | | let line = {...record, ...option.props.extra} |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, line) |
| | | |
| | | setTimeout(() => { |
| | | MKEmitter.emit('tdFocus', 'debtor' + record.uuid) |
| | | }, 50) |
| | | } |
| | | |
| | | render() { |
| | | let { col, record, className } = this.props |
| | | let { col, record, subjects, className } = this.props |
| | | const { editing } = this.state |
| | | |
| | | let children = null |
| | |
| | | children = <div className="content-wrap" onClick={this.focus}>{val}</div> |
| | | } |
| | | } |
| | | } else if (col.field === 'subject') { |
| | | } else if (col.field === 'subjectscode') { |
| | | if (record.type === 'total') { |
| | | colSpan = 0 |
| | | } else { |
| | | let val = record.subject || '' |
| | | |
| | | if (editing) { |
| | | children = <Input.TextArea id={col.uuid + record.uuid} autoSize={false} defaultValue={val} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | children = <Select |
| | | showSearch |
| | | defaultValue={record.subjectscode || ''} |
| | | dropdownClassName="edit-table-dropdown" |
| | | id={col.uuid + record.uuid} |
| | | onBlur={this.onBlur} |
| | | filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} |
| | | onSelect={this.onSelectChange} |
| | | > |
| | | {subjects.map((item, i) => (<Select.Option key={i} extra={item} value={item.subjectscode}>{item.subjectscode + ' ' + item.subjectsname}</Select.Option>))} |
| | | </Select> |
| | | } else { |
| | | let val = '' |
| | | if (record.subjectscode) { |
| | | val = (record.subjectscode || '') + ' ' + (record.subjectsname || '') |
| | | } |
| | | children = <div className="content-wrap" onClick={this.focus}>{val}</div> |
| | | } |
| | | } |
| | |
| | | class VoucherTable extends Component { |
| | | static propTpyes = { |
| | | config: PropTypes.object, // 菜单Id |
| | | subjects: PropTypes.array, // 会计科目 |
| | | BID: PropTypes.any, // 主表ID |
| | | data: PropTypes.any, // 表格数据 |
| | | total: PropTypes.any, // 总数 |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { config } = this.props |
| | | |
| | | let data = [ |
| | | {remark: '提现', subject: '1001 库存现金', debtor: 124, creditor: ''}, |
| | | {remark: '购入固定资产', subject: '1001 库存现金', debtor: '', creditor: 124}, |
| | | {remark: '转结销售成本', subject: '1001 库存现金', debtor: -524, creditor: ''}, |
| | | {remark: '提现', subject: '1001 库存现金', debtor: 34, creditor: ''}, |
| | | ] |
| | | |
| | | data = this.initData(data) |
| | | data.push(this.getTotalLine(data)) |
| | | const { config, subjects, data } = this.props |
| | | |
| | | let columns = [ |
| | | { |
| | |
| | | }, |
| | | { |
| | | title: '会计科目', |
| | | dataIndex: 'subject', |
| | | key: 'subject', |
| | | dataIndex: 'subjectscode', |
| | | key: 'subjectscode', |
| | | width: '34%', |
| | | onCell: record => ({ |
| | | record, |
| | | col: {uuid: 'subject', field: 'subject', tableId: config.uuid}, |
| | | subjects, |
| | | col: {uuid: 'subjectscode', field: 'subjectscode', tableId: config.uuid}, |
| | | }) |
| | | }, |
| | | { |
| | |
| | | ] |
| | | |
| | | this.setState({ |
| | | data: data, |
| | | edData: fromJS(data).toJS(), |
| | | edData: this.resetData(fromJS(data).toJS()), |
| | | columns, |
| | | tableId: config.uuid |
| | | }) |
| | |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | if (!is(fromJS(this.props.data), fromJS(nextProps.data))) { |
| | | this.setState({data: nextProps.data || []}) |
| | | this.resetData(fromJS(nextProps.data).toJS()) |
| | | } else if (!is(fromJS(this.props.subjects), fromJS(nextProps.subjects))) { |
| | | this.resetSubjects(nextProps.subjects) |
| | | } |
| | | } |
| | | |
| | | resetSubjects = (subjects) => { |
| | | const { config } = this.props |
| | | let columns = fromJS(this.state.columns).toJS() |
| | | |
| | | this.setState({ |
| | | columns: columns.map(col => { |
| | | if (col.key === 'subjectscode') { |
| | | return { |
| | | title: '会计科目', |
| | | dataIndex: 'subjectscode', |
| | | key: 'subjectscode', |
| | | width: '34%', |
| | | onCell: record => ({ |
| | | record, |
| | | subjects, |
| | | col: {uuid: 'subjectscode', field: 'subjectscode', tableId: config.uuid}, |
| | | }) |
| | | } |
| | | } |
| | | return col |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | resetData = (data) => { |
| | | data = this.initData(data) |
| | | data.push(this.getTotalLine(data)) |
| | | |
| | | this.setState({ |
| | | edData: data |
| | | }) |
| | | } |
| | | |
| | | initData = (data) => { |
| | |
| | | |
| | | if (_data.length < 4) { |
| | | for (let i = _data.length - 1; i < 4; i++) { |
| | | _data.push({uuid: Utils.getuuid(), index: i + 1, remark: '', subject: '', debtor: '', creditor: ''}) |
| | | _data.push({uuid: Utils.getuuid(), index: i + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}) |
| | | } |
| | | } |
| | | return _data |
| | |
| | | MKEmitter.emit('tdFocus', 'remark' + edData[record.index + 1].uuid) |
| | | } else { |
| | | let _data = fromJS(edData).toJS() |
| | | let line = {uuid: Utils.getuuid(), index: _data.length - 1, remark: record.remark || '', subject: '', debtor: '', creditor: ''} |
| | | let line = {uuid: Utils.getuuid(), index: _data.length - 1, remark: record.remark || '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''} |
| | | |
| | | _data.splice(_data.length - 1, 0, line) |
| | | |
| | |
| | | |
| | | if (_data.length < 4) { |
| | | for (let i = _data.length - 1; i < 4; i++) { |
| | | _data.push({uuid: Utils.getuuid(), index: i + 1, remark: '', subject: '', debtor: '', creditor: ''}) |
| | | _data.push({uuid: Utils.getuuid(), index: i + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}) |
| | | } |
| | | } |
| | | |
| | |
| | | _data.pop() |
| | | |
| | | if (record.index === _data.length - 1) { |
| | | _data.push({uuid: Utils.getuuid(), index: record.index + 1, remark: '', subject: '', debtor: '', creditor: ''}) |
| | | _data.push({uuid: Utils.getuuid(), index: record.index + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}) |
| | | } |
| | | |
| | | _data.push(this.getTotalLine(_data)) |