UNPKG

ttk-app-core

Version:
284 lines (251 loc) 10.1 kB
import React from 'react' import { action as MetaAction, AppLoader } from 'edf-meta-engine' import { fromJS } from 'immutable' import config from './config' import moment from 'moment' import utils from 'edf-utils' import extend from './extend' 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 } 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) } this.load() } load = async () => { // let currentOrg = this.metaAction.context.get("currentOrg"), // accountingStandards = currentOrg.accountingStandards == consts.ACCOUNTINGSTANDARDS_2013 // this.metaAction.sf('data.other.accountingStandards', accountingStandards) this.changeSubjects() } //当前app的 "tab被点击" (从其他app切换到当前app) onTabFocus = async() => { let currentOrg = this.metaAction.context.get("currentOrg"), accountingStandards = currentOrg.accountingStandards == consts.ACCOUNTINGSTANDARDS_2013 let data = this.metaAction.gf('data').toJS() if(accountingStandards != data.other.accountingStandards && data.filter.targetList == '5000010003'){ this.metaAction.sf('data.other.accountingStandards', accountingStandards) this.tabChange('all') }else{ this.metaAction.sf('data.other.accountingStandards', accountingStandards) let targetList = this.metaAction.gf('data.filter.targetList') this.changeSubjects(targetList) } } //修改编码规则 setSubjectCode = async() =>{ const ret = await this.metaAction.modal('show', { title: '编码设置', width: 650, bodyStyle:{padding: 6, fontSize: 12}, children: this.metaAction.loadApp('ttk-table-app-tab-list-code', { store: this.component.props.store }) }) if(ret){ console.log(ret) } } disabledState = (subject) => { let state = false, {code, grade, cashTypeId} = subject 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 } addSubject = (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() //本地刷新 // this.injections.reduce('addSubject', ret, data.id) } } //编辑 editSubject = (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() //本地刷新 // this.injections.reduce('updateSubject', ret) } } deleteSubject = (data) => async () => { if(!(!data.isSystem && data.isEndNode) || !data.isEnable) return const ret = await this.metaAction.modal('confirm', { content: '确认删除?' }) if(ret){ // const newData = await this.webapi.find(data) let {id, parentId, ts, code} = data, option = {} option.id = id option.ts = ts const response = await this.webapi.delete(data) let messageText,isDelCurSubject //判断后端是否删除成功 if(response == ''){ isDelCurSubject = true this.metaAction.toast('success', '删除成功') this.changeSubjects() }else{ // isDelCurSubject = false //已经被使用,不能删除,只能更改状态 // this.injections.reduce('deleteSubject', id, parentId, isDelCurSubject, rowIndex) } } } changeSubjects= async (activeKey) => { const newData = this.metaAction.gf('data').toJS() let option = {}, key = activeKey || newData.filter.targetList if(key !== 'all'){ option.accountTypeId = key } if(activeKey && !newData.other.loading){ this.metaAction.sf('data.other.loading', true) } const response = await this.webapi.query(option) newData.list = response.glAccounts newData.other.calcDict = {...response.calcDict} newData.other.loading = false this.injections.reduce('load', newData) } setScrollTop = (name,value) => { // this.metaAction.sm(value) } tabChange = async (key) => { this.metaAction.sf('data.filter.targetList', key) this.metaAction.sf('data.other.loading', true) this.changeSubjects(key) } numberFormat = utils.number.format } 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 arr = subjectList 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 }