ttk-app-core
Version:
enterprise develop framework
1,043 lines (930 loc) • 73.1 kB
JavaScript
import React from 'react'
import { action as MetaAction, AppLoader } from 'edf-meta-engine'
import { TableOperate, Select, LoadingMask, Button, Modal, Input, Checkbox, Icon } from 'edf-component'
import { accountTypeEnum, clearThousandsPosition, combineAuxItemContent, ACCOUNTTYPE_PROFITANDLOSS, ACCOUNTTYPE_ASSETS } from './data'
import { fromJS, set } from 'immutable'
import config from './config'
//import moment from 'moment'
import utils from 'edf-utils'
//import extend from './extend'
import * as data from './data'
// import { setTimeout } from 'timers'
import { consts } from 'edf-consts'
class action {
constructor(option) {
this.metaAction = option.metaAction
//this.extendAction = option.extendAction
this.config = config.current
this.webapi = this.config.webapi
this.menuList = {}
this.clickWraper = {}
this.isHaveResult = false
}
componentDidMount = () => {
const win = window
if (win.addEventListener) {
win.addEventListener('resize', this.onResize, false)
} else if (win.attachEvent) {
win.attachEvent('onresize', this.onResize)
} else {
win.onresize = this.onResize
}
}
componetWillUnmount = () => {
const win = window
if (win.removeEventListener) {
win.removeEventListener('resize', this.onResize, false)
} else if (win.detachEvent) {
win.detachEvent('onresize', this.onResize)
} else {
win.onresize = undefined
}
}
onResize = (e) => {
let keyRandom = Math.floor(Math.random() * 10000)
this.keyRandom = keyRandom
setTimeout(() => {
if (this.keyRandom == keyRandom) {
this.computeFun(e)
}
}, 100)
}
computeFun = (e) => {
const wrapContent = document.getElementById('app-account-beginbalance-id')
const headerContent = document.getElementById('app-account-beginbalance-header-id')
const tabHeadContent = document.getElementById('app-account-beginbalance-tabHeaderDiv-id')
const singleRowContent = document.getElementById("app-account-beginbalance-singleRowContent-id") ?
document.getElementById("app-account-beginbalance-singleRowContent-id").getElementsByTagName('tbody')[0] : ''
const doubleRowContent = document.getElementById("app-account-beginbalance-doubleRowContent-id")
? document.getElementById("app-account-beginbalance-doubleRowContent-id").getElementsByTagName('tbody')[0] : ''
const isCalcQuantity = this.metaAction.gf('data.filter.isCalcQuantity')
const isCalcMulti = this.metaAction.gf('data.filter.isCalcMulti')
const isNotJanuary = this.metaAction.gf('data.other.isNotJanuary')
if (isCalcQuantity || isCalcMulti) {
if (!doubleRowContent) {
if (e) {
return
}
setTimeout(() => {
this.computeFun()
}, 500)
} else {
const wrapContentHeight = wrapContent.offsetHeight
const headerContentHeight = headerContent.offsetHeight
const tabHeadContentHeight = tabHeadContent.offsetHeight
const doubleRowContentHeight = doubleRowContent.offsetHeight
const num = !isNotJanuary ? 85 : 83
let tableDivHeight
tableDivHeight = doubleRowContentHeight < wrapContentHeight - headerContentHeight - tabHeadContentHeight - num ? 0 : wrapContentHeight - headerContentHeight - tabHeadContentHeight - num
const saveTabDivHeight = this.metaAction.gf('data.other.scrollY')
if (saveTabDivHeight != tableDivHeight) {
this.injections.reduce('setScroll', tableDivHeight)
}
}
} else {
if (!singleRowContent) {
if (e) {
return
}
setTimeout(() => {
this.computeFun()
}, 500)
} else {
const wrapContentHeight = wrapContent.offsetHeight
const headerContentHeight = headerContent.offsetHeight
const tabHeadContentHeight = tabHeadContent.offsetHeight
const singleRowContentHeight = singleRowContent.offsetHeight
let tableDivHeight
tableDivHeight = singleRowContentHeight < wrapContentHeight - headerContentHeight - tabHeadContentHeight - 49 ? 0 : wrapContentHeight - headerContentHeight - tabHeadContentHeight - 49
const saveTabDivHeight = this.metaAction.gf('data.other.scrollY')
if (saveTabDivHeight != tableDivHeight) {
this.injections.reduce('setScroll', tableDivHeight)
}
}
}
}
onInit = ({ component, injections }) => {
//this.extendAction.gridAction.onInit({ component, injections })
this.component = component
this.injections = injections
let option = {
isGuide: this.component.props.isGuide,
menuKey: this.component.props.isMenuCode
}
this.menuList = option
injections.reduce('init', option)
let addEventListener = this.component.props.addEventListener
if (addEventListener) {
addEventListener('onTabFocus', :: this.onTabFocus)
addEventListener('enlargeClick', () => this.onResize({}))
}
this.initBalanceView()
//处理财务期初初始化按钮显示
this.injections.reduce('isShowBtn',this.component.props && this.component.props.appExtendParams)
}
initBalanceView = async () => {
// let accountTypeId = accountTypeEnum.ACCOUNT_ASSETS
let accountTypeId = ACCOUNTTYPE_ASSETS
let year = this.metaAction.context.get("currentOrg").enabledYear
year = Number(year)
let option = {
accountTypeId: accountTypeId,
year: year,
isCalcQuantity: false,
isCalcMulti: false
}
let currentOrg = this.metaAction.context.get("currentOrg"),
accountingStandards = currentOrg.accountingStandards == consts.ACCOUNTINGSTANDARDS_2013
// const response = await this.webapi.init({ accountTypeId: accountTypeId })
const response = await this.webapi.init(option)
this.metaAction.sf('data.other.isLoading', false)
let enabledPeriod = { enabledYear: response.enabledYear ? response.enabledYear : '', enabledMonth: response.enabledMonth ? response.enabledMonth : '', ts: response.ts ? response.ts : '' },
selectedYear,
calcDict = response.calcDict, haveMonthlyClosing = response.haveMonthlyClosing,
settedPeriod = `${response.enabledYear}-${response.enabledMonth}`
this.injections.reduce('initBalanceView', response, year, settedPeriod, enabledPeriod, accountingStandards, accountTypeId, calcDict, haveMonthlyClosing)
setTimeout(() => {
this.computeFun()
}, 20)
// //启用期间为空时,系统弹出启用期间选择对话框,供操作员选择启用的期间;COMMENT START 0102 TODO
if (!response.enabledYear) {
// resetPeriodBegin('setStartMonth')
this.changeEnabledPeriod()
}
}
loadBalanceData = async (accountType, selectedYear) => {
let currentOrg = this.metaAction.context.get("currentOrg"),
accountingStandards = currentOrg.accountingStandards == consts.ACCOUNTINGSTANDARDS_2013
let accountTypeNew = accountType
// 若之前为企业准则而且选择的是共同这一项时 切到期初时默认显示资产这列
if (accountTypeNew == 5000010003 && accountingStandards) {
accountTypeNew = 5000010001
}
let year = this.metaAction.context.get("currentOrg").enabledYear
year = Number(year)
let option = {
accountTypeId: accountTypeNew,
// year: selectedYear,
year: year,
isCalcQuantity: !!this.metaAction.gf('data.filter.isCalcQuantity'),
isCalcMulti: !!this.metaAction.gf('data.filter.isCalcMulti')
}
const response = await this.webapi.init(option)
this.metaAction.sf('data.other.isLoading', false)
let enabledPeriod = { enabledYear: response.enabledYear, enabledMonth: response.enabledMonth, ts: response.ts ? response.ts : '' },
calcDict = response.calcDict, haveMonthlyClosing = response.haveMonthlyClosing,
settedPeriod = `${response.enabledYear}-${response.enabledMonth}`
this.injections.reduce('loadBalanceData', response, year, settedPeriod, enabledPeriod, accountingStandards, accountTypeNew, calcDict, haveMonthlyClosing)
setTimeout(() => {
this.computeFun()
}, 20)
}
onTabFocus = () => {
let accountType = this.metaAction.gf('data.filter.targetKey'),
selectedYear = this.metaAction.gf('data.other.year').get('id')
this.loadBalanceData(accountType, selectedYear)
}
tabChange = async (key) => {
let selectedYear = this.metaAction.gf('data.other.year').get('id')
this.loadBalanceData(key, selectedYear)
}
reload = async () => {
const pagination = this.metaAction.gf('data.pagination').toJS()
const filter = this.metaAction.gf('data.filter').toJS()
this.load(pagination, filter)
}
getDisabledDate = (current) => {
var disabledDate = new Date(this.metaAction.gf('data.other.settedPeriod'))
return current && current.valueOf() < disabledDate
}
renderColumns = (columnName, v, path, rowIndex) => {
let list = this.metaAction.gf('data.list'),
// rowIndex = list.toJS().findIndex((x) => x.accountCode == v.accountCode),
text = list ? list.get(rowIndex).get(columnName) : '',
isEndNode = list ? !!list.get(rowIndex).get('isEndNode') : false,
isCalc = list ? !!list.get(rowIndex).get('isCalc') : false,
isDetailData = list ? !!list.get(rowIndex).get('isDetailData') : false,
isCalcMulti = list ? !!list.get(rowIndex).get('isCalcMulti') : false,
enabledYear = this.metaAction.gf('data.other.enabledYear'),
selectedYear = this.metaAction.gf('data.other.year'),
// haveMonthlyClosing = this.metaAction.gf('data.other.haveMonthlyClosing'), //是否月结
// editable = enabledYear == selectedYear.get('id') ? (isEndNode && !(isCalc || isCalcMulti) && enabledYear == selectedYear.get('id')) || isDetailData : false,
editable = (isEndNode && !(isCalc || isCalcMulti)) || isDetailData, //年份下拉选去掉 不再受年份控制
// editable = !haveMonthlyClosing && ((isEndNode && !(isCalc || isCalcMulti)) || isDetailData), //年份下拉选去掉 不再受年份控制 已经月结的不能再进行操作
accountCode = list ? list.get(rowIndex).get('accountCode') : '',
oldValue = list ? list.get(rowIndex).get(columnName) : '',
isResetVisible = this.metaAction.gf('data.other.isResetVisible'),
customAttribute = this.metaAction.gf('data.other.customAttribute') //为了只有操作另一个input时才去render input
if(!text){
text = ''
}else if(columnName == 'quantityDr'||columnName =='beginQuantity'||columnName=='quantityCr'||columnName=='yearBeginQuantity'){
// console.log(text)
text = text && text
// text = utils.number.format(text,6)
}else{
text = text && text
}
return (
<EditableCell
editable={editable}
value={text}
disabled={!isResetVisible}
onBlur={(value) => this.handleBlur(rowIndex, columnName, value)}
onEnter={(e) => this.handleEnter(e, rowIndex, columnName)}
// onkeydown={(e) => this.handleKeyDown(e, rowIndex, columnName)}
customAttribute={customAttribute}
rowIndex={rowIndex}
columnName={columnName}
/>
)
}
handleKeyDown = (e, rowIndex, columnName) => {
const inputs = document.getElementsByClassName('ant-input mk-input-number app-account-beginbalance-tableClass')
let index = $(inputs).index(e.target),
newValue = e.target.value,
list = this.metaAction.gf('data.list', list),
errorMessage = this.getErrorMessage(columnName)
// 获取光标当前位置
let cursorPosition = utils.dom.getCursorPosition(e.target)
// let newValue = e.target.value,list = this.metaAction.gf('data.list', list),errorMessage = this.getErrorMessage(columnName)
if (e.keyCode == 38 || e.keyCode == 40 || e.keyCode == 37 || e.keyCode == 39 || e.keyCode == 13 || e.keyCode == 108 || e.key == 'Enter') {
if (newValue && newValue.indexOf(',') > -1) {
newValue = newValue.replace(/,/g, '')
}
if (newValue && newValue > 9999999999.99) {
this.metaAction.toast('warning', `${errorMessage}不能大于9,999,999,999.99,请调整`)
return
}
if (newValue && newValue < -9999999999.99) {
this.metaAction.toast('warning', `${errorMessage}不能小于9,999,999,999.99,请调整`)
return
}
if (newValue && isNaN(Number(parseFloat(newValue)))) {
this.metaAction.toast('warning', '请输入数字')
return
}
switch (e.keyCode) {
case 38: //上
index = index - 3
if (index < 0) {
index = index + 3
}
break;
case 40: // 下
index = index + 3
if (index > inputs.length - 1) {
index = index - 3
}
break;
case 37: // 左
// if (cursorPosition == 1 || cursorPosition == 0) {
if (cursorPosition == 1) {
index = index - 1
if (index < 0) {
index = index + 1
}
}
break;
case 39: //右
// if (cursorPosition == String(newValue).length + 1 || cursorPosition == String(newValue).length) {
if (cursorPosition == String(newValue).length + 1) {
index = index + 1
if (index > inputs.length - 1) {
index = index - 1
}
}
break;
case 13: //ENTER
index = index + 1
break;
case 108:
index = index + 1
break;
default: return
}
}
inputs[index].focus()
}
onExit = (tour) => {
const intro = tour
if (intro.action == 'skip' || intro.status == 'finished') {
let stepEnabled = this.metaAction.gf('data.other.stepEnabled')
if (stepEnabled == true) {
this.metaAction.sf('data.other.stepEnabled', false)
let params = { "menuId": this.menuList.menuKey, "isVisible": false }
this.webapi.updateGuide(params)
this.component.props.closeGuide &&
this.component.props.closeGuide(this.component.props.appName)
}
}
}
/**
* 财务期初-上一步
*/
preStep = async () => {
if (this.component.props) {
const appParams = this.component.props && this.component.props.appExtendParams
if (appParams && !appParams.preStep){
appParams.preStep ='app-account-subjects'
}
this.component.props.setPortalContent('科目初始化', appParams.preStep, appParams)
}
}
/**
* 财务期初-完成
*/
finish = async () => {
if (this.component.props) {
const appParams = this.component.props && this.component.props.appExtendParams
this.component.props.setPortalContent('完成', 'ttk-gl-app-financeinit-success', appParams)
}
}
handleEnter = (e, rowIndex, columnName) => { //enter键切换input框
if (e.keyCode == 13 || e.key == 'Enter' || e.keyCode == 108) {
const inputs = document.getElementsByClassName('ant-input mk-input-number app-account-beginbalance-tableClass')
const index = $(inputs).index(e.target)
let newValue = e.target.value, list = this.metaAction.gf('data.list', list), errorMessage = this.getErrorMessage(columnName)
if (newValue && newValue > 9999999999.99) {
this.metaAction.toast('warning', `${errorMessage}不能大于9,999,999,999.99,请调整`)
return
}
if (newValue && newValue < -9999999999.99) {
this.metaAction.toast('warning', `${errorMessage}不能小于9,999,999,999.99,请调整`)
return
}
if (newValue && newValue.indexOf(',') > -1) {
newValue = newValue.replace(/,/g, '')
}
if (isNaN(newValue)) {
this.metaAction.toast('warning', '请输入数字')
return
}
inputs[index + 1].focus()
}
}
handleBlur = (rowIndex, columnName, value) => {
// LoadingMask.show()
let list = this.metaAction.gf('data.list'),
oldValue = list.get(rowIndex).get(columnName),
newValue = value,
errorMessage = this.getErrorMessage(columnName)
list = list.update(rowIndex, item => item.set(columnName, newValue))
// newValue = value ? parseFloat(value).toFixed(2) : value
if (newValue && newValue.indexOf && newValue.indexOf(',') > -1) { //对于修改格式化好的数字 避免isNaN为true
newValue = newValue.replace(/,/g, '')
}
if (newValue > 9999999999.99) {
newValue = undefined
list = list.update(rowIndex, item => {
item = item.set(columnName, newValue)
return item
})
this.metaAction.sf('data.list', list)
this.metaAction.toast('warning', `${errorMessage}不能大于9,999,999,999.99,请调整`)
return
}
if (newValue < -9999999999.99) {
newValue = undefined
list = list.update(rowIndex, item => {
item = item.set(columnName, newValue)
return item
})
this.metaAction.sf('data.list', list)
this.metaAction.toast('warning', `${errorMessage}不能小于9,999,999,999.99,请调整`)
return
}
if (isNaN(newValue)) {
this.metaAction.toast('warning', '请输入数字')
return
}
list = list.update(rowIndex, item => item.set(columnName, newValue))
this.metaAction.sf('data.list', list)
const customAttribute = Math.random()
this.metaAction.sf('data.other.customAttribute', customAttribute)
this.onFieldChange(columnName + ',' + rowIndex, oldValue, rowIndex)(newValue)
}
setField = async (path, value) => {
let res = await this.changeEnabledPeriod(value)
}
onFieldChange = (path, oldValue, rowIndex) => (newValue) => {
let accountType = this.metaAction.gf('data.filter.targetKey'),
selectedYear = this.metaAction.gf('data.other.year').get('id'),
errorMessage
//if(oldValue.toString() === newValue) return
if (oldValue == newValue) return
//数量、金额、外币变更时,上级科目及年初余额计算
if (path.indexOf('beginQuantity') > -1 ||
path.indexOf('beginAmount') > -1 ||
path.indexOf('beginOrigAmount') > -1 ||
path.indexOf('quantityDr') > -1 ||
path.indexOf('amountDr') > -1 ||
path.indexOf('origAmountDr') > -1 ||
path.indexOf('quantityCr') > -1 ||
path.indexOf('amountCr') > -1 ||
path.indexOf('origAmountCr') > -1) {
// let rowIndex = path.split(',')[1],
let curEditField = path.split(',')[0], curYearTotalAmountField, beginAmountField,
accountType = this.metaAction.gf('data.other.accountType'),
errorMessage = this.getErrorMessage(curEditField),
list = this.metaAction.gf('data.list')
// newValue = clearThousandsPosition(newValue)
if (newValue && newValue.toString().indexOf(',') > -1) {
newValue = newValue.replace(/,/g, '')
}
let dataName = 'list'
let curBeginBalance = (this.metaAction.gf('data.list')).toJS()[rowIndex] //当前期初余额行
// console.log(curBeginBalance, rowIndex, '当前行')
// 如果是本位币是人民币 填写期初余额时本位币金额和外币保持一致
const isBaseCurrency = curBeginBalance.isBaseCurrency
if (isBaseCurrency) {
switch (curEditField) {
case 'beginOrigAmount':
beginAmountField = 'beginAmount'
break;
case 'beginAmount':
beginAmountField = 'beginOrigAmount'
break;
case 'origAmountDr':
beginAmountField = 'amountDr'
break;
case 'amountDr':
beginAmountField = 'origAmountDr'
break;
case 'amountCr':
beginAmountField = 'origAmountCr'
break;
case 'origAmountCr':
beginAmountField = 'amountCr'
break;
default: beginAmountField = curEditField
}
}
let isPositiveNum = false
//在期初余额,在录入【财务费用-利息收入】的【借方累计、贷方累计】录入时,提示用户请录入负值,包含数量、外币、金额
if ((path.indexOf('quantityDr') > -1 ||
path.indexOf('origAmountDr') > -1 ||
path.indexOf('amountDr') > -1 ||
path.indexOf('quantityCr') > -1 ||
path.indexOf('origAmountCr') > -1 ||
path.indexOf('amountCr') > -1) &&
curBeginBalance.cashTypeId == 203 && //203:利息收入
parseFloat(newValue) > 0) {
isPositiveNum = true
newValue = -parseFloat(newValue)
}
//损益类科目时,填写了借方(贷方)累计金额后,贷方(借方)累计金额自动取相同值
//为了保持年初余额为零
if (accountType == ACCOUNTTYPE_PROFITANDLOSS && curEditField == 'amountDr') {
curYearTotalAmountField = 'amountCr'
} else if (accountType == ACCOUNTTYPE_PROFITANDLOSS && curEditField == 'amountCr') {
curYearTotalAmountField = 'amountDr'
}
if (accountType == data.ACCOUNTTYPE_PROFITANDLOSS && curEditField == 'origAmountCr') {
curYearTotalAmountField = 'origAmountDr'
} else if (accountType == data.ACCOUNTTYPE_PROFITANDLOSS && curEditField == 'origAmountDr') {
curYearTotalAmountField = 'origAmountCr'
}
//本年借方和贷方的数量也要保持一致
if (accountType == data.ACCOUNTTYPE_PROFITANDLOSS && curEditField == 'quantityDr') {
curYearTotalAmountField = 'quantityCr'
} else if (accountType == data.ACCOUNTTYPE_PROFITANDLOSS && curEditField == 'quantityCr') {
curYearTotalAmountField = 'quantityDr'
}
let listBalance = [],
// curEditBeginBalance = this.getBalanceItem(curBeginBalance, curEditField, newValue, curYearTotalAmountField)
curEditBeginBalance = this.getBalanceItem(curBeginBalance, curEditField, newValue, curYearTotalAmountField, beginAmountField)
// curEditBeginBalance.year = this.getSelectedYear()
curEditBeginBalance.year = this.metaAction.gf('data.other.enabledYear'), //不在受年份控制
listBalance.push(curEditBeginBalance)
// 期初余额的计算工作放入后端,所以以下三行注释掉 0105 haozhao
// let curAccountGrade = curBeginBalance.accountGrade
// listBalance = caculateTopGrade(curEditField, curEditBeginBalance, curAccountGrade, curYearTotalAmountField)
// let saveUseList = generateSaveUseList(listBalance)
// 保存期初余额
this.createAndUpdateBatch(listBalance, curEditField, isPositiveNum, curYearTotalAmountField, beginAmountField) //初始
//数量CheckBox变更时列的控制
} else if (path == 'root.children.header.children.right.children.isCalcQuantity') {
this.metaAction.sf('data.filter.isCalcQuantity', !this.metaAction.gf('data.filter.isCalcQuantity'))
// this.injections.reduce('changeShowQuanMulti', this.metaAction.gf('data.filter.isCalcQuantity'), 1);
// this.computeFun(1)
this.loadBalanceData(accountType, selectedYear)
//外币CheckBox变更时列的控制
} else if (path == 'root.children.header.children.right.children.isCalcMulti') {
this.metaAction.sf('data.filter.isCalcMulti', !this.metaAction.gf('data.filter.isCalcMulti'))
this.loadBalanceData(accountType, selectedYear)
// this.computeFun(2)
//年度变化时,重新加载期初余额
} else if (path == 'root.children.header.children.left.children.year.children.year') {
let yearList = this.metaAction.gf('data.other.yearList'),
hit = yearList.find(o => o.get('id') == newValue)
if (hit) {
this.metaAction.sf('data.other.year', fromJS(hit))
selectedYear = hit.get('id')
}
this.loadBalanceData(accountType, selectedYear)
}
}
getErrorMessage = (curEditField) => {
let errorMessage
if (curEditField === 'beginQuantity') {
// errorMessage = `期初余额-数量`
errorMessage = `期初余额数量`
} else if (curEditField === 'beginOrigAmount') {
// errorMessage = `期初余额-外币`
errorMessage = `期初余额外币`
} else if (curEditField === 'beginAmount') {
// errorMessage = `期初余额-金额`
errorMessage = `期初余额金额`
} else if (curEditField === 'quantityDr') {
// errorMessage = `本年借方累计-数量`
errorMessage = `本年借方累计数量`
} else if (curEditField === 'origAmountDr') {
// errorMessage = `本年借方累计-外币`
errorMessage = `本年借方累计外币`
} else if (curEditField === 'amountDr') {
// errorMessage = `本年借方累计-金额`
errorMessage = `本年借方累计金额`
} else if (curEditField === 'quantityCr') {
// errorMessage = `本年贷方累计-数量`
errorMessage = `本年贷方累计数量`
} else if (curEditField === 'origAmountCr') {
// errorMessage = `行本年贷方累计-外币`
errorMessage = `行本年贷方累计外币`
} else if (curEditField === 'amountCr') {
// errorMessage = `本年贷方累计-金额`
errorMessage = `本年贷方累计金额`
}
return errorMessage
}
//新增修改合并处理
createAndUpdateBatch = async (listBalance, curEditField, isPositiveNum, curYearTotalAmountField, beginAmountField) => {
// createAndUpdateBatch = async (listBalance, curEditField, isPositiveNum, curYearTotalAmountField) => {
// debugger
const data = await this.webapi.createAndUpdateBatch(listBalance)
let accountType = this.metaAction.gf('data.other.accountType')
const curIsCalcMulti = this.metaAction.gf('data.filter.isCalcMulti')
if (data) {
data.dataList.map(subItem => {
if (subItem.currencyId) {
subItem.accountCode = combineAuxItemContent(subItem, 'accountCode') + '_' + subItem.currencyCode
// subItem.accountCode = ''
} else {
subItem.accountCode = combineAuxItemContent(subItem, 'accountCode')
}
if (subItem[curEditField]) {
// if (curEditField == 'beginQuantity' ||
// curEditField == 'quantityDr' ||
// curEditField == 'quantityCr') {
// subItem[curEditField] = subItem[curEditField].toFixed(2)
// } else {
// subItem[curEditField] = subItem[curEditField].toFixed(2)
if(curEditField!='beginQuantity'&&curEditField!='quantityDr'&&curEditField!='quantityCr'&&curEditField!='yearBeginQuantity'){
subItem[curEditField] = subItem[curEditField] ? parseFloat(subItem[curEditField]).toFixed(2) : undefined
}else{
subItem[curEditField] = subItem[curEditField] ? parseFloat(subItem[curEditField]).toFixed(6) : undefined
}
if (curYearTotalAmountField) {
// subItem[curYearTotalAmountField] = subItem[curYearTotalAmountField].toFixed(2)
subItem[curYearTotalAmountField] = subItem[curYearTotalAmountField] ? parseFloat(subItem[curYearTotalAmountField]).toFixed(2) : undefined
}
if (beginAmountField && curIsCalcMulti) {
if (accountType == ACCOUNTTYPE_PROFITANDLOSS) {
switch (beginAmountField) {
case 'origAmountDr':
subItem['origAmountDr'] = parseFloat(subItem['origAmountDr']).toFixed(2)
subItem['amountDr'] = parseFloat(subItem['origAmountDr']).toFixed(2)
subItem['origAmountCr'] = parseFloat(subItem['origAmountDr']).toFixed(2)
subItem['amountCr'] = parseFloat(subItem['origAmountDr']).toFixed(2)
break;
case 'amountDr':
subItem['amountDr'] = parseFloat(subItem['amountDr']).toFixed(2)
subItem['origAmountDr'] = parseFloat(subItem['amountDr']).toFixed(2)
subItem['origAmountCr'] = parseFloat(subItem['amountDr']).toFixed(2)
subItem['amountCr'] = parseFloat(subItem['amountDr']).toFixed(2)
break;
case 'origAmountCr':
subItem['amountDr'] = parseFloat(subItem['origAmountCr']).toFixed(2)
subItem['origAmountDr'] = parseFloat(subItem['origAmountCr']).toFixed(2)
subItem['origAmountCr'] = parseFloat(subItem['origAmountCr']).toFixed(2)
subItem['amountCr'] = parseFloat(subItem['origAmountCr']).toFixed(2)
break;
case 'amountCr':
subItem['amountDr'] = parseFloat(subItem['amountCr']).toFixed(2)
subItem['origAmountDr'] = parseFloat(subItem['amountCr']).toFixed(2)
subItem['origAmountCr'] = parseFloat(subItem['amountCr']).toFixed(2)
subItem['amountCr'] = parseFloat(subItem['amountCr']).toFixed(2)
break;
// default: subItem[beginAmountField] = subItem[beginAmountField].toFixed(2)
default:
if (beginAmountField.toLowerCase().indexOf('quantity') > -1) {
subItem[beginAmountField] = subItem[beginAmountField] ? parseFloat(subItem[beginAmountField]).toFixed(6) : undefined
} else {
subItem[beginAmountField] = subItem[beginAmountField] ? parseFloat(subItem[beginAmountField]).toFixed(2) : undefined
}
}
} else {
if (beginAmountField.toLowerCase().indexOf('quantity') > -1) {
subItem[beginAmountField] = subItem[beginAmountField] ? parseFloat(subItem[beginAmountField]).toFixed(6) : undefined
} else {
subItem[beginAmountField] = subItem[beginAmountField] ? parseFloat(subItem[beginAmountField]).toFixed(2) : undefined
}
}
}
// }
}
// subItem['yearBeginQuantity'] = subItem['yearBeginQuantity'].toFixed(2)
subItem['yearBeginQuantity'] = subItem['yearBeginQuantity'] ? subItem['yearBeginQuantity'].toFixed(6) : undefined
subItem['yearBeginOrigAmount'] = subItem['yearBeginOrigAmount'] ? subItem['yearBeginOrigAmount'].toFixed(2) : undefined
// subItem['yearBeginAmount'] = subItem['yearBeginAmount'].toFixed(2)
subItem['yearBeginAmount'] = subItem['yearBeginAmount'] ? subItem['yearBeginAmount'].toFixed(2) : undefined
return subItem
})
this.injections.reduce('updateBeginBalanceRows', data.dataList, curEditField, data.PeriodBeginDto, curYearTotalAmountField, beginAmountField)
// this.injections.reduce('updateBeginBalanceRows', data.dataList, curEditField, data.PeriodBeginDto, curYearTotalAmountField)
if (isPositiveNum) {
this.metaAction.toast('success', '期初余额更新成功!财务费用下的利息收入是借方科目,[本年借方累计][本年贷方累计]列应该录入负数')
} else {
// this.controlTip()
this.metaAction.toast('success', '期初余额更新成功')
}
}
// this.reload();
}
controlTip = () => {
let getRandom = Math.floor(Math.random() * 10000)
this.getRandom = getRandom
setTimeout(() => {
if (this.getRandom == getRandom) {
this.metaAction.toast('success', '期初余额更新成功')
}
}, 1000)
}
getSelectedYear = () => {
let selectedYear
if (this.metaAction.gf('data.other.year')) {
selectedYear = this.metaAction.gf('data.other.year').get('id')
}
return selectedYear
}
// getBalanceItem = (balanceFromServer, curEditField, newValue, curYearTotalAmountField) => {
getBalanceItem = (balanceFromServer, curEditField, newValue, curYearTotalAmountField, beginAmountField) => {
if (!balanceFromServer) {
return {}
}
let retBalance = {
id: balanceFromServer.id, // 期初余额id
year: balanceFromServer.currentYear, // 年度
origAmountDr: clearThousandsPosition(balanceFromServer.origAmountDr), // 本年借方累计(外币)
origAmountCr: clearThousandsPosition(balanceFromServer.origAmountCr), // 本年贷方累计(外币)
amountDr: clearThousandsPosition(balanceFromServer.amountDr), // 本年借方累计(本币)
amountCr: clearThousandsPosition(balanceFromServer.amountCr), // 本年贷方累计(本币)
quantityDr: clearThousandsPosition(balanceFromServer.quantityDr), // 本年借方累计(数量)
quantityCr: clearThousandsPosition(balanceFromServer.quantityCr), // 本年贷方累计(数量)
beginOrigAmount: clearThousandsPosition(balanceFromServer.beginOrigAmount), // 期初余额(外币)
beginAmount: clearThousandsPosition(balanceFromServer.beginAmount), // 期初余额(本币)
beginQuantity: clearThousandsPosition(balanceFromServer.beginQuantity), // 期初余额(数量)
// isAuxAccCalc: balanceFromServer.isAuxAccCalc, // 是否辅助明细数据
// isAuxAccCalc:balanceFromServer.isDetailData, // 是否辅助明细数据
isDetailData: balanceFromServer.isDetailData, // 是否辅助明细数据
unitId: balanceFromServer.unitId, // 计量单位ID
currencyId: balanceFromServer.currencyId, // 币种ID
currencyCode: balanceFromServer.currencyCode, // 币种编码
accountId: balanceFromServer.accountId, // 科目ID
accountCode: balanceFromServer.accountCode, // 科目编码
direction: balanceFromServer.direction, // 方向编码
departmentId: balanceFromServer.departmentId, // 部门ID
personId: balanceFromServer.personId, // 人员ID
customerId: balanceFromServer.customerId, // 客户ID
supplierId: balanceFromServer.supplierId, // 供应商ID
inventoryId: balanceFromServer.inventoryId, // 存货ID
projectId: balanceFromServer.projectId, // 项目ID
bankAccountId: balanceFromServer.bankAccountId, // 账号ID
levyAndRetreatId: balanceFromServer.levyAndRetreatId, // 即征即退ID
inputTaxId: balanceFromServer.inputTaxId // 即征即退ID
}, accountType = this.metaAction.gf('data.other.accountType')
if (newValue != undefined) {
retBalance[curEditField] = newValue
}
if (curYearTotalAmountField && newValue != undefined) {
retBalance[curYearTotalAmountField] = newValue
}
if (beginAmountField && newValue != undefined) {
if (accountType == ACCOUNTTYPE_PROFITANDLOSS) {
switch (beginAmountField) {
case 'origAmountDr':
retBalance['origAmountDr'] = newValue
retBalance['amountDr'] = newValue
retBalance['origAmountCr'] = newValue
retBalance['amountCr'] = newValue
break;
case 'amountDr':
retBalance['amountDr'] = newValue
retBalance['origAmountDr'] = newValue
retBalance['origAmountCr'] = newValue
retBalance['amountCr'] = newValue
break;
case 'origAmountCr':
retBalance['amountDr'] = newValue
retBalance['origAmountDr'] = newValue
retBalance['origAmountCr'] = newValue
retBalance['amountCr'] = newValue
break;
case 'amountCr':
retBalance['amountDr'] = newValue
retBalance['origAmountDr'] = newValue
retBalance['origAmountCr'] = newValue
retBalance['amountCr'] = newValue
break;
default: retBalance[beginAmountField] = newValue
}
} else {
retBalance[beginAmountField] = newValue
}
}
return retBalance
}
operateCol = (record, rowIndex) => {
let obj,
enabledYear = this.metaAction.gf('data.other.enabledYear'),
selectedYear = this.metaAction.gf('data.other.year').get('id')
// if (record && (record.isCalcMulti || record.isCalc) && !record.isDetailData && record.isEndNode && enabledYear == selectedYear) {
if (record && (record.isCalcMulti || record.isCalc) && !record.isDetailData && record.isEndNode) {
obj = {
children: (
<span>
<Icon type="xinzengkemu" fontFamily='edficon' className='table_fixed_width-addIcon' title='新增' onClick={() => this.addAuxItem(record, rowIndex)} />
</span>
)
}
// } else if (record && record.isDetailData && enabledYear == selectedYear) {
} else if (record && record.isDetailData) {
obj = {
children: (
<span>
<Icon type="shanchu" fontFamily='edficon' className='table_fixed_width-deleteIcon' title='删除' onClick={() => this.deleteAuxItem(record, rowIndex)} />
</span>
)
}
}
return obj
}
deleteItem = async (selectObj, selectIndex) => {
// const year = selectObj.year
let year = this.metaAction.context.get("currentOrg").enabledYear
year = Number(year)
const id = selectObj.id
const result = await this.webapi.deleteAuxItem({ id, year })
if (result) {
this.injections.reduce('deleteAuxItemRows', result.dataList, selectIndex, result.PeriodBeginDto)
this.metaAction.toast('success', '期初余额删除成功')
this.computeFun()
}
}
//删除辅助明细确认弹框
deleteAuxItem = async (record, rowIndex) => {
const _this = this
const ret = await this.metaAction.modal('confirm', {
title: '删除',
content: '你确定要删除吗?',
onOk() {
_this.deleteItem(record, rowIndex)
},
onCancel() { }
})
}
// 新增辅助明细
addBatch = async (listBalance, rowIndex, isSelectCurrency, accountId) => {
// debugger
if (this.isHaveResult) return
listBalance.isReturnValue = true
this.isHaveResult = true
const data = await this.webapi.createAndUpdateBatch(listBalance)
if (data.result == false) {
this.isHaveResult = false
this.metaAction.toast('warning', data.error.message)
return false
} else {
this.isHaveResult = false
for (let auxItem of data.dataList) {
// let filteredItem = data.dataList.filter(subItem => {
// if (subItem.isDetailData) {
// return combineAuxItemContent(subItem, 'accountCode') + '_' + subItem.currencyCode == auxItem.accountCode + '_' + auxItem.currencyCode
// } else {
// return subItem.accountCode == auxItem.accountCode
// }
// })
// if (filteredItem && filteredItem.length > 0) {
// console.log(filteredItem)
// // auxItem.id = filteredItem[0].id
// auxItem.yearBeginQuantity = filteredItem[0].yearBeginQuantity ?
// addThousandsPosition(parseFloat(filteredItem[0].yearBeginQuantity).toFixed(2)) == 0 ? undefined :
// addThousandsPosition(parseFloat(filteredItem[0].yearBeginQuantity).toFixed(2)) : undefined
// auxItem.yearBeginOrigAmount = filteredItem[0].yearBeginOrigAmount ?
// addThousandsPosition(parseFloat(filteredItem[0].yearBeginOrigAmount).toFixed(2)) == 0 ? undefined :
// addThousandsPosition(parseFloat(filteredItem[0].yearBeginOrigAmount).toFixed(2)) : undefined
// console.log(filteredItem[0].yearBeginAmount, 'filteredItem[0].yearBeginAmount4444444444')
// if (filteredItem[0].yearBeginAmount && filteredItem[0].yearBeginAmount.toString().indexOf(',') > -1) {
// auxItem.yearBeginAmount = filteredItem[0].yearBeginAmount ? filteredItem[0].yearBeginAmount : undefined
// } else {
// auxItem.yearBeginAmount = filteredItem[0].yearBeginAmount ?
// addThousandsPosition(parseFloat(filteredItem[0].yearBeginAmount).toFixed(2)) == 0 ? undefined :
// addThousandsPosition(parseFloat(filteredItem[0].yearBeginAmount).toFixed(2)) : undefined
// }
// }
const attributArr = ['yearBeginQuantity', 'yearBeginAmount', 'yearBeginOrigAmount', 'amountDr', 'amountCr', 'origAmountDr', 'origAmountCr', 'quantityDr', 'quantityCr', 'beginAmount', 'beginOrigAmount', 'beginQuantity']
attributArr.forEach((item) => {
if(item == 'yearBeginQuantity'||item=='quantityDr'||item=='quantityCr'||item=='beginQuantity'){
// auxItem[item] = auxItem[item] ? utils.number.format(auxItem[item],6) == 0 ? '' : utils.number.format(auxItem[item],6) : ''
auxItem[item] = auxItem[item]&&utils.number.format(auxItem[item],6)
// console.log(auxItem[item])
}else{
auxItem[item] = addThousandsPosition(auxItem[item],true) ? addThousandsPosition(auxItem[item],true) == 0 ? '' : addThousandsPosition(auxItem[item],true) : ''
}
})
// console.log(auxItem)
}
this.injections.reduce('addAuxCalcItemRows', data.dataList, rowIndex, isSelectCurrency, accountId, data.PeriodBeginDto)
this.metaAction.toast('success', '期初余额新增成功')
this.computeFun()
return true
}
}
handlerResult = async (result, accountingSubject, rowIndex) => {
// console.log(result.value.toJS())
if (result) {
// let selectedYear = this.getSelectedYear(),
let selectedYear = this.metaAction.gf('data.other.enabledYear'), //不在受年份控制
list = this.metaAction.gf('data.list'),
auxItems = [],
accountId = accountingSubject.accountId,
accountCode = accountingSubject.accountCode,
direction = accountingSubject.direction,
cashTypeId = accountingSubject.cashTypeId
const resultList = result.value.toJS()
for (let i = 0; i < resultList.length; i++) {
let item = resultList[i],
auxItem = this.addFileToBalance(item, selectedYear, accountId, accountCode, direction, cashTypeId, accountingSubject)
auxItems.push(auxItem)
}
// 辅助明细不允许重复添加
// let arrAuxItems = list.filter(subItem => {
// return subItem.get('accountId') == accountId &&
// subItem.get('isCalc') == true
// })
let arrAuxItems = list.filter(subItem => {
return subItem.get('accountId') == accountId &&
subItem.get('isDetailData') == true
})
for (let i = 0; i < auxItems.length; i++) {
let filterItem = arrAuxItems.filter(subItem => {
if (auxItems[i].currencyId) {
return subItem.get('accountCode') + '_' + subItem.get('currencyCode') == auxItems[i].accountCode + '_' + auxItems[i].currencyCode
} else {
return subItem.get('accountCode') == auxItems[i].accountCode
}
})
if (filterItem.size > 0) {
// setMessage({ type: 'warning', mode: 'message', content: '辅助项不能重复添加!' })
this.metaAction.toast('warning', '辅助项不能重复添加')
return
}
}
let addAuxItems = []
for (let i = 0; i < auxItems.length; i++) {
if (auxItems[i].addFlg != 0) {
addAuxItems.push(auxItems[i])
}
}
if (addAuxItems.length == 0) {
clearMessage()
return
}
// 若当前期初余额还未入库,则逐级次找出上级科目期初余额数据准备入库
// let id = getterByField(`list.${rowIndex}.id`), //期初余额id
// accountGrade = getterByField(`list.${rowIndex}.accountGrade`)
// 判断是否有选择了币种
let isSelectCurrency = false
for (let i = 0; i < result.value.length; i++) {
let auxItem = result.value[i]
if (!!auxItem.currencyId && (!!auxItem.currencyId.code || auxItem.currencyId.id || auxItem.currencyId.name)) {
isSelectCurrency = true
break
}
}
const res = this.addBatch(addAuxItems, rowIndex, isSelectCurrency, accountId)
return res
//this.reload()
}
}
//增加辅助项弹框
addAuxItem = async (accountingSubject, rowIndex) => {
accountingSubject.accountType = this.metaAction.gf('data.other.accountType')
// const isNotJanuary = this.metaAction.gf('data.other.isNotJanuary')
const enabledMonth = this.metaAction.gf('data.other.enabledMonth')
const isNotJanuary = enabledMonth != 1
const calcDict = this.metaAction.gf('data.other.calcDict')
let width,
valueTrueNum = 0,
colums, title = '外币期初余额'
for (let key in accountingSubject) {
if (accountingSubject.hasOwnProperty(key) && typeof (accountingSubject[key]) == 'boolean' && accountingSubject[key] == tru