ttk-app-core
Version:
enterprise develop framework
630 lines (599 loc) • 25.3 kB
JavaScript
import React from 'react'
import { action as MetaAction, AppLoader } from 'edf-meta-engine'
import { fromJS, List, Map } from 'immutable'
import config from './config'
import moment from 'moment'
import utils from 'edf-utils'
import extend from './extend'
import { consts } from 'edf-consts'
import renderColumns from './utils/renderDataGridColumns';
import { Tree } from 'edf-component'
class action {
constructor(option) {
this.metaAction = option.metaAction
this.extendAction = option.extendAction
this.config = config.current
this.webapi = this.config.webapi
}
onInit = ({ component, injections }) => {
this.extendAction.gridAction.onInit({ component, injections })
this.component = component
this.injections = injections
injections.reduce('init')
let addEventListener = this.component.props.addEventListener
if (addEventListener) {
addEventListener('onTabFocus', :: this.onTabFocus)
}
const params = this.component.props && this.component.props.appExtendParams
this.load(params && params.isUploaded)
}
load = async (params) => {
this.changeSubjects(params)
}
changeSubjects = async (params) => {
this.injections.reduce('loading', true)
//参数取反 ,只有第一步上传文件onlyQuery:false 匹配和映射 否则都是true 直接查询
LoadingMask.show()
let response = await this.webapi.financeinit.matchInit({ "onlyQuery": params ? false : true })
this.injections.reduce('load', response)
this.injections.reduce('loading', false)
LoadingMask.hide()
}
/**
* 页签切换
*/
onTabFocus = async () => {
this.changeSubjects(false)
}
/**
* 判断操作按钮的状态
*/
disabledState = (subject) => {
let state = false,
{ code, grade, cashTypeId, id } = subject
if (!code) {
return state
}
if (!id) {
return true
}
if ((cashTypeId == 5000020003 && grade != 1)
|| (code.indexOf('1012') != -1 && grade != 1 && grade != 2)
|| (code == '22210401')
|| (code.indexOf('1001') != -1 && grade == 1)
|| (cashTypeId == 5000020033 && grade != 1)
|| ((cashTypeId == 5000020034 || cashTypeId == 5000020035 || cashTypeId == 5000020036 || cashTypeId == 5000020037) && grade != 2)
|| (code == '22210109')
|| (cashTypeId == 5000020005) || grade == 5) {
state = true
}
return state
}
/**
* 新增
*/
addAccount = (data) => async () => {
let { id, code, grade, cashTypeId } = data
if (grade == 5) {
this.metaAction.toast('warning', '已经是第五级科目,无法再增加下级科目。')
return
}
if ((cashTypeId == 5000020003 && grade != 1)
|| (code.indexOf('1012') != -1 && grade != 1 && grade != 2)
|| (code == '22210401')
|| (code.indexOf('1001') != -1 && grade == 1)
|| (cashTypeId == 5000020033 && grade != 1)
|| ((cashTypeId == 5000020034 || cashTypeId == 5000020035 || cashTypeId == 5000020036 || cashTypeId == 5000020037) && grade != 2)
|| (code == '22210109')
|| (cashTypeId == 5000020005)) {
return
}
const oldData = this.metaAction.gf('data').toJS()
let { list, other } = oldData
const ret = await this.metaAction.modal('show', {
title: '科目',
width: 400,
okText: '保存',
style: { top: 40 },
bodyStyle: { padding: 24, fontSize: 12 },
children: this.metaAction.loadApp('app-proof-of-charge-subjects-add', {
store: this.component.props.store,
active: 'add',
newCode: generateNewSubCode(id, code, list),
data: data,
})
})
if (ret) {
this.changeSubjects(false)
}
}
/**
* 批量新增
*/
batchAddSubject = (data) => async () => {
let { id, code, grade, cashTypeId } = data
if (grade == 5) {
this.metaAction.toast('warning', '已经是第五级科目,无法再增加下级科目')
return
}
if ((cashTypeId == consts.CASHTYPE_003 && grade != 1)
|| (code.indexOf('1012') != -1 && grade != 1 && grade != 2)
|| (code == '22210401')
|| (code.indexOf('1001') != -1 && grade == 1)
|| (cashTypeId == consts.CASHTYPE_033 && grade != 1)
|| ((cashTypeId == consts.CASHTYPE_034 || cashTypeId == consts.CASHTYPE_035 || cashTypeId == consts.CASHTYPE_036 || cashTypeId == consts.CASHTYPE_037) && grade != 2)
|| (code == '22210109')
|| (cashTypeId == consts.CASHTYPE_005)) {
return
}
const ret = await this.metaAction.modal('show', {
title: '可粘贴科目名称,多个科目请换行',
width: 400,
okText: '确定',
style: { top: 140 },
bodyStyle: { padding: 24, fontSize: 12 },
children: this.metaAction.loadApp('app-account-subjects-batch-add', {
store: this.component.props.store,
parentId: id
})
})
if (ret) {
let option = {
parentId: id,
accountNameList: ret
}
LoadingMask.show()
const response = await this.webapi.financeinit.batchAdd(option)
LoadingMask.hide()
if (response) {
this.metaAction.toast('success', this.message(response.message), response.message.indexOf('<br>') != -1 ? 3 : 1)
this.changeSubjects(false)
}
}
}
/**
* 编辑
*/
editAccount = (data) => async () => {
const list = this.metaAction.gf('data.list').toJS()
const ret = await this.metaAction.modal('show', {
title: '科目',
width: 400,
style: { top: 40 },
okText: '保存',
bodyStyle: { padding: 24, fontSize: 12 },
children: this.metaAction.loadApp('app-proof-of-charge-subjects-add', {
store: this.component.props.store,
active: 'edit',
data: data,
parentSubject: getParentSubject(list, data.parentId),
})
})
if (ret) {
this.changeSubjects(false)
}
}
/**
* 删除
*/
deleteAccount = (data) => async () => {
if (!(!data.isSystem && data.isEndNode) || !data.isEnable)
return
const ret = await this.metaAction.modal('confirm', {
content: '确认删除?'
})
if (ret) {
let { id, parentId, ts, code } = data, option = {}
option.id = id
option.ts = ts
const response = await this.webapi.financeinit.delete(option)
let messageText, isDelCurSubject
//判断后端是否删除成功
if (response == '') {
isDelCurSubject = true
this.metaAction.toast('success', '删除成功')
this.changeSubjects(false)
} else {
isDelCurSubject = false //科目已经被使用,不能删除,只能更改状态
this.injections.reduce('deleteAccount', id, parentId, isDelCurSubject, rowIndex)
}
}
}
/**
* 内容提醒
*/
message = (message) => {
message = message.split('<br>')
return (
<div>
{
message.map((o, i) => {
return (
<div>{o}</div>
)
})
}
</div>
)
}
/**
* 渲染表格列
*/
tableColumns = (list) => {
let targetAccountWidth, screenWidth = document.getElementsByClassName("fixedDataTableLayout_rowsContainer")
if (screenWidth && screenWidth.length > 0) {
targetAccountWidth = screenWidth[0].style.width
}
const params = [this.renderMsgColumns, this.disabledState, this.addAccount, this.batchAddSubject, this.editAccount, this.deleteAccount]
return renderColumns(list, targetAccountWidth, ...params)
}
/**
* 渲染错误提示cell单元格内容
*/
renderMsgColumns = (columnName, index) => {
let list = this.metaAction.gf('data.list')
if (list) {
let currentRow = list.get(index) ? list.get(index).toJS() : list.get(index)
const cellElement = this.getAhrefAutoMatch(currentRow, index)
return (
<div className={currentRow && (currentRow.autoMatch < 0 || currentRow.autoMatch == 3) && currentRow.sourceIsAuxAccCalc ? "ttk-gl-app-financeinit-accountrelation-content-msgcell lineheight" : "ttk-gl-app-financeinit-accountrelation-content-msgcell"}>
{cellElement}
</div>
)
}
}
/**
* 根据返回的状态,重新加载界面的展现内容
*/
getAhrefAutoMatch = (currentRow, index) => {
/**
* "autoMatch": 1,
* 0:什么都不显示
* 1:已匹配科目
* 2:系统自动创建
* 3:系统自动创建(重新匹配)
* -3:系统自动创建(重新匹配/忽略)
* 4:重新匹配
* -4:重新匹配/忽略
* 5:已匹配科目(重新匹配)
"sourceIsAuxAccCalc": false, --原科目是否启用辅助项
"needMatchAuxAccCalc":false, --是否需要匹配辅助项
*/
let res
if (!currentRow) {
return res
}
let autoMatch = currentRow.autoMatch,
sourceIsAuxAccCalc = currentRow.sourceIsAuxAccCalc,
needMatchAuxAccCalc = currentRow.needMatchAuxAccCalc
const auxspan = <a href="javascript:;"
onClick={() => this.auxSetting(currentRow, index)}
style={needMatchAuxAccCalc ? { color: '#E74040' } : {}}
title='辅助核算设置'>
辅助核算设置
</a>
switch (autoMatch) {
case 0:
res = <span></span>
break;
case 1:
res = <span>
已匹配科目
{sourceIsAuxAccCalc ? '(' : ''}
{sourceIsAuxAccCalc ? auxspan : ''}
{sourceIsAuxAccCalc ? ')' : ''}
</span>
break;
case 2:
res = <span>
系统自动创建
{sourceIsAuxAccCalc ? '(' : ''}
{sourceIsAuxAccCalc ? auxspan : ''}
{sourceIsAuxAccCalc ? ')' : ''}
</span>
break;
case 3:
res = <span>
系统自动创建(
<a href="javascript:;"
style={{ color: '#E74040' }}
onClick={() => this.reReplace(currentRow)}
title='重新匹配'>
重新匹配
</a>
{sourceIsAuxAccCalc ? <span>/</span> : ''}
{sourceIsAuxAccCalc ? auxspan : ''}
)
</span>
break;
case -3:
res = <span>
系统自动创建(
<a href="javascript:;"
style={{ color: '#E74040' }}
onClick={() => this.reReplace(currentRow)}
title='重新匹配'>
重新匹配
</a>
<span>/</span>
<a href="javascript:;"
onClick={() => this.handlerCurRowIgnore(currentRow, index)}
style={{ color: '#E74040' }}
title='忽略'>
忽略
</a>
{sourceIsAuxAccCalc ? <span>/</span> : ''}
{sourceIsAuxAccCalc ? auxspan : ''}
)</span>
break;
case 4:
res = <span>
<a href="javascript:;"
onClick={() => this.reReplace(currentRow)}
title='重新匹配'>
重新匹配
</a>
{sourceIsAuxAccCalc ? <span>/</span> : ''}
{sourceIsAuxAccCalc ? auxspan : ''}
</span>
break;
case -4:
res = <span>
<a href="javascript:;"
onClick={() => this.reReplace(currentRow)}
style={{ color: '#E74040' }}
title='重新匹配'>
重新匹配
</a>
<span>/</span>
{sourceIsAuxAccCalc ? <span>/</span> : ''}
{sourceIsAuxAccCalc ? auxspan : ''}
</span>
break;
case 5:
res =
<span>
已匹配科目(
<a href="javascript:;"
// style={{ color: '#E74040' }}
onClick={() => this.reReplace(currentRow)}
title='重新匹配'>
重新匹配
</a>
{sourceIsAuxAccCalc ? <span>/</span> : ''}
{sourceIsAuxAccCalc ? auxspan : ''}
)</span>
break;
default:
res = <span></span>
break;
}
return res
}
/**
* 财务期初-上一步
*/
preStep = async () => {
if (this.component.props) {
const appParams = this.component.props.appExtendParams
this.component.props.setPortalContent('上传数据', 'ttk-gl-app-financeinit-uploaddata', appParams)
}
}
/**
* 财务期初-下一步
*/
nextStep = async () => {
if (this.component.props) {
LoadingMask.show()
const response = await this.webapi.financeinit.importData()
LoadingMask.hide()
if (response) {
const appParams = this.component.props.appExtendParams,
preStep = 'ttk-gl-app-financeinit-accountrelation'
//ttk-gl-app-finance-periodbegin app-account-beginbalance
this.component.props.setPortalContent('确认数据', 'ttk-gl-app-finance-periodbegin', { preStep, ...appParams })
}
}
}
/**
* 忽略
*/
handlerCurRowIgnore = async (currentRow, index) => {
LoadingMask.show()
const handMatchIgnore = await this.webapi.financeinit.handMatchIgnore({ "id": currentRow.id })
LoadingMask.hide()
let list = this.metaAction.gf('data.list'), sfsData = {}
if (handMatchIgnore && handMatchIgnore.matchList) {
const matchIgnore = handMatchIgnore.matchList[0]
list = list.update(index, item => item.set('autoMatch', matchIgnore.autoMatch))
list = list.update(index, item => item.set('sourceIsAuxAccCalc', matchIgnore.sourceIsAuxAccCalc))
list = list.update(index, item => item.set('needMatchAuxAccCalc', matchIgnore.needMatchAuxAccCalc))
list = list.update(index, item => item.set('accountId', matchIgnore.accountId))
list = list.update(index, item => item.set('auxOrder', matchIgnore.auxOrder))
if (matchIgnore.accountDto) {
list = list.update(index, item => item.set('accountDto', matchIgnore.accountDto))
}
sfsData['data.list'] = list
this.metaAction.sfs(sfsData)
}
}
/**
* 重新匹配
*/
reReplace = async (currentRow) => {
let list = this.metaAction.gf('data.list'), sfsData = {}
const res = await this.metaAction.modal('show', {
title: '科目匹配',
width: 580,
cancelText: '取消',
okText: '保存',
children: this.metaAction.loadApp('ttk-gl-app-account-rereplace', {
store: this.component.props.store,
id: currentRow && currentRow.id
}),
})
if (res && res.matchList) {
const matchList = res.matchList
for (let index = 0; index < matchList.length; index++) {
const reElement = matchList[index]
for (let _rowIndex = 0; _rowIndex < list.size; _rowIndex++) {
const element = list.get(_rowIndex).toJS()
if (element.id == reElement.id) {
list = list.update(_rowIndex, item => item.set('autoMatch', reElement.autoMatch))
list = list.update(_rowIndex, item => item.set('sourceIsAuxAccCalc', reElement.sourceIsAuxAccCalc))
list = list.update(_rowIndex, item => item.set('needMatchAuxAccCalc', reElement.needMatchAuxAccCalc))
list = list.update(_rowIndex, item => item.set('accountId', reElement.accountId))
list = list.update(_rowIndex, item => item.set('accountDto', reElement.accountDto))
}
}
}
sfsData['data.list'] = list
this.metaAction.sfs(sfsData)
/*
原表内有辅助核算
对应科目未启用辅助核算,在匹配科目后需要弹框提示,xxx科目是否启用辅助核算?
是,则弹出科目辅助核算设置页面,让其勾选核算,多核算项目的,
提示,将按照启用核算项目的先后顺序对应科目核算项目
*/
// let confirmTips = await this.metaAction.modal('confirm', {
// content: this.getDisplayConfirmMSg(`${currentRow.sourceCode}${currentRow.sourceName}`, `${currentRow.accountDto.code}${currentRow.accountDto.name}`),
// cancelText: '否',
// okText: '是'
// })
// if (confirmTips) {
// }
}
}
/**
* 辅助核算项目设置
*/
auxSetting = async (currentRow, index) => {
const ret = await this.metaAction.modal('show', {
title: '辅助核算设置',
width: 580,
//okText: '保存',
wrapClassName: 'auxiliary-setting',
children: this.metaAction.loadApp('ttk-gl-app-auxiliary-setting', {
store: this.component.props.store,
initData: { rowIndex: index, ...currentRow },
callbackAction: this.saveAux
}),
})
}
/**
* 保存辅助核算
*/
saveAux = async (params) => {
if (params) {
let list = this.metaAction.gf('data.list'),
sfsData = {}
LoadingMask.show()
let handMatchAux = await this.webapi.financeinit.handMatchAux({ "id": params.id, "auxNameList": params.auxNameList })
LoadingMask.hide()
if (handMatchAux) {
const auxMatch = handMatchAux.matchList[0]
list = list.update(params.rowIndex, item => item.set('autoMatch', auxMatch.autoMatch))
list = list.update(params.rowIndex, item => item.set('sourceIsAuxAccCalc', auxMatch.sourceIsAuxAccCalc))
list = list.update(params.rowIndex, item => item.set('needMatchAuxAccCalc', auxMatch.needMatchAuxAccCalc))
list = list.update(params.rowIndex, item => item.set('auxOrder', auxMatch.auxOrder))
list = list.update(params.rowIndex, item => item.set('accountDto', auxMatch.accountDto))
sfsData['data.list'] = list
this.metaAction.sfs(sfsData)
}
}
}
/**
* 提示内容封装
*/
getDisplayConfirmMSg = (sourceAccount, targetAccount) => {
return (
<div style={{ display: 'inline-table' }}>
<div style={{ 'fontSize': '12px', color: '#484848' }}>{`原表${sourceAccount}科目、${targetAccount}科目有辅助核算,是否启用辅助核算项目?`}</div>
</div>)
}
/**
* cell单元格控件选择处理事件
*/
handleSelectChange = (value, columnName, index, accountList) => {
// let list = this.metaAction.gf('data.list')
// accountType = this.metaAction.gf('data.other.accountingSubject').toJS().accountTypeId
if (!accountList) return
const selectAccount = accountList.filter((item) => item.toJS().id == value)
const obj = selectAccount ? selectAccount.toJS()[0] : { code, unitName, currencyName, AuxAccCalcInfo }
accountList = accountList.update(index, item => item.set(columnName, fromJS(obj.id)))
accountList = accountList.update(index, item => item.set('code', fromJS(obj.code)))
accountList = accountList.update(index, item => item.set('id', fromJS(obj.id)))
accountList = accountList.update(index, item => item.set('codeAndName', fromJS(obj.codeAndName)))
accountList = accountList.update(index, item => item.set('unitName', fromJS(obj.unitName)))
accountList = accountList.update(index, item => item.set('currencyName', fromJS(obj.currencyName)))
accountList = accountList.update(index, item => item.set('AuxAccCalcInfo', fromJS(obj.AuxAccCalcInfo)))
//todo
//this.preSave()
this.metaAction.sf('data.list', accountList)
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
extendAction = extend.actionCreator({ ...option, metaAction }),
o = new action({ ...option, metaAction, extendAction })
const ret = { ...metaAction, ...extendAction.gridAction, ...o }
metaAction.config({ metaHandlers: ret })
return ret
}
//获取父级科目信息
function getParentSubject(subjectList, parentSubjectId) {
if (!parentSubjectId) {
return { id: null, code: '无父级科目', name: '', codeAndName: null, accountTypeId: null }
}
let parentSubject = subjectList.filter(subItem => {
return parseInt(subItem.id) == parseInt(parentSubjectId)
})
let ret
if (parentSubject && parentSubject.length > 0)
ret = {
id: parentSubject[0].id,
code: parentSubject[0].code,
name: parentSubject[0].name,
codeAndName: parentSubject[0].codeAndName,
accountTypeId: parentSubject[0].accountTypeId
}
else
ret = { id: null, code: '无父级科目', name: null, codeAndName: null, accountTypeId: null }
return ret
}
//生成新的科目编码
function generateNewSubCode(parentId, parentCode, subjectList) {
let newCode,
newSubjectList = subjectList.filter(subItem => {
return parseInt(subItem.parentId) == parseInt(parentId)
})
if (newSubjectList.length == 0) {
newCode = '01'
} else {
let endGradeList = []
for (var i = 0; i < newSubjectList.length; i++) {
let code = newSubjectList[i].code
endGradeList.push(code.substring(code.length - 2))
}
endGradeList = endGradeList.sort(sortNumber)
let maxCode = endGradeList[endGradeList.length - 1]
if (maxCode == '99' && endGradeList.length < 98) {
maxCode = endGradeList[endGradeList.length - 2]
if (!isNaN(maxCode)) {
newCode = '00' + (parseInt(maxCode) + 1).toString()
newCode = newCode.substring(newCode.length - 2)
} else {
newCode = '00'
}
} else if (maxCode != '99' && !isNaN(maxCode)) {
newCode = '00' + (parseInt(maxCode) + 1).toString()
newCode = newCode.substring(newCode.length - 2)
} else {
newCode = '00'
}
}
return newCode
}
function sortNumber(a, b) {
return a - b
}