From c39acd25c3e8747be16773a003f519e4ef801640 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 17 一月 2023 16:44:16 +0800 Subject: [PATCH] 2023-01-17 --- src/tabviews/custom/components/module/voucher/voucherTable/index.jsx | 133 +++++++++++++++++++++++++++++++++----------- 1 files changed, 99 insertions(+), 34 deletions(-) diff --git a/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx b/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx index 8d5240d..b79fdd7 100644 --- a/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx +++ b/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx @@ -1,7 +1,7 @@ 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' @@ -78,7 +78,7 @@ 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) @@ -89,10 +89,19 @@ 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 = () => { @@ -100,6 +109,8 @@ const { value } = this.state this.setState({editing: false}) + + if (col.field === 'subjectscode') return if (value !== record[col.field]) { let line = {...record, [col.field]: value} @@ -118,12 +129,28 @@ 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 @@ -154,15 +181,27 @@ 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> } } @@ -217,6 +256,7 @@ class VoucherTable extends Component { static propTpyes = { config: PropTypes.object, // 鑿滃崟Id + subjects: PropTypes.array, // 浼氳绉戠洰 BID: PropTypes.any, // 涓昏〃ID data: PropTypes.any, // 琛ㄦ牸鏁版嵁 total: PropTypes.any, // 鎬绘暟 @@ -236,17 +276,7 @@ } 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 = [ { @@ -261,12 +291,13 @@ }, { 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}, }) }, { @@ -304,8 +335,7 @@ ] this.setState({ - data: data, - edData: fromJS(data).toJS(), + edData: this.resetData(fromJS(data).toJS()), columns, tableId: config.uuid }) @@ -335,8 +365,43 @@ 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) => { @@ -349,7 +414,7 @@ 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 @@ -478,7 +543,7 @@ 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) @@ -512,7 +577,7 @@ 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: ''}) } } @@ -535,7 +600,7 @@ _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)) -- Gitblit v1.8.0