| | |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Table, Modal, Input, InputNumber, notification, message, AutoComplete, Select } from 'antd' |
| | | import { PlusOutlined, CloseOutlined } from '@ant-design/icons' |
| | | |
| | | import Api from '@/api' |
| | | import Utils from '@/utils/utils.js' |
| | |
| | | |
| | | this.setState({editing: false}) |
| | | |
| | | let line = {...record} |
| | | |
| | | if (value !== record[col.field]) { |
| | | let line = {...record, [col.field]: value} |
| | | line[col.field] = value |
| | | |
| | | if (col.field === 'debtor') { |
| | | line.creditor = '' |
| | | if (isNaN(line.debtor)) { |
| | | line.debtor = '' |
| | | } |
| | | } else { |
| | | line.debtor = '' |
| | | if (isNaN(line.creditor)) { |
| | | line.creditor = '' |
| | | } |
| | | } |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, line) |
| | | } |
| | | |
| | | setTimeout(() => { |
| | | if (col.field === 'creditor') { |
| | | if (col.field === 'debtor' && (line.debtor || line.debtor === 0)) { |
| | | MKEmitter.emit('nextLine', col, record) |
| | | } else if (col.field === 'creditor') { |
| | | MKEmitter.emit('nextLine', col, record) |
| | | } else { |
| | | let cl = {remark: 'subjectscode', subjectscode: 'debtor', debtor: 'creditor'} |
| | |
| | | |
| | | if (col.field === 'debtor') { |
| | | line.creditor = '' |
| | | if (isNaN(line.debtor)) { |
| | | line.debtor = '' |
| | | } |
| | | } else { |
| | | line.debtor = '' |
| | | if (isNaN(line.creditor)) { |
| | | line.creditor = '' |
| | | } |
| | | } |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, line) |
| | |
| | | this.setState({value: val}, () => { |
| | | this.onBlur() |
| | | }) |
| | | } |
| | | |
| | | plusLine = () => { |
| | | const { col, record } = this.props |
| | | |
| | | MKEmitter.emit('plusLine', col.tableId, record) |
| | | } |
| | | |
| | | delRecord = () => { |
| | | const { col, record } = this.props |
| | | |
| | | MKEmitter.emit('delRecord', col.tableId, record) |
| | | } |
| | | |
| | | onSelectChange = (val, option) => { |
| | |
| | | |
| | | let children = null |
| | | let colSpan = 1 |
| | | let extra = null |
| | | |
| | | if (col.field === 'remark') { |
| | | let val = record.remark || '' |
| | |
| | | children = <div className="content-wrap" style={{lineHeight: '60px'}}>合计: {val}</div> |
| | | colSpan = 2 |
| | | } else { |
| | | extra = <PlusOutlined onClick={this.plusLine}/> |
| | | |
| | | if (editing) { |
| | | let options = ['现金', '发票'] |
| | | children = <AutoComplete |
| | |
| | | } |
| | | } |
| | | } else if (col.field === 'debtor') { |
| | | let val = record.debtor |
| | | let down = false |
| | | let vals = [] |
| | | if (typeof(val) === 'number') { |
| | | if (val < 0) { |
| | | down = true |
| | | val = Math.abs(val) |
| | | } |
| | | vals = (val * 100).toFixed(0).split('').reverse() |
| | | } |
| | | |
| | | if (editing) { |
| | | children = <InputNumber id={col.uuid + record.uuid} defaultValue={val} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | children = <InputNumber id={col.uuid + record.uuid} defaultValue={record.debtor} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | } else { |
| | | let val = record.debtor |
| | | let down = false |
| | | let vals = [] |
| | | if (!isNaN(val) && val !== '') { |
| | | if (val < 0) { |
| | | down = true |
| | | val = Math.abs(val) |
| | | } |
| | | vals = (val * 100).toFixed(0).split('').reverse() |
| | | } |
| | | children = <div className={'money-uint' + (down ? ' down' : '')} onClick={this.focus}> |
| | | <span>{vals[10] || ''}</span> <span>{vals[9] || ''}</span> <span>{vals[8] || ''}</span> <span>{vals[7] || ''}</span> <span>{vals[6] || ''}</span> <span>{vals[5] || ''}</span> |
| | | <span>{vals[4] || ''}</span> <span>{vals[3] || ''}</span> <span>{vals[2] || ''}</span> <span>{vals[1] || ''}</span> <span className="last">{vals[0] || ''}</span> |
| | | </div> |
| | | } |
| | | } else if (col.field === 'creditor') { |
| | | let val = record.creditor |
| | | let down = false |
| | | let vals = [] |
| | | if (typeof(val) === 'number') { |
| | | if (val < 0) { |
| | | down = true |
| | | val = Math.abs(val) |
| | | } |
| | | vals = (val * 100).toFixed(0).split('').reverse() |
| | | } |
| | | extra = <CloseOutlined onClick={this.delRecord}/> |
| | | |
| | | if (editing) { |
| | | children = <InputNumber id={col.uuid + record.uuid} defaultValue={val} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | children = <InputNumber id={col.uuid + record.uuid} defaultValue={record.creditor} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | } else { |
| | | let val = record.creditor |
| | | let down = false |
| | | let vals = [] |
| | | if (!isNaN(val) && val !== '') { |
| | | if (val < 0) { |
| | | down = true |
| | | val = Math.abs(val) |
| | | } |
| | | vals = (val * 100).toFixed(0).split('').reverse() |
| | | } |
| | | children = <div className={'money-uint' + (down ? ' down' : '')} onClick={this.focus}> |
| | | <span>{vals[10] || ''}</span> <span>{vals[9] || ''}</span> <span>{vals[8] || ''}</span> <span>{vals[7] || ''}</span> <span>{vals[6] || ''}</span> <span>{vals[5] || ''}</span> |
| | | <span>{vals[4] || ''}</span> <span>{vals[3] || ''}</span> <span>{vals[2] || ''}</span> <span>{vals[1] || ''}</span> <span className="last">{vals[0] || ''}</span> |
| | |
| | | |
| | | if (!colSpan) return null |
| | | |
| | | return (<td colSpan={colSpan} className={className}>{children}</td>) |
| | | return (<td colSpan={colSpan} className={className}>{children}{extra}</td>) |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('nextLine', this.nextLine) |
| | | MKEmitter.addListener('plusLine', this.plusLine) |
| | | MKEmitter.addListener('delRecord', this.delRecord) |
| | | MKEmitter.addListener('changeRecord', this.changeRecord) |
| | | } |
| | |
| | | return |
| | | } |
| | | MKEmitter.removeListener('nextLine', this.nextLine) |
| | | MKEmitter.removeListener('plusLine', this.plusLine) |
| | | MKEmitter.removeListener('delRecord', this.delRecord) |
| | | MKEmitter.removeListener('changeRecord', this.changeRecord) |
| | | } |
| | |
| | | let creditor = '' |
| | | |
| | | data.forEach(item => { |
| | | if (typeof(item.debtor) === 'number') { |
| | | if (!isNaN(item.debtor) && item.debtor !== '') { |
| | | if (debtor === '') { |
| | | debtor = 0 |
| | | } |
| | | |
| | | debtor += item.debtor |
| | | } else if (typeof(item.creditor) === 'number') { |
| | | } else if (!isNaN(item.creditor) && item.creditor !== '') { |
| | | if (debtor === '') { |
| | | debtor = 0 |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | plusLine = (initEditLine) => { |
| | | const { edData } = this.state |
| | | plusLine = (tid, record) => { |
| | | const { edData, tableId } = this.state |
| | | |
| | | let item = {...edData[edData.length - 1]} |
| | | if (tid !== tableId) return |
| | | |
| | | item.key = item.key + 1 |
| | | item.$$uuid = '$new' |
| | | let _data = fromJS(edData).toJS() |
| | | let line = {uuid: Utils.getuuid(), index: 0, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''} |
| | | |
| | | this.setState({edData: [...edData, item]}, () => { |
| | | MKEmitter.emit('tdFocus', initEditLine.uuid + item.uuid) |
| | | }) |
| | | _data.splice(record.index, 0, line) |
| | | |
| | | this.setState({edData: _data.map((item, index) => { |
| | | item.index = index |
| | | return item |
| | | })}) |
| | | } |
| | | |
| | | delRecord = (id, record) => { |
| | |
| | | |
| | | if (id !== tableId) return |
| | | |
| | | let _data = edData.filter(item => item.uuid !== record.uuid) |
| | | let _data = fromJS(edData).toJS().filter(item => item.uuid !== record.uuid) |
| | | |
| | | _data.pop() |
| | | |
| | | if (_data.length < 4) { |
| | | for (let i = _data.length - 1; i < 4; i++) { |
| | | _data.push({uuid: Utils.getuuid(), index: i + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}) |
| | | for (let i = _data.length; i < 4; i++) { |
| | | _data.push({uuid: Utils.getuuid(), index: 0, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}) |
| | | } |
| | | } |
| | | |
| | | _data = _data.map((item, index) => { |
| | | item.index = index |
| | | return item |
| | | }) |
| | | |
| | | _data.push(this.getTotalLine(_data)) |
| | | |
| | |
| | | _data.push(this.getTotalLine(_data)) |
| | | |
| | | this.setState({edData: _data}) |
| | | } |
| | | |
| | | addLine = () => { |
| | | const { BID } = this.props |
| | | const { edData } = this.state |
| | | |
| | | let item = {} |
| | | if (edData.length > 0) { |
| | | item = {...edData[edData.length - 1]} |
| | | item.key = item.key + 1 |
| | | item.$$uuid = '$new' |
| | | } else { |
| | | item.key = 0 |
| | | item.$$uuid = '$new' |
| | | item.$$BID = BID || '' |
| | | } |
| | | |
| | | this.setState({edData: [...edData, item]}) |
| | | } |
| | | |
| | | checkData = () => { |