UNPKG

ttk-app-core

Version:
571 lines (499 loc) 18.2 kB
import React from 'react' import { action as MetaAction, AppLoader } from 'edf-meta-engine' import { Menu, Checkbox, DataGrid, Icon } from 'edf-component' import { List, fromJS } from 'immutable' import moment from 'moment' import extend from './extend' import config from './config' import renderColumns from './utils/renderColumns' import utils from 'edf-utils' 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 let addEventListener = this.component.props.addEventListener if (addEventListener) { addEventListener('onTabFocus', :: this.onTabFocus) // addEventListener('onTabClose', :: this.onTabClose) } injections.reduce('init') this.load() } load = async () => { this.metaAction.sf('data.other.loading', true) const date = await this.webapi.asset.date() this.metaAction.sf('data.other.loading', false) let contextDate = date.systemDate, currentOrg = this.metaAction.context.get("currentOrg") if(currentOrg.periodDate && moment(currentOrg.periodDate)<=moment(date.systemDate)){ contextDate = currentOrg.periodDate } let filter = this.metaAction.gf('data.filter').toJS() filter.period = utils.moment.stringToMoment(contextDate).endOf('month').format('YYYY-MM') filter.init = true if(this.component.props.noDate){ filter.period = utils.moment.stringToMoment(contextDate).endOf('month').format('YYYY-MM') } if(this.component.props.initSearchValue) { filter.period = this.component.props.initSearchValue.date } this.metaAction.sf('data.other.loading', true) let res = await this.webapi.asset.depreciationList(filter) this.metaAction.sf('data.other.loading', false) if(res) { if(res.isTasking){ this.metaAction.toast('warning', '凭证正在生成中,请稍后刷新') } res.date = filter.period this.injections.reduce('load', res) } } getListRowsCount = () => { return this.metaAction.gf('data.list').size } refresh = async (newFilter) => { _hmt && _hmt.push(['_trackEvent', '资产', '折旧摊销', '刷新']) let filter = this.metaAction.gf('data.filter').toJS() if(newFilter && newFilter.page) filter = newFilter if(newFilter && newFilter.date) filter.period = newFilter.date if(newFilter && newFilter.userOrderField){ filter.userOrderField = newFilter.userOrderField filter.order = newFilter.order } this.metaAction.sf('data.other.loading', true) let res = await this.webapi.asset.depreciationList(filter) this.metaAction.sf('data.other.loading', false) if(res) { if(res.isTasking){ this.metaAction.toast('warning', '凭证正在生成中,请稍后刷新') } this.metaAction.sf(`data.filter`, fromJS(filter)) this.injections.reduce('load', res) } } //当前app的 "tab被点击" (从其他app切换到当前app) onTabFocus = async (props) => { let obj = null, systemDate = this.metaAction.gf('data.systemDate') if(props && props.toJS().noDate){ obj = {date: utils.moment.stringToMoment(systemDate).format('YYYY-MM')} } if(props && props.toJS().initSearchValue){ obj = props.toJS().initSearchValue } this.refresh(obj) } //渲染列 getColumns = () => { let columns = this.metaAction.gf('data.other.columnDto').toJS(), list = this.metaAction.gf('data.list').toJS(), other = this.metaAction.gf('data.other').toJS() return renderColumns(columns, list, other, this) } //排序发生变化 sortChange = (key, value) => { let params = { 'userOrderField': value == false ? null : key, 'order': value == false ? null : value } this.injections.reduce('sortReduce', params) if(value) this.refresh(params) } //表格拖宽 onColumnResizeEnd = async (newColumnWidth, columnKey) => { let columnDto = this.metaAction.gf('data.other.columnDto').toJS(), other = this.metaAction.gf('data').toJS().other, params = {}, columnDetails = [] columnDto.map(item=>{ if(item.isVisible) columnDetails.push({ fieldName: item.fieldName, isVisible: item.isVisible, width: item.fieldName == columnKey ? newColumnWidth : item.width }) }) params.code = other.code params.columnDetails = columnDetails let res = await this.webapi.asset.batchUpdate(params) this.injections.reduce('onColumnResizeEnd', res) } //栏目重置 resetTableSetting = async () => { this.injections.reduce('update',{ path: 'data.showTableSetting', value: false }) const other = this.metaAction.gf('data').toJS().other //重置栏目 let res = await this.webapi.asset.reInitByUser({code: other.code}) this.load() } getPeriodValue = (systemDate) =>{ if(systemDate) { return utils.moment.stringToMoment(systemDate) } } //资产属性切换 assetPropertyChange = async (path, option) => { _hmt && _hmt.push(['_trackEvent', '资产', '折旧摊销', '资产属性']) this.metaAction.sf(path, fromJS(option)) let other = this.metaAction.gf('data.other').toJS(), assetClass = { label: '全部', value: 0, assetPropertyId: 0 }, assetClassArr, name = path.split(".") this.metaAction.sf(`${name[0]}.${name[1]}.assetClass`, fromJS(assetClass)) if(other.assetClassAll){ assetClassArr = other.assetClassAll.filter(item => item.assetPropertyId == option.value) } assetClassArr.unshift(assetClass) this.metaAction.sf(`data.other.assetClass`, fromJS(assetClassArr)) this.getSearchAssetClass(option, assetClass) } //资产分类切换 assetClassChange = async (path, option) => { _hmt && _hmt.push(['_trackEvent', '资产', '折旧摊销', '资产分类']) this.metaAction.sf(path, fromJS(option)) let assetProperty = this.metaAction.gf('data.form.assetProperty').toJS() this.getSearchAssetClass(assetProperty, option) } //资产分类查询 getSearchAssetClass = async (assetProperty, assetClass, option) => { let assetClassAll = this.metaAction.gf('data.other.assetClassAll').toJS(), filter = this.metaAction.gf('data.filter').toJS(), ids = '' //if(option && !option.page) option.page = filter.page if(option) filter = option if(!assetProperty.value || (!assetProperty.value && !assetClass.value)){ ids = '' } else if(!assetClass.value){ let assetClassArr = assetClassAll.filter(item => item.assetPropertyId == assetProperty.value), idsArr = [] assetClassArr.map(item => { idsArr.push(item.value) }) ids = idsArr.join(',') } else{ ids = assetClass.value+'' } if(ids) { filter.assetClassId = ids }else{ delete filter.assetClassId } if(assetProperty && assetProperty.label != '全部'){ filter.assetPropertyId = assetProperty.value } filter.page = { currentPage: 1, pageSize: 20 } this.refresh(filter) } //查询上一个月 prev = () => { let filter = this.metaAction.gf('data.filter').toJS(), currentOrg = this.metaAction.context.get("currentOrg"), startMonth = currentOrg.enabledYear +"-"+currentOrg.enabledMonth if(filter.period){ let preMonth = this.metaAction.momentToString(this.getPreMonth(filter.period), 'YYYY-MM') if(moment(preMonth) < moment(startMonth)){ return } filter.period = preMonth this.refresh(filter) } } //查询下一个月 next = () => { let filter = this.metaAction.gf('data.filter').toJS(), systemDate = this.metaAction.gf('data.systemDate') endMonth = this.getNextMonth(utils.moment.stringToMoment(systemDate).format('YYYY-MM')) if(filter.period) { let nextMonth = this.metaAction.momentToString(this.getNextMonth(filter.period), 'YYYY-MM') if(moment(nextMonth) >= moment(endMonth)){ return } filter.period = nextMonth this.refresh(filter) } } //月份不可选控制 disabledMonth = (current) => { let systemDate = this.metaAction.gf('data.systemDate'), endMonth = this.getNextMonth(utils.moment.stringToMoment(systemDate).format('YYYY-MM')), currentOrg = this.metaAction.context.get("currentOrg"), startMonth = currentOrg.enabledYear +"-"+currentOrg.enabledMonth return current && (current >= moment(endMonth) || current <= moment(startMonth)) } getClassName = (period, type) => { let name = "jiantou", disableName = "jiantou disable", systemDate = this.metaAction.gf('data.systemDate'), endMonth = utils.moment.stringToMoment(systemDate).format('YYYY-MM'), currentOrg = this.metaAction.context.get("currentOrg"), startMonth = currentOrg.enabledYear +"-"+currentOrg.enabledMonth if((type == 'next' && moment(period) >= moment(endMonth)) || (type == 'prev' && moment(period) <= moment(startMonth))){ return disableName } return name } //月份查询 depreciationChange = async (e) => { _hmt && _hmt.push(['_trackEvent', '资产', '折旧摊销', '月份查询']) let filter = this.metaAction.gf('data.filter').toJS() let date = this.metaAction.momentToString(e, 'YYYY-MM') filter.period = date this.refresh(filter) } //已提折旧 depreciation = async () => { let filter = this.metaAction.gf('data.filter').toJS() if(filter.period){ let option = {period: filter.period} option.isReturnValue=true let isDepreciation = this.metaAction.gf('data.other.isDepreciation') if(!isDepreciation) return this.metaAction.sf('data.other.isDepreciation', false) let response = await this.webapi.asset.depreciation(option) this.metaAction.sf('data.other.isDepreciation', true) if (response && response.result == false) { this.metaAction.toast('error', response.error.message) } else { this.metaAction.toast('success', '计提折旧成功') this.refresh() } } } //生成凭证 generatingVoucher = async () => { let filter = this.metaAction.gf('data.filter').toJS() if(filter.period){ let option = {period: filter.period} option.isReturnValue=true let isGeneratingVoucher = this.metaAction.gf('data.other.isGeneratingVoucher') if(!isGeneratingVoucher) return this.metaAction.sf('data.other.isGeneratingVoucher', false) let response = await this.webapi.asset.voucher(option) this.metaAction.sf('data.other.isGeneratingVoucher', true) if (response && response.result == false) { this.metaAction.toast('error', response.error.message) } else { this.metaAction.toast('success', '生成凭证成功') this.refresh() } } } //渲染凭证号 getDocCodes = (docCodes, docIds) => { if(!docCodes || !docIds) return let docCodesArr = docCodes.split(','), option = [] return docCodesArr.map((item, index) => { return ( <a className='docCodes' onClick={this.getDocCode.bind(this, docIds, index)}>{index+1 == docCodesArr.length ? item : item+','}</a> ) }) } //查看凭证 getDocCode = (docIds, index) => { let docIdsArr = docIds.split(',') this.component.props.setPortalContent && this.component.props.setPortalContent('填制凭证', 'app-proof-of-charge', { accessType: 1, initData: { id: docIdsArr[index] } }) } //打印 print = async () => { _hmt && _hmt.push(['_trackEvent', '资产', '折旧摊销', '打印']) let printFilter = this.getPrintExportsFilter('print') if(printFilter){ //debugger let res = await this.webapi.asset.print(printFilter) } } //导出 exports = async () => { _hmt && _hmt.push(['_trackEvent', '资产', '折旧摊销', '导出']) let exportsFilter = this.getPrintExportsFilter('exports') if(exportsFilter){ //debugger let res = await this.webapi.asset.exports(exportsFilter) } } getPrintExportsFilter = (exportsOrPrint) => { let filter = this.metaAction.gf('data.filter').toJS(),columnDetails = [], list = this.metaAction.gf('data.list').toJS(), columnDto = this.metaAction.gf('data.other.columnDto').toJS() if(exportsOrPrint == 'print' && !list.length){ this.metaAction.toast('warning', '当前暂无数据可打印') return false }else if(exportsOrPrint == 'exports' && !list.length){ this.metaAction.toast('warning', '当前暂无数据可导出') return false } if(filter.period) { if(filter.page) delete filter.page columnDto.map(item=>{ if(item.isVisible) columnDetails.push(item.fieldName) }) filter.columnDetails = columnDetails return filter }else{ return false } } //查看处置 query = (id) => () => { let title = '资产卡片', status = "query" this.openCard(title, status, id) } openCard = async (title, status, id) => { let res = await this.webapi.asset.isDispatch() if(!res) { this.metaAction.toast('warning', '折旧正在处理中,请稍后') return } const ret = await this.metaAction.modal('show', { title: title, wrapClassName: 'asset-card', // width: 1200, className: 'cards', okText: '确定', closeModal: this.close, closeBack: (back) => {this.closeTip = back}, bodyStyle: {padding: '10px 0px 10px 24px'}, footer: '', children: this.metaAction.loadApp('app-asset-card', { store: this.component.props.store, status: status, id: id ? id : '', }), }) } close = (ret) => { this.closeTip() if(ret) { if(!ret.isQuery) this.refresh() } } //获取上一个月 getPreMonth = (date) => { var arr = date.split('-'); var year = arr[0]; //获取当前日期的年份 var month = arr[1]; //获取当前日期的月份 var year2 = year; var month2 = parseInt(month) - 1; if (month2 == 0) { year2 = parseInt(year2) - 1; month2 = 12; } if (month2 < 10) { month2 = '0' + month2; } var t2 = year2 + '-' + month2; return t2; } //获取下一个月 getNextMonth = (date) => { var arr = date.split('-'); var year = arr[0]; //获取当前日期的年份 var month = arr[1]; //获取当前日期的月份 var year2 = year; var month2 = parseInt(month) + 1; if (month2 == 13) { year2 = parseInt(year2) + 1; month2 = 1; } if (month2 < 10) { month2 = '0' + month2; } var t2 = year2 + '-' + month2; return t2; } //分页修改 pageChanged = (currentPage, pageSize) => { let filter = this.metaAction.gf('data.filter').toJS() if (pageSize == null || pageSize == undefined) { pageSize = this.metaAction.gf('data.page').toJS().pageSize } let page = {currentPage, pageSize} filter.page = page this.refresh(filter) } combineColumnProp = (data) => { if (!data) return [] let newDataArray = [] data.forEach((ele, index) => { newDataArray.push({ "isVisible": ele.isVisible, "id": ele.id, 'ts': ele.ts }) }) return newDataArray } showTableSetting = async ({ value, data }) => { /** * 更新栏目 */ _hmt && _hmt.push(['_trackEvent', '资产', '折旧摊销', '栏目设置']) this.injections.reduce('update',{ path: 'data.showTableSetting', value: false }) if (!value) { let isColumnSolution = this.metaAction.gf('data.other.isColumnSolution') if(!isColumnSolution) return this.metaAction.sf('data.other.isColumnSolution', false) const columnSolution = await this.webapi.asset.findByParam({ code: 'assetDepreciationList' }) if (columnSolution) { let columnSolutionId = columnSolution.id const ts = this.metaAction.gf('data.other.ts') this.metaAction.sf('data.other.loading', true) const columnDetail = await this.webapi.asset.updateWithDetail({ "id": columnSolutionId, "columnDetails": this.combineColumnProp(data), ts: ts }) this.metaAction.sf('data.other.loading', false) this.metaAction.sf('data.other.isColumnSolution', true) if (columnDetail) { this.injections.reduce('settingOptionsUpdate', { visible: value, data: columnDetail.columnDetails }) } }else{ this.metaAction.sf('data.other.isColumnSolution', true) } } else { this.injections.reduce('tableSettingVisible', { value, data: data }) } } closeTableSetting = () => { _hmt && _hmt.push(['_trackEvent', '资产', '折旧摊销', '栏目设置取消']) this.injections.reduce('tableSettingVisible', { value: false }) } openCardClick = async () => { //资产卡片 if (!this.config.apps['edfx-business-subject-manage']) { throw '依赖app-asset-list app,请使用mk clone app-asset-list命令添加' } this.component.props.setPortalContent && this.component.props.setPortalContent('资产卡片', 'app-asset-list') } moreMenuClick = async () => { //科目设置 if (!this.config.apps['edfx-business-subject-manage']) { throw '依赖app-asset-management-list app,请使用mk clone app-asset-management-list命令添加' } this.component.props.setPortalContent && this.component.props.setPortalContent('科目设置', 'edfx-business-subject-manage', {accessType: 'depreciation'}) } } export default function creator(option) { const metaAction = new MetaAction(option), extendAction = extend.actionCreator({ ...option, metaAction }), o = new action({ ...option, metaAction, extendAction }), ret = { ...metaAction, ...extendAction.gridAction, ...o } metaAction.config({ metaHandlers: ret }) return ret }