From b59af63c6742fa48de8fcdba67c9b8dc2e42bf94 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 03 二月 2023 11:25:29 +0800 Subject: [PATCH] Merge branch 'develop' --- src/tabviews/custom/components/module/voucher/voucherTable/index.jsx | 1027 +++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 738 insertions(+), 289 deletions(-) diff --git a/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx b/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx index b79fdd7..9a37f76 100644 --- a/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx +++ b/src/tabviews/custom/components/module/voucher/voucherTable/index.jsx @@ -1,13 +1,11 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Table, Modal, Input, InputNumber, notification, message, AutoComplete, Select } from 'antd' +import { Table, Form, Input, InputNumber, notification, AutoComplete, Select, Popover, Button } from 'antd' +import { PlusOutlined, CloseOutlined } from '@ant-design/icons' -import Api from '@/api' import Utils from '@/utils/utils.js' import MKEmitter from '@/utils/events.js' -import zhCN from '@/locales/zh-CN/main.js' -import enUS from '@/locales/en-US/main.js' import './index.scss' class BodyRow extends React.Component { @@ -24,14 +22,108 @@ } } +class Accounting extends React.Component { + state = { + subAccounts: [], + record: null + } + + UNSAFE_componentWillMount() { + const { data, tableId } = this.props + let subAccounts = data.sup_accounting.split(',') + let msg = window.GLOB.CacheVoucher.get(tableId) || {} + let names = msg.names || {} + + subAccounts = subAccounts.map(n => { + let item = { + field: n, + label: names[n] || n, + initval: data[n] || '', + options: [] + } + + if (msg[n]) { + item.options = msg[n] + } + + return item + }) + + this.setState({subAccounts: subAccounts, record: fromJS(data).toJS()}) + } + + selectChange = (val, item) => { + this.setState({record: {...this.state.record, [item.field]: val || ''}}) + } + + getFields() { + const { subAccounts } = this.state + + const fields = [] + + subAccounts.forEach((item) => { + fields.push( + <Form.Item label={item.label} key={item.field}> + <Select + showSearch + allowClear + defaultValue={item.initval} + dropdownMatchSelectWidth={false} + filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} + onChange={(val) => this.selectChange(val, item)} + > + {item.options.map((option, i) => + <Select.Option key={i} value={option.value}>{option.label}</Select.Option> + )} + </Select> + </Form.Item> + ) + }) + + return fields + } + + confirm = () => { + const { subAccounts, record } = this.state + + let empty = '' + subAccounts.forEach(item => { + if (!empty && !record[item.field]) { + empty = item.label + } + }) + + if (empty) { + notification.warning({ + top: 92, + message: '璇烽�夋嫨' + empty, + duration: 5 + }) + } else { + this.props.confirm(record) + } + } + + render() { + return <div> + {this.getFields()} + <div className="footer"> + <Button onClick={this.props.cancel}>鍙栨秷</Button> + <Button onClick={this.confirm}>纭畾</Button> + </div> + </div> + } +} + class BodyCell extends React.Component { state = { editing: false, - } - - shouldComponentUpdate (nextProps, nextState) { - return !is(fromJS(this.props.record), fromJS(nextProps.record)) || - nextState.editing !== this.state.editing + visible: false, + counting: false, + priceing: false, + curring: false, + ratioing: false, + origining: false, } componentDidMount () { @@ -62,20 +154,43 @@ this.setState({editing: false}) - if (value !== record[col.field]) { - let line = {...record, [col.field]: value} + let line = {...record} + line[col.field] = value - if (col.field === 'debtor') { - line.creditor = '' - } else { + if (col.field === 'debtor') { + line.creditor = '' + if (isNaN(line.debtor)) { line.debtor = '' } - - MKEmitter.emit('changeRecord', col.tableId, line) + } else { + line.debtor = '' + if (isNaN(line.creditor)) { + line.creditor = '' + } } + if (line.count_type === 'Y' && line.count) { + if (line.debtor) { + line.price = Math.round(line.debtor / line.count * 10000) / 10000 + } else if (line.creditor) { + line.price = Math.round(line.creditor / line.count * 10000) / 10000 + } + } + + if (line.foreign_currency_type === 'Y' && line.origin) { + if (line.debtor) { + line.unitratio = Math.round(line.debtor / line.origin * 100000) / 100000 + } else if (line.creditor) { + line.unitratio = Math.round(line.creditor / line.origin * 100000) / 100000 + } + } + + 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'} @@ -91,10 +206,8 @@ if (col.field === 'subjectscode') { this.setState({editing: true}, () => { - try { - let node = document.getElementById(col.uuid + record.uuid) - node.click() - } catch(e) {} + let node = document.getElementById(col.uuid + record.uuid) + node && node.click() }) } else { this.setState({editing: true, value: record[col.field]}, () => { @@ -110,15 +223,35 @@ this.setState({editing: false}) - if (col.field === 'subjectscode') return - if (value !== record[col.field]) { let line = {...record, [col.field]: value} if (col.field === 'debtor') { line.creditor = '' + if (isNaN(line.debtor)) { + line.debtor = '' + } } else { line.debtor = '' + if (isNaN(line.creditor)) { + line.creditor = '' + } + } + + if (line.count_type === 'Y' && line.count) { + if (line.debtor) { + line.price = Math.round(line.debtor / line.count * 10000) / 10000 + } else if (line.creditor) { + line.price = Math.round(line.creditor / line.count * 10000) / 10000 + } + } + + if (line.foreign_currency_type === 'Y' && line.origin) { + if (line.debtor) { + line.unitratio = Math.round(line.debtor / line.origin * 100000) / 100000 + } else if (line.creditor) { + line.unitratio = Math.round(line.creditor / line.origin * 100000) / 100000 + } } MKEmitter.emit('changeRecord', col.tableId, line) @@ -135,26 +268,382 @@ }) } + plusLine = () => { + const { col, record } = this.props + + MKEmitter.emit('plusLine', col.tableId, record) + } + + delRecord = () => { + const { col, record } = this.props + + MKEmitter.emit('delRecord', col.tableId, record) + } + + onSelectBlur = () => { + const { visible } = this.state + + if (visible) return + + this.setState({editing: false}) + } + onSelectChange = (val, option) => { const { col, record } = this.props - this.setState({editing: false}) + let line = {...record, ...option.props.extra} + + if (record.sup_accounting && !line.sup_accounting) { + record.sup_accounting.split(',').forEach(item => { + line[item] = '' + }) + } + + if (line.foreign_currency_type === 'Y' && line.foreign_currency) { + let msg = window.GLOB.CacheVoucher.get(col.tableId) + let cur = msg ? msg.currency.filter(n => n.exratename === line.foreign_currency)[0] : null + if (cur) { + line = {...line, ...cur} + } + + this.currencyChange(line) + } + + MKEmitter.emit('changeRecord', col.tableId, line) + + if (line.sup_accounting) { + setTimeout(() => { + this.setState({visible: true}) + }, 100) + } else if (line.count_type === 'Y') { + this.setState({counting: true, value: line.count || 0}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'count') + node && node.select() + }) + } else if (line.foreign_currency_type === 'Y') { + this.setState({curring: true}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'currency') + node && node.click() + }) + } else { + this.setState({editing: false, visible: false, counting: false, priceing: false}) + setTimeout(() => { + MKEmitter.emit('tdFocus', 'debtor' + record.uuid) + }, 50) + } + } + + confirm = (res) => { + const { col } = this.props + + MKEmitter.emit('changeRecord', col.tableId, fromJS(res).toJS()) + + this.setState({editing: false, visible: false}) + + if (res.count_type === 'Y') { + this.setState({counting: true, value: res.count || 0}, () => { + let node = document.getElementById(col.uuid + res.uuid + 'count') + node && node.select() + }) + } else { + setTimeout(() => { + MKEmitter.emit('tdFocus', 'debtor' + res.uuid) + }, 50) + } + } + + cancel = () => { + const { col } = this.props + let record = fromJS(this.props.record).toJS() + record.balance_direction = '' + record.count_type = '' + record.foreign_currency_type = '' + record.mnemonic_code = '' + record.subjectscode = '' + record.subjectsname = '' + record.sup_accounting.split(',').forEach(item => { + record[item] = '' + }) + + record.sup_accounting = '' + + MKEmitter.emit('changeRecord', col.tableId, record) + + this.setState({editing: false, visible: false}) + } + + editCount = (e) => { + const { col, record } = this.props + e.stopPropagation() + + this.setState({counting: true, value: record.count || 0}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'count') + node && node.select() + }) + } + + editPrice = (e) => { + const { col, record } = this.props + e.stopPropagation() + + this.setState({priceing: true, value: record.price || 0}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'price') + node && node.select() + }) + } + + countPress = () => { + const { col, record } = this.props + const { value } = this.state + + let line = {...record} + line.count = value || 0 + + if (isNaN(line.count)) { + line.count = 0 + } + + this.countChange(line) + + MKEmitter.emit('changeRecord', col.tableId, line) + + this.setState({counting: false, priceing: true, value: line.price || 0}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'price') + node && node.select() + }) + } + + countBlur = () => { + const { col, record } = this.props + const { value } = this.state + + this.setState({counting: false}) + + let line = {...record} + line.count = value || 0 + + if (isNaN(line.count)) { + line.count = 0 + } + + this.countChange(line) + + MKEmitter.emit('changeRecord', col.tableId, line) + } + + pricePress = () => { + const { col, record } = this.props + const { value } = this.state + + let line = {...record} + line.price = value || 0 + + if (isNaN(line.price)) { + line.price = 0 + } + + this.countChange(line) + + MKEmitter.emit('changeRecord', col.tableId, line) + + this.setState({priceing: false}) + setTimeout(() => { + MKEmitter.emit('tdFocus', 'debtor' + record.uuid) + }, 50) + } + + priceBlur = () => { + const { col, record } = this.props + const { value } = this.state + + this.setState({priceing: false}) + + let line = {...record} + line.price = value || 0 + + if (isNaN(line.price)) { + line.price = 0 + } + + this.countChange(line) + + MKEmitter.emit('changeRecord', col.tableId, line) + } + + editCurrency = (e) => { + const { col, record } = this.props + e.stopPropagation() + + this.setState({curring: true}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'currency') + node && node.click() + }) + } + + onCurrSelectChange = (val, option) => { + const { col, record } = this.props let line = {...record, ...option.props.extra} + this.currencyChange(line) + MKEmitter.emit('changeRecord', col.tableId, line) + + if (line.exratename === 'CNY') { + this.setState({curring: false, origining: true, value: line.origin || 0}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'origin') + node && node.select() + }) + } else { + this.setState({curring: false, ratioing: true, value: line.unitratio || 1}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'ratio') + node && node.select() + }) + } + } + + editRatio = (e) => { + const { col, record } = this.props + e.stopPropagation() + + this.setState({ratioing: true, value: record.unitratio || 1}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'ratio') + node && node.select() + }) + } + + ratioPress = () => { + const { col, record } = this.props + const { value } = this.state + + let line = {...record} + line.unitratio = value || 1 + + if (isNaN(line.unitratio)) { + line.unitratio = 1 + } + + this.currencyChange(line) + + MKEmitter.emit('changeRecord', col.tableId, line) + + this.setState({ratioing: false, origining: true, value: line.origin || 0}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'origin') + node && node.select() + }) + } + + ratioBlur = () => { + const { col, record } = this.props + const { value } = this.state + + this.setState({ratioing: false}) + + let line = {...record} + line.unitratio = value || 1 + + if (isNaN(line.unitratio)) { + line.unitratio = 1 + } + + this.currencyChange(line) + + MKEmitter.emit('changeRecord', col.tableId, line) + } + + editOrigin = (e) => { + const { col, record } = this.props + e.stopPropagation() + + this.setState({origining: true, value: record.origin || 1}, () => { + let node = document.getElementById(col.uuid + record.uuid + 'origin') + node && node.select() + }) + } + + originPress = () => { + const { col, record } = this.props + const { value } = this.state + + let line = {...record} + line.origin = value || 0 + + if (isNaN(line.origin)) { + line.origin = 0 + } + + this.currencyChange(line) + + MKEmitter.emit('changeRecord', col.tableId, line) + + this.setState({origining: false}) setTimeout(() => { MKEmitter.emit('tdFocus', 'debtor' + record.uuid) }, 50) } + originBlur = () => { + const { col, record } = this.props + const { value } = this.state + + this.setState({origining: false}) + + let line = {...record} + line.origin = value || 0 + + if (isNaN(line.origin)) { + line.origin = 0 + } + + this.currencyChange(line) + + MKEmitter.emit('changeRecord', col.tableId, line) + } + + countChange = (line) => { + if (line.count && line.price) { + if (line.creditor) { + line.creditor = Math.round(line.count * line.price * 100) / 100 + } else { + line.debtor = Math.round(line.count * line.price * 100) / 100 + } + + if (line.foreign_currency_type === 'Y' && line.origin) { + if (line.debtor) { + line.unitratio = Math.round(line.debtor / line.origin * 100000) / 100000 + } else if (line.creditor) { + line.unitratio = Math.round(line.creditor / line.origin * 100000) / 100000 + } + } + } + } + + currencyChange = (line) => { + if (line.unitratio && line.origin) { + if (line.creditor) { + line.creditor = Math.round(line.unitratio * line.origin * 100) / 100 + } else { + line.debtor = Math.round(line.unitratio * line.origin * 100) / 100 + } + + if (line.count_type === 'Y' && line.count) { + if (line.debtor) { + line.price = Math.round(line.debtor / line.count * 10000) / 10000 + } else if (line.creditor) { + line.price = Math.round(line.creditor / line.count * 10000) / 10000 + } + } + } + } + render() { - let { col, record, subjects, className } = this.props - const { editing } = this.state + let { col, record, className } = this.props + const { editing, visible, counting, priceing, curring, ratioing, origining } = this.state let children = null let colSpan = 1 + let extra = null if (col.field === 'remark') { let val = record.remark || '' @@ -163,6 +652,8 @@ children = <div className="content-wrap" style={{lineHeight: '60px'}}>鍚堣: {val}</div> colSpan = 2 } else { + extra = <PlusOutlined onClick={this.plusLine}/> + if (editing) { let options = ['鐜伴噾', '鍙戠エ'] children = <AutoComplete @@ -186,60 +677,197 @@ colSpan = 0 } else { if (editing) { - 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> + let msg = window.GLOB.CacheVoucher.get(col.tableId) + let subjects = msg ? msg.subjects : [] + + children = <> + <Select + showSearch + defaultValue={record.subjectscode || ''} + dropdownClassName="edit-table-dropdown" + id={col.uuid + record.uuid} + onBlur={this.onSelectBlur} + 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> + <Popover overlayClassName="subject-pop-wrap" placement="bottom" title="" visible={visible} content={<Accounting confirm={this.confirm} cancel={this.cancel} tableId={col.tableId} data={record}/>}> + <span className="pop-anchor"></span> + </Popover> + </> } else { let val = '' if (record.subjectscode) { val = (record.subjectscode || '') + ' ' + (record.subjectsname || '') + + record.sup_accounting && record.sup_accounting.split(',').forEach(item => { + if (record[item]) { + val += '_' + record[item] + } + }) } - children = <div className="content-wrap" onClick={this.focus}>{val}</div> + + let countNode = null + let currencyNode = null + + if (record.count_type === 'Y') { + if (counting) { + countNode = <div className="count-wrap"> + <span style={{marginRight: '5px'}} onClick={(e) => e.stopPropagation()}> + <span>鏁伴噺锛�</span> + <span><InputNumber precision={4} className="inner-input" id={col.uuid + record.uuid + 'count'} defaultValue={record.count || 0} onChange={(val) => this.onChange(val)} onPressEnter={this.countPress} onBlur={this.countBlur}/></span> + </span> + <span onClick={this.editPrice}> + <span>鍗曚环锛�</span> + <span>{record.price || 0}</span> + </span> + </div> + } else if (priceing) { + countNode = <div className="count-wrap"> + <span style={{marginRight: '5px'}} onClick={this.editCount}> + <span>鏁伴噺锛�</span> + <span>{record.count || 0}</span> + </span> + <span onClick={(e) => e.stopPropagation()}> + <span>鍗曚环锛�</span> + <span><InputNumber precision={4} className="inner-input" id={col.uuid + record.uuid + 'price'} defaultValue={record.price || 0} onChange={(val) => this.onChange(val)} onPressEnter={this.pricePress} onBlur={this.priceBlur}/></span> + </span> + </div> + } else { + countNode = <div className="count-wrap"> + <span style={{marginRight: '5px'}} onClick={this.editCount}> + <span>鏁伴噺锛�</span> + <span>{record.count || 0}</span> + </span> + <span onClick={this.editPrice}> + <span>鍗曚环锛�</span> + <span>{record.price || 0}</span> + </span> + </div> + } + } + + if (record.foreign_currency_type === 'Y') { + if (curring) { + let msg = window.GLOB.CacheVoucher.get(col.tableId) + let currency = msg ? msg.currency : [] + + currencyNode = <div className="count-wrap"> + <span style={{marginRight: '5px'}} onClick={(e) => e.stopPropagation()}> + <span>璐у竵锛�</span> + <span> + <Select + className="currency-select" + defaultValue={record.exratename || ''} + dropdownClassName="edit-table-dropdown" + id={col.uuid + record.uuid + 'currency'} + onBlur={() => this.setState({curring: false})} + onSelect={this.onCurrSelectChange} + > + {currency.map((item, i) => (<Select.Option key={i} extra={item} value={item.exratename}>{item.exratename}</Select.Option>))} + </Select> + </span> + </span> + <span style={{marginRight: '5px'}} onClick={this.editRatio}> + <span>姹囩巼锛�</span> + <span>{record.unitratio || 1}</span> + </span> + <span onClick={this.editOrigin}> + <span>鍘熷竵锛�</span> + <span>{record.origin || 0}</span> + </span> + </div> + } else if (ratioing) { + currencyNode = <div className="count-wrap"> + <span style={{marginRight: '5px'}} onClick={this.editCurrency}> + <span>璐у竵锛�</span> + <span>{record.exratename || ''}</span> + </span> + <span style={{marginRight: '5px'}} onClick={(e) => e.stopPropagation()}> + <span>姹囩巼锛�</span> + <span><InputNumber precision={5} className="inner-input" id={col.uuid + record.uuid + 'ratio'} defaultValue={record.unitratio || 1} onChange={(val) => this.onChange(val)} onPressEnter={this.ratioPress} onBlur={this.ratioBlur}/></span> + </span> + <span onClick={this.editOrigin}> + <span>鍘熷竵锛�</span> + <span>{record.origin || 0}</span> + </span> + </div> + } else if (origining) { + currencyNode = <div className="count-wrap"> + <span style={{marginRight: '5px'}} onClick={this.editCurrency}> + <span>璐у竵锛�</span> + <span>{record.exratename || ''}</span> + </span> + <span style={{marginRight: '5px'}} onClick={this.editRatio}> + <span>姹囩巼锛�</span> + <span>{record.unitratio || 1}</span> + </span> + <span onClick={(e) => e.stopPropagation()}> + <span>鍘熷竵锛�</span> + <span><InputNumber precision={2} className="inner-input" id={col.uuid + record.uuid + 'origin'} defaultValue={record.origin || 0} onChange={(val) => this.onChange(val)} onPressEnter={this.originPress} onBlur={this.originBlur}/></span> + </span> + </div> + } else { + currencyNode = <div className="count-wrap"> + <span style={{marginRight: '5px'}} onClick={this.editCurrency}> + <span>璐у竵锛�</span> + <span>{record.exratename || ''}</span> + </span> + <span style={{marginRight: '5px'}} onClick={this.editRatio}> + <span>姹囩巼锛�</span> + <span>{record.unitratio || 1}</span> + </span> + <span onClick={this.editOrigin}> + <span>鍘熷竵锛�</span> + <span>{record.origin || 0}</span> + </span> + </div> + } + } + + children = <div className="content-wrap" onClick={this.focus}> + {val} + {countNode} + {currencyNode} + </div> } } } 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} precision={2} 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} precision={2} 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> @@ -249,34 +877,27 @@ if (!colSpan) return null - return (<td colSpan={colSpan} className={className}>{children}</td>) + return (<td colSpan={colSpan} className={className}>{children}{extra}</td>) } } class VoucherTable extends Component { static propTpyes = { config: PropTypes.object, // 鑿滃崟Id - subjects: PropTypes.array, // 浼氳绉戠洰 - BID: PropTypes.any, // 涓昏〃ID data: PropTypes.any, // 琛ㄦ牸鏁版嵁 - total: PropTypes.any, // 鎬绘暟 loading: PropTypes.bool, // 琛ㄦ牸鍔犺浇涓� - refreshdata: PropTypes.func, // 琛ㄦ牸涓帓搴忓垪銆侀〉鐮佺殑鍙樺寲鏃跺埛鏂� + onChange: PropTypes.func, // 琛ㄦ牸鍙樺姩 } state = { - dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, data: [], edData: [], - edColumns: [], tableId: '', // 琛ㄦ牸ID - pageSize: 10, // 姣忛〉鏁版嵁鏉℃暟 columns: null, // 鏄剧ず鍒� - loading: false, } UNSAFE_componentWillMount () { - const { config, subjects, data } = this.props + const { config, data } = this.props let columns = [ { @@ -296,7 +917,6 @@ width: '34%', onCell: record => ({ record, - subjects, col: {uuid: 'subjectscode', field: 'subjectscode', tableId: config.uuid}, }) }, @@ -347,7 +967,9 @@ componentDidMount () { MKEmitter.addListener('nextLine', this.nextLine) + MKEmitter.addListener('plusLine', this.plusLine) MKEmitter.addListener('delRecord', this.delRecord) + MKEmitter.addListener('cleartable', this.cleartable) MKEmitter.addListener('changeRecord', this.changeRecord) } @@ -359,40 +981,24 @@ return } MKEmitter.removeListener('nextLine', this.nextLine) + MKEmitter.removeListener('plusLine', this.plusLine) MKEmitter.removeListener('delRecord', this.delRecord) + MKEmitter.removeListener('cleartable', this.cleartable) MKEmitter.removeListener('changeRecord', this.changeRecord) } UNSAFE_componentWillReceiveProps(nextProps) { if (!is(fromJS(this.props.data), fromJS(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() + cleartable = (tbid) => { + const { tableId } = this.state - 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 - }) - }) + if (tbid !== tableId) return + + this.resetData([]) } resetData = (data) => { @@ -400,39 +1006,44 @@ data.push(this.getTotalLine(data)) this.setState({ - edData: data + edData: [] + }, () => { + this.setState({ + edData: data + }) }) } initData = (data) => { let _data = data.map((item, i) => { - item.uuid = Utils.getuuid() + // item.uuid = Utils.getguid() item.index = i + item.$origin = true return item }) 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: ''}) + _data.push({uuid: Utils.getguid(), index: i + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}) } } return _data } getTotalLine = (data) => { - let totalLine = {uuid: Utils.getuuid(), type: 'total'} + let totalLine = {uuid: Utils.getguid(), type: 'total'} let debtor = '' 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 } @@ -543,27 +1154,33 @@ 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 || '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''} + let line = {uuid: Utils.getguid(), index: _data.length - 1, remark: record.remark || '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''} _data.splice(_data.length - 1, 0, line) this.setState({edData: _data}, () => { MKEmitter.emit('tdFocus', 'remark' + line.uuid) }) + this.props.onChange(_data) } } - 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.getguid(), 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) + _data = _data.map((item, index) => { + item.index = index + return item }) + + this.setState({edData: _data}) + this.props.onChange(_data) } delRecord = (id, record) => { @@ -571,19 +1188,25 @@ 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.getguid(), index: 0, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}) } } + + _data = _data.map((item, index) => { + item.index = index + return item + }) _data.push(this.getTotalLine(_data)) this.setState({edData: _data}) + this.props.onChange(_data, record.$origin ? record : null) } changeRecord = (tableId, record) => { @@ -600,187 +1223,13 @@ _data.pop() if (record.index === _data.length - 1) { - _data.push({uuid: Utils.getuuid(), index: record.index + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}) + _data.push({uuid: Utils.getguid(), index: record.index + 1, remark: '', subjectscode: '', subjectsname: '', debtor: '', creditor: ''}) } _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 = () => { - const { edData } = this.state - - if (edData.length === 0) { - notification.warning({ - top: 92, - message: '鎻愪氦鏁版嵁涓嶅彲涓虹┖锛�', - duration: 5 - }) - return - } - let err = '' - let data = fromJS(edData).toJS().map(item => { - // let line = [] - // fields.forEach(col => { - // if (col.editable !== 'true' || item.$deleted) { - // if (col.type === 'number') { - // item[col.field] = +item[col.field] - // if (isNaN(item[col.field])) { - // item[col.field] = 0 - // } - // } else { - // item[col.field] = item[col.field] !== undefined ? (item[col.field] + '') : '' - // } - // return - // } - // if (col.type === 'text') { - // let val = item[col.field] !== undefined ? (item[col.field] + '') : '' - // if (col.required === 'true' && !val) { - // line.push(`${col.label}涓嶅彲涓虹┖`) - // } - // item[col.field] = val - // } else if (col.type === 'number') { - // let val = item[col.field] - // if (!val && val !== 0) { - // line.push(`${col.label}涓嶅彲涓虹┖`) - // return - // } - // val = +val - // if (isNaN(val)) { - // line.push(`${col.label}鏁版嵁鏍煎紡閿欒`) - // return - // } - - // val = +val.toFixed(col.decimal || 0) - - // if (typeof(col.max) === 'number' && val > col.max) { - // line.push(`${col.label}涓嶅彲澶т簬${col.max}`) - // } else if (typeof(col.min) === 'number' && val < col.min) { - // line.push(`${col.label}涓嶅彲灏忎簬${col.min}`) - // } - - // item[col.field] = val - // } - // }) - - return item - }) - - if (err) { - notification.warning({ - top: 92, - message: err, - duration: 5 - }) - } else { - this.submit(data) - } - } - - submit = (data) => { - const { BID } = this.props - - let param = { - // excel_in: result.lines, - BID: BID || '' - } - - this.setState({ - loading: true - }) - - param.func = 'submit.innerFunc' - - Api.genericInterface(param).then((res) => { - if (res.status) { - this.execSuccess(res) - } else { - this.execError(res) - } - }, () => { - this.execError({}) - }) - } - - execSuccess = (res) => { - const { submit } = this.props - - if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛 - notification.success({ - top: 92, - message: res.ErrMesg || this.state.dict['main.action.confirm.success'], - duration: submit.stime ? submit.stime : 2 - }) - } else if (res && res.ErrCode === 'Y') { // 鎵ц鎴愬姛 - Modal.success({ - title: res.ErrMesg || this.state.dict['main.action.confirm.success'] - }) - } else if (res && res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず - - } - - this.setState({ - loading: false - }) - - if (submit.closetab === 'true') { - MKEmitter.emit('popclose') - } - if (submit.execSuccess !== 'never') { - MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit) - } - } - - execError = (res) => { - const { submit } = this.props - - if (res.ErrCode === 'E') { - Modal.error({ - title: res.message || res.ErrMesg, - }) - } else if (res.ErrCode === 'N') { - notification.error({ - top: 92, - message: res.message || res.ErrMesg, - duration: submit.ntime ? submit.ntime : 10 - }) - } else if (res.ErrCode === 'F') { - notification.error({ - className: 'notification-custom-error', - top: 92, - message: res.message || res.ErrMesg, - duration: submit.ftime ? submit.ftime : 10 - }) - } else if (res.ErrCode === 'NM') { - message.error(res.message || res.ErrMesg) - } - - this.setState({ - loading: false - }) - - if (submit.execError !== 'never') { - MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execError, submit) - } + this.props.onChange(_data) } render() { @@ -801,7 +1250,7 @@ columns={columns} dataSource={edData} bordered={true} - // loading={this.props.loading} + loading={this.props.loading} onRow={(record, index) => { return { data: record -- Gitblit v1.8.0