| | |
| | | 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, 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 '@/assets/css/table.scss' |
| | | import './index.scss' |
| | | |
| | | class BodyRow extends React.Component { |
| | |
| | | } |
| | | } |
| | | |
| | | class Accounting extends React.Component { |
| | | state = { |
| | | subAccounts: [] |
| | | } |
| | | |
| | | UNSAFE_componentWillMount() { |
| | | const { data, tableId } = this.props |
| | | let subAccounts = fromJS(data.supAccounts).toJS() |
| | | let msg = window.GLOB.CacheVoucher.get(tableId) || {} |
| | | |
| | | subAccounts = subAccounts.map(item => { |
| | | if (msg[item.field]) { |
| | | item.options = msg[item.field] |
| | | } else if (msg.others) { |
| | | item.options = msg.others.filter(cell => cell.parentId === item.field) |
| | | } else { |
| | | item.options = [] |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | this.setState({subAccounts: subAccounts}) |
| | | } |
| | | |
| | | selectChange = (option, key) => { |
| | | this.setState({ |
| | | subAccounts: fromJS(this.state.subAccounts).toJS().map(cell => { |
| | | if (key === cell.field) { |
| | | cell.value = option ? option.props.value : '' |
| | | cell.name = option ? option.props.name : '' |
| | | } |
| | | return cell |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | 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, option) => this.selectChange(option, item.field)} |
| | | > |
| | | {item.options.map((option, i) => |
| | | <Select.Option key={i} name={option.label} value={option.value}>{option.label}</Select.Option> |
| | | )} |
| | | </Select> |
| | | </Form.Item> |
| | | ) |
| | | }) |
| | | |
| | | return fields |
| | | } |
| | | |
| | | confirm = () => { |
| | | const { data } = this.props |
| | | const { subAccounts } = this.state |
| | | |
| | | let empty = '' |
| | | subAccounts.forEach(item => { |
| | | if (!empty && !item.value) { |
| | | empty = item.label |
| | | } |
| | | }) |
| | | |
| | | if (empty) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请选择' + empty, |
| | | duration: 5 |
| | | }) |
| | | } else { |
| | | let line = fromJS(data).toJS() |
| | | let account = {} |
| | | |
| | | subAccounts.forEach(item => { |
| | | if (item.field === 'supplier') { |
| | | account[item.field] = {suppliercode: item.value, suppliername: item.name} |
| | | } else if (item.field === 'customer') { |
| | | account[item.field] = {customercode: item.value, customername: item.name} |
| | | } else if (item.field === 'department') { |
| | | account[item.field] = {co_pro_code: item.value, co_pro_name: item.name} |
| | | } else if (item.field === 'project') { |
| | | account[item.field] = {projectcode: item.value, projectname: item.name} |
| | | } else if (item.field === 'inventory') { |
| | | account[item.field] = {productcode: item.value, productname: item.name} |
| | | } else if (item.field === 'employee') { |
| | | account[item.field] = {workercode: item.value, workername: item.name} |
| | | } else if (item.field === 'cash_flow') { |
| | | account[item.field] = {cash_flow_code: item.value, cash_flow_name: item.name} |
| | | } else { |
| | | account[item.field] = {sup_acc_code: item.value, sup_acc_name: item.name} |
| | | } |
| | | }) |
| | | |
| | | line.supAccounts = line.supAccounts.map(item => { |
| | | if (account[item.field]) { |
| | | item = {...item, ...account[item.field]} |
| | | } |
| | | return item |
| | | }) |
| | | |
| | | this.props.confirm(line) |
| | | } |
| | | } |
| | | |
| | | 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 () { |
| | |
| | | |
| | | 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 { |
| | | line.debtor = '' |
| | | if (col.field === 'debit') { |
| | | line.credit = '' |
| | | if (isNaN(line.debit)) { |
| | | line.debit = '' |
| | | } |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, line) |
| | | } else { |
| | | line.debit = '' |
| | | if (isNaN(line.credit)) { |
| | | line.credit = '' |
| | | } |
| | | } |
| | | |
| | | if (line.count_type === 'Y' && line.fcc_count) { |
| | | if (line.debit) { |
| | | line.net_unitprice = Math.round(line.debit / line.fcc_count * 10000) / 10000 |
| | | } else if (line.credit) { |
| | | line.net_unitprice = Math.round(line.credit / line.fcc_count * 10000) / 10000 |
| | | } |
| | | } |
| | | |
| | | if (line.foreign_currency_type === 'Y' && line.foreign_amount) { |
| | | if (line.debit) { |
| | | line.unitratio = Math.round(line.debit / line.foreign_amount * 100000) / 100000 |
| | | } else if (line.credit) { |
| | | line.unitratio = Math.round(line.credit / line.foreign_amount * 100000) / 100000 |
| | | } |
| | | } |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, line) |
| | | |
| | | setTimeout(() => { |
| | | if (col.field === 'creditor') { |
| | | if (col.field === 'debit' && (line.debit || line.debit === 0)) { |
| | | MKEmitter.emit('nextLine', col, record) |
| | | } else if (col.field === 'credit') { |
| | | MKEmitter.emit('nextLine', col, record) |
| | | } else { |
| | | let cl = {remark: 'subject', subject: 'debtor', debtor: 'creditor'} |
| | | let cl = {subject_voucher_text: 'subject_code', subject_code: 'debit', debit: 'credit'} |
| | | 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 === 'subject_code') { |
| | | this.setState({editing: true}, () => { |
| | | let node = document.getElementById(col.uuid + record.uuid) |
| | | node && node.click() |
| | | }) |
| | | } else { |
| | | this.setState({editing: true, value: record[col.field]}, () => { |
| | | let node = document.getElementById(col.uuid + record.uuid) |
| | | node && node.select() |
| | | }) |
| | | } |
| | | } |
| | | |
| | | onBlur = () => { |
| | |
| | | if (value !== record[col.field]) { |
| | | let line = {...record, [col.field]: value} |
| | | |
| | | if (col.field === 'debtor') { |
| | | line.creditor = '' |
| | | if (col.field === 'debit') { |
| | | line.credit = '' |
| | | if (isNaN(line.debit)) { |
| | | line.debit = '' |
| | | } |
| | | } else { |
| | | line.debtor = '' |
| | | line.debit = '' |
| | | if (isNaN(line.credit)) { |
| | | line.credit = '' |
| | | } |
| | | } |
| | | |
| | | if (line.count_type === 'Y' && line.fcc_count) { |
| | | if (line.debit) { |
| | | line.net_unitprice = Math.round(line.debit / line.fcc_count * 10000) / 10000 |
| | | } else if (line.credit) { |
| | | line.net_unitprice = Math.round(line.credit / line.fcc_count * 10000) / 10000 |
| | | } |
| | | } |
| | | |
| | | if (line.foreign_currency_type === 'Y' && line.foreign_amount) { |
| | | if (line.debit) { |
| | | line.unitratio = Math.round(line.debit / line.foreign_amount * 100000) / 100000 |
| | | } else if (line.credit) { |
| | | line.unitratio = Math.round(line.credit / line.foreign_amount * 100000) / 100000 |
| | | } |
| | | } |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, line) |
| | |
| | | this.setState({value: val}) |
| | | } |
| | | |
| | | complete = (key, option) => { |
| | | this.setState({value: option.props.value}) |
| | | complete = (val) => { |
| | | 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) |
| | | } |
| | | |
| | | onSelectBlur = () => { |
| | | const { visible } = this.state |
| | | |
| | | if (visible) return |
| | | |
| | | this.setState({editing: false}) |
| | | } |
| | | |
| | | onSelectChange = (val, option) => { |
| | | const { col, record } = this.props |
| | | |
| | | let line = {...record, ...option.props.extra} |
| | | |
| | | line.supAccounts = [] |
| | | |
| | | if (line.sup_accounting) { |
| | | let msg = window.GLOB.CacheVoucher.get(col.tableId) || {} |
| | | let names = msg.names || {} |
| | | |
| | | line.supAccounts = line.sup_accounting.split(',').map(item => { |
| | | return { |
| | | uuid: Utils.getguid(), |
| | | sup_acc_type: item, |
| | | field: item, |
| | | label: names[item] || item, |
| | | initval: '' |
| | | } |
| | | }) |
| | | } |
| | | |
| | | 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.fcc_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', 'debit' + 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.fcc_count || 0}, () => { |
| | | let node = document.getElementById(col.uuid + res.uuid + 'count') |
| | | node && node.select() |
| | | }) |
| | | } else { |
| | | setTimeout(() => { |
| | | MKEmitter.emit('tdFocus', 'debit' + 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.subject_code = '' |
| | | record.subject_name = '' |
| | | record.sup_accounting = '' |
| | | record.supAccounts = [] |
| | | |
| | | 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.fcc_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.net_unitprice || 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.fcc_count = value || 0 |
| | | |
| | | if (isNaN(line.fcc_count)) { |
| | | line.fcc_count = 0 |
| | | } |
| | | |
| | | this.countChange(line) |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, line) |
| | | |
| | | this.setState({counting: false, priceing: true, value: line.net_unitprice || 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.fcc_count = value || 0 |
| | | |
| | | if (isNaN(line.fcc_count)) { |
| | | line.fcc_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.net_unitprice = value || 0 |
| | | |
| | | if (isNaN(line.net_unitprice)) { |
| | | line.net_unitprice = 0 |
| | | } |
| | | |
| | | this.countChange(line) |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, line) |
| | | |
| | | this.setState({priceing: false}) |
| | | setTimeout(() => { |
| | | MKEmitter.emit('tdFocus', 'debit' + record.uuid) |
| | | }, 50) |
| | | } |
| | | |
| | | priceBlur = () => { |
| | | const { col, record } = this.props |
| | | const { value } = this.state |
| | | |
| | | this.setState({priceing: false}) |
| | | |
| | | let line = {...record} |
| | | line.net_unitprice = value || 0 |
| | | |
| | | if (isNaN(line.net_unitprice)) { |
| | | line.net_unitprice = 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.foreign_amount || 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.foreign_amount || 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.foreign_amount || 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.foreign_amount = value || 0 |
| | | |
| | | if (isNaN(line.foreign_amount)) { |
| | | line.foreign_amount = 0 |
| | | } |
| | | |
| | | this.currencyChange(line) |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, line) |
| | | |
| | | this.setState({origining: false}) |
| | | |
| | | setTimeout(() => { |
| | | MKEmitter.emit('tdFocus', 'debit' + record.uuid) |
| | | }, 50) |
| | | } |
| | | |
| | | originBlur = () => { |
| | | const { col, record } = this.props |
| | | const { value } = this.state |
| | | |
| | | this.setState({origining: false}) |
| | | |
| | | let line = {...record} |
| | | line.foreign_amount = value || 0 |
| | | |
| | | if (isNaN(line.foreign_amount)) { |
| | | line.foreign_amount = 0 |
| | | } |
| | | |
| | | this.currencyChange(line) |
| | | |
| | | MKEmitter.emit('changeRecord', col.tableId, line) |
| | | } |
| | | |
| | | countChange = (line) => { |
| | | if (line.fcc_count && line.net_unitprice) { |
| | | if (line.credit) { |
| | | line.credit = Math.round(line.fcc_count * line.net_unitprice * 100) / 100 |
| | | } else { |
| | | line.debit = Math.round(line.fcc_count * line.net_unitprice * 100) / 100 |
| | | } |
| | | |
| | | if (line.foreign_currency_type === 'Y' && line.foreign_amount) { |
| | | if (line.debit) { |
| | | line.unitratio = Math.round(line.debit / line.foreign_amount * 100000) / 100000 |
| | | } else if (line.credit) { |
| | | line.unitratio = Math.round(line.credit / line.foreign_amount * 100000) / 100000 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | currencyChange = (line) => { |
| | | if (line.unitratio && line.foreign_amount) { |
| | | if (line.credit) { |
| | | line.credit = Math.round(line.unitratio * line.foreign_amount * 100) / 100 |
| | | } else { |
| | | line.debit = Math.round(line.unitratio * line.foreign_amount * 100) / 100 |
| | | } |
| | | |
| | | if (line.count_type === 'Y' && line.fcc_count) { |
| | | if (line.debit) { |
| | | line.net_unitprice = Math.round(line.debit / line.fcc_count * 10000) / 10000 |
| | | } else if (line.credit) { |
| | | line.net_unitprice = Math.round(line.credit / line.fcc_count * 10000) / 10000 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | let { col, record, className } = this.props |
| | | const { editing } = this.state |
| | | 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 || '' |
| | | if (col.field === 'subject_voucher_text') { |
| | | let val = record.subject_voucher_text || '' |
| | | |
| | | if (record.type === 'total') { |
| | | children = <div className="content-wrap" style={{lineHeight: '60px'}}>合计: {val}</div> |
| | | colSpan = 2 |
| | | } else { |
| | | extra = <PlusOutlined onClick={this.plusLine}/> |
| | | |
| | | if (editing) { |
| | | let options = ['现金', '发票'] |
| | | let options = localStorage.getItem(window.GLOB.host + '_voucher_extract') |
| | | options = options ? JSON.parse(options) : [] |
| | | |
| | | children = <AutoComplete |
| | | dataSource={options.map((cell, i) => <AutoComplete.Option value={cell} key={i}> |
| | | {cell} |
| | |
| | | filterOption={(input, option) => option.props.children.indexOf(input) > -1} |
| | | onSelect={this.complete} |
| | | defaultValue={val} |
| | | onChange={(val) => this.onChange(val)} |
| | | defaultOpen={true} |
| | | > |
| | | <Input.TextArea id={col.uuid + record.uuid} autoSize={false} defaultValue={val} onChange={(e) => this.onChange(e.target.value)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | <Input.TextArea id={col.uuid + record.uuid} autoSize={false} defaultValue={val} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | </AutoComplete> |
| | | } else { |
| | | children = <div className="content-wrap" onClick={this.focus}>{val}</div> |
| | | } |
| | | } |
| | | } else if (col.field === 'subject') { |
| | | } else if (col.field === 'subject_code') { |
| | | 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}/> |
| | | } else { |
| | | children = <div className="content-wrap" onClick={this.focus}>{val}</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() |
| | | } |
| | | let msg = window.GLOB.CacheVoucher.get(col.tableId) |
| | | let subjects = msg ? msg.subjects : [] |
| | | |
| | | children = <> |
| | | <Select |
| | | showSearch |
| | | defaultValue={record.subject_code || ''} |
| | | 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.subject_code}>{item.subject_code + ' ' + item.subject_name}</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.subject_code) { |
| | | val = (record.subject_code || '') + ' ' + (record.subject_name || '') |
| | | |
| | | if (record.sup_accounting && record.supAccounts) { |
| | | record.supAccounts.forEach(item => { |
| | | if (item.sup_acc_type === 'supplier') { |
| | | val += item.suppliercode ? '_' + item.suppliercode + ' ' + item.suppliername : '' |
| | | } else if (item.sup_acc_type === 'customer') { |
| | | val += item.customercode ? '_' + item.customercode + ' ' + item.customername : '' |
| | | } else if (item.sup_acc_type === 'department') { |
| | | val += item.co_pro_code ? '_' + item.co_pro_code + ' ' + item.co_pro_name : '' |
| | | } else if (item.sup_acc_type === 'project') { |
| | | val += item.projectcode ? '_' + item.projectcode + ' ' + item.projectname : '' |
| | | } else if (item.sup_acc_type === 'inventory') { |
| | | val += item.productcode ? '_' + item.productcode + ' ' + item.productname : '' |
| | | } else if (item.sup_acc_type === 'employee') { |
| | | val += item.workercode ? '_' + item.workercode + ' ' + item.workername : '' |
| | | } else if (item.sup_acc_type === 'cash_flow') { |
| | | val += item.cash_flow_code ? '_' + item.cash_flow_code + ' ' + item.cash_flow_name : '' |
| | | } else if (item.sup_acc_code) { |
| | | val += '_' + item.sup_acc_code + ' ' + item.sup_acc_name |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | 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.fcc_count || 0} onChange={(val) => this.onChange(val)} onPressEnter={this.countPress} onBlur={this.countBlur}/></span> |
| | | </span> |
| | | <span onClick={this.editPrice}> |
| | | <span>单价:</span> |
| | | <span>{record.net_unitprice || 0}</span> |
| | | </span> |
| | | </div> |
| | | } else if (priceing) { |
| | | countNode = <div className="count-wrap"> |
| | | <span style={{marginRight: '5px'}} onClick={this.editCount}> |
| | | <span>数量:</span> |
| | | <span>{record.fcc_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.net_unitprice || 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.fcc_count || 0}</span> |
| | | </span> |
| | | <span onClick={this.editPrice}> |
| | | <span>单价:</span> |
| | | <span>{record.net_unitprice || 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.foreign_amount || 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.foreign_amount || 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.foreign_amount || 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.foreign_amount || 0}</span> |
| | | </span> |
| | | </div> |
| | | } |
| | | } |
| | | |
| | | children = <div className="content-wrap" onClick={this.focus}> |
| | | {val} |
| | | {countNode} |
| | | {currencyNode} |
| | | </div> |
| | | } |
| | | } |
| | | } else if (col.field === 'debit') { |
| | | 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.debit} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | } else { |
| | | let val = record.debit |
| | | 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() |
| | | } |
| | | } else if (col.field === 'credit') { |
| | | 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.credit} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/> |
| | | } else { |
| | | let val = record.credit |
| | | 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>) |
| | | } |
| | | } |
| | | |
| | | class VoucherTable extends Component { |
| | | static propTpyes = { |
| | | config: PropTypes.object, // 菜单Id |
| | | 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 } = 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, data } = this.props |
| | | |
| | | let columns = [ |
| | | { |
| | | title: '摘要', |
| | | dataIndex: 'remark', |
| | | key: 'remark', |
| | | dataIndex: 'subject_voucher_text', |
| | | key: 'subject_voucher_text', |
| | | width: '22%', |
| | | onCell: record => ({ |
| | | record, |
| | | col: {uuid: 'remark', field: 'remark', tableId: config.uuid}, |
| | | col: {uuid: 'subject_voucher_text', field: 'subject_voucher_text', tableId: config.uuid}, |
| | | }) |
| | | }, |
| | | { |
| | | title: '会计科目', |
| | | dataIndex: 'subject', |
| | | key: 'subject', |
| | | dataIndex: 'subject_code', |
| | | key: 'subject_code', |
| | | width: '34%', |
| | | onCell: record => ({ |
| | | record, |
| | | col: {uuid: 'subject', field: 'subject', tableId: config.uuid}, |
| | | col: {uuid: 'subject_code', field: 'subject_code', tableId: config.uuid}, |
| | | }) |
| | | }, |
| | | { |
| | |
| | | <span>百</span> <span>十</span> <span>元</span> <span>角</span> <span className="last">分</span> |
| | | </div> |
| | | </>), |
| | | dataIndex: 'debtor', |
| | | key: 'debtor', |
| | | dataIndex: 'debit', |
| | | key: 'debit', |
| | | width: '22%', |
| | | onCell: record => ({ |
| | | record, |
| | | col: {uuid: 'debtor', field: 'debtor', tableId: config.uuid}, |
| | | col: {uuid: 'debit', field: 'debit', tableId: config.uuid}, |
| | | }) |
| | | }, |
| | | { |
| | |
| | | <span>百</span> <span>十</span> <span>元</span> <span>角</span> <span className="last">分</span> |
| | | </div> |
| | | </>), |
| | | dataIndex: 'creditor', |
| | | key: 'creditor', |
| | | dataIndex: 'credit', |
| | | key: 'credit', |
| | | width: '22%', |
| | | onCell: record => ({ |
| | | record, |
| | | col: {uuid: 'creditor', field: 'creditor', tableId: config.uuid}, |
| | | col: {uuid: 'credit', field: 'credit', tableId: config.uuid}, |
| | | }) |
| | | } |
| | | ] |
| | | |
| | | this.setState({ |
| | | data: data, |
| | | edData: fromJS(data).toJS(), |
| | | edData: this.resetData(fromJS(data).toJS()), |
| | | columns, |
| | | tableId: config.uuid |
| | | }) |
| | |
| | | |
| | | 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) |
| | | } |
| | | |
| | |
| | | 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.setState({data: nextProps.data || []}) |
| | | this.resetData(fromJS(nextProps.data).toJS()) |
| | | } |
| | | } |
| | | |
| | | cleartable = (tbid) => { |
| | | const { tableId } = this.state |
| | | |
| | | if (tbid !== tableId) return |
| | | |
| | | this.resetData([]) |
| | | } |
| | | |
| | | resetData = (data) => { |
| | | data = this.initData(data) |
| | | data.push(this.getTotalLine(data)) |
| | | |
| | | this.setState({ |
| | | edData: [] |
| | | }, () => { |
| | | this.setState({ |
| | | edData: data |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | initData = (data) => { |
| | | let _data = data.map((item, i) => { |
| | | item.uuid = Utils.getuuid() |
| | | // item.uuid = Utils.getguid() |
| | | item.index = i |
| | | |
| | | return item |
| | |
| | | |
| | | 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.getguid(), index: i + 1, subject_voucher_text: '', subject_code: '', subject_name: '', debit: '', credit: ''}) |
| | | } |
| | | } |
| | | return _data |
| | | } |
| | | |
| | | getTotalLine = (data) => { |
| | | let totalLine = {uuid: Utils.getuuid(), type: 'total'} |
| | | let debtor = '' |
| | | let creditor = '' |
| | | let totalLine = {uuid: Utils.getguid(), type: 'total'} |
| | | let debit = '' |
| | | let credit = '' |
| | | |
| | | data.forEach(item => { |
| | | if (typeof(item.debtor) === 'number') { |
| | | if (debtor === '') { |
| | | debtor = 0 |
| | | if (!isNaN(item.debit) && item.debit !== '') { |
| | | if (debit === '') { |
| | | debit = 0 |
| | | } |
| | | |
| | | debtor += item.debtor |
| | | } else if (typeof(item.creditor) === 'number') { |
| | | if (debtor === '') { |
| | | debtor = 0 |
| | | debit += item.debit |
| | | } else if (!isNaN(item.credit) && item.credit !== '') { |
| | | if (debit === '') { |
| | | debit = 0 |
| | | } |
| | | if (creditor === '') { |
| | | creditor = 0 |
| | | if (credit === '') { |
| | | credit = 0 |
| | | } |
| | | creditor += item.creditor |
| | | credit += item.credit |
| | | } |
| | | }) |
| | | |
| | | totalLine.debtor = debtor |
| | | totalLine.creditor = creditor |
| | | totalLine.debit = debit |
| | | totalLine.credit = credit |
| | | |
| | | totalLine.remark = this.changeMoneyToChinese(debtor) |
| | | totalLine.subject_voucher_text = this.changeMoneyToChinese(debit) |
| | | |
| | | return totalLine |
| | | } |
| | |
| | | if (col.tableId !== tableId) return |
| | | |
| | | if (record.index < edData.length - 2) { |
| | | MKEmitter.emit('tdFocus', 'remark' + edData[record.index + 1].uuid) |
| | | MKEmitter.emit('tdFocus', 'subject_voucher_text' + 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.getguid(), index: _data.length - 1, subject_voucher_text: record.subject_voucher_text || '', subject_code: '', subject_name: '', debit: '', credit: ''} |
| | | |
| | | _data.splice(_data.length - 1, 0, line) |
| | | |
| | | this.setState({edData: _data}, () => { |
| | | MKEmitter.emit('tdFocus', 'remark' + line.uuid) |
| | | MKEmitter.emit('tdFocus', 'subject_voucher_text' + 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, subject_voucher_text: '', subject_code: '', subject_name: '', debit: '', credit: ''} |
| | | |
| | | 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) => { |
| | |
| | | |
| | | 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: '', subject: '', debtor: '', creditor: ''}) |
| | | for (let i = _data.length; i < 4; i++) { |
| | | _data.push({uuid: Utils.getguid(), index: 0, subject_voucher_text: '', subject_code: '', subject_name: '', debit: '', credit: ''}) |
| | | } |
| | | } |
| | | |
| | | _data = _data.map((item, index) => { |
| | | item.index = index |
| | | return item |
| | | }) |
| | | |
| | | _data.push(this.getTotalLine(_data)) |
| | | |
| | | this.setState({edData: _data}) |
| | | this.props.onChange(_data) |
| | | } |
| | | |
| | | changeRecord = (tableId, record) => { |
| | |
| | | _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.getguid(), index: record.index + 1, subject_voucher_text: '', subject_code: '', subject_name: '', debit: '', credit: ''}) |
| | | } |
| | | |
| | | _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() { |
| | |
| | | columns={columns} |
| | | dataSource={edData} |
| | | bordered={true} |
| | | // loading={this.props.loading} |
| | | loading={this.props.loading} |
| | | onRow={(record, index) => { |
| | | return { |
| | | data: record |