ttk-app-core
Version:
enterprise develop framework
530 lines (461 loc) • 18 kB
JavaScript
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 utils from 'edf-utils'
import extend from './extend'
import config from './config'
import {consts} from 'edf-consts'
import renderColumns from './utils/renderColumns'
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 () => {
let filter = this.metaAction.gf('data.filter').toJS()
filter.init = true
this.metaAction.sf('data.other.loading', true)
let res = await this.webapi.asset.query(filter)
this.metaAction.sf('data.other.loading', false)
if(res) {
this.injections.reduce('load', {value: res, form: this.searchCard.form})
}
}
getListRowsCount = () => {
return this.metaAction.gf('data.list').size
}
refresh = async (newFilter) => {
let filter = this.metaAction.gf('data.filter').toJS()
if(newFilter && newFilter.page) filter = newFilter
this.metaAction.sf('data.other.loading', true)
let res = await this.webapi.asset.query(filter)
this.metaAction.sf('data.other.loading', false)
if(res) {
this.metaAction.sf(`data.filter`, fromJS(filter))
this.injections.reduce('load', {value: res, form: this.searchCard.form})
}
}
//当前app的 "tab被点击" (从其他app切换到当前app)
onTabFocus = async (props) => {
this.refresh()
}
//渲染列
getColumns = () => {
let columns = this.metaAction.gf('data.other.columnDto').toJS(),
list = this.metaAction.gf('data.list').toJS()
return renderColumns(columns, list, this)
}
//表格拖宽
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()
}
//取消处置
noDispose = async () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产处置清单', '取消处置'])
let selectedArr = this.extendAction.gridAction.getSelected('dataGrid')
if(selectedArr.length){
let ids, arr = []
selectedArr.map((item) => arr.push(item.id))
ids = arr.join(',')
let isNoDispose = this.metaAction.gf('data.other.isNoDispose')
if(!isNoDispose) return
this.metaAction.sf('data.other.isNoDispose', false)
/*const ret = await this.metaAction.modal('confirm', {
title: '取消处置',
content: '确认取消处置?'
})
if(ret){*/
let response = await this.webapi.asset.disposeCancel(ids)
this.metaAction.sf('data.other.isNoDispose', true)
if(response.warning){
this.metaAction.toast('error', response.warning)
}else if(response || response === null) {
this.metaAction.toast('success', '取消处置成功')
this.load()
}
//}
}else{
this.metaAction.toast('warning', '请选择要处置资产')
}
}
//处置结果查看
assetDisposeDetail = async (option) => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产处置清单', '处置结果查看'])
let response = await this.webapi.asset.assetDisposeDetail(option.id)
let clientWidth = document.body.clientWidth,
width = clientWidth<1280?750:900,
height = clientWidth<1280?470:(clientWidth<1680?580:640),
className = 'asset-management',
asset2 = consts.ASSETPROPERTY_0002
if(option&&option.assetPropertyId==asset2) {//无形资产样式 类名
className = 'asset-management asset-management-wx'
} else {//固定资产样式 类名
className = 'asset-management asset-management-gd'
}
if (response){
const ret = await this.metaAction.modal('show', {
title: '资产处置',
wrapClassName: className,
width: width,
height: height,
bodyStyle: {padding: '5px 0', fontSize: '12px'},
children: this.metaAction.loadApp('app-asset-management', {
store: this.component.props.store,
response: response,
option: option,
detail: true
}),
})
}
}
//手工生成凭证
generatingVoucher = async () => {
let selectedArr = this.extendAction.gridAction.getSelected('dataGrid')
if(selectedArr.length){
let ids, arr = []
selectedArr.map((item) => arr.push(item.id))
ids = arr.join(',')
let isGeneratingVoucher = this.metaAction.gf('data.other.isGeneratingVoucher')
if(!isGeneratingVoucher) return
this.metaAction.sf('data.other.isGeneratingVoucher', false)
/*const ret = await this.metaAction.modal('confirm', {
title: '生成凭证',
content: '确认生成凭证?'
})
if(ret){*/
let response = await this.webapi.asset.disposeSubmit(ids)
this.metaAction.sf('data.other.isGeneratingVoucher', true)
if (response || response === null) {
this.metaAction.toast('success', '生成凭证成功')
this.refresh()
}
//}
}else{
this.metaAction.toast('warning', '请选择要生成凭证资产')
}
}
//高级查询查询操作
searchValueChange = async (value) => {
if(value) {
this.metaAction.sf('data.other.oldSearchValue', fromJS(value))
let option = {},
assetProperty = this.metaAction.gf('data.searchValue.assetProperty').toJS(),
assetClass = this.metaAction.gf('data.searchValue.assetClass').toJS()
if(value.startDate) option.startDate = this.metaAction.momentToString(value.startDate,'YYYY-MM-DD')
if(value.endDate) option.endDate = this.metaAction.momentToString(value.endDate,'YYYY-MM-DD')
if(value.assets) option.id = value.assets
if(value.assetDisposeType) option.assetDisposeTypeId = value.assetDisposeType
this.metaAction.sf('data.form.assetProperty', fromJS(assetProperty))
this.metaAction.sf('data.form.assetClass', fromJS(assetClass))
this.getSearchAssetClass(assetProperty, assetClass, option)
}
}
//高级查询取消操作
searchCancelChange = (value) => {
let assetProperty = this.metaAction.gf('data.form.assetProperty').toJS(),
assetClass = this.metaAction.gf('data.form.assetClass').toJS(),
filter = this.metaAction.gf('data.filter').toJS(),
searchValue = {}
let other = this.metaAction.gf('data.other').toJS()
let assetClassArr=[]
if(other.assetClassAll){
assetClassArr = other.assetClassAll.filter(item => item.assetPropertyId == assetProperty.value)
}
assetClassArr.unshift({ label: '全部', value: 0, assetPropertyId: 0 })
this.metaAction.sf(`data.other.assetClass`, fromJS(assetClassArr))
this.metaAction.sf('data.searchValue.assetProperty', fromJS(assetProperty))
this.metaAction.sf('data.searchValue.assetClass', fromJS(assetClass))
}
//高级查询清空操作
clearValueChange = (value) => {
let filter = this.metaAction.gf('data.filter').toJS(),
all = { label: '全部', value: 0 }
this.searchCard.clearValue()
this.metaAction.sf('data.other.assetClass', fromJS([all]))
this.metaAction.sf('data.searchValue.assetProperty', fromJS(all))
this.metaAction.sf('data.searchValue.assetClass', fromJS(all))
this.metaAction.sf('data.other.oldSearchValue', fromJS(value))
}
//资产属性切换
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},
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))
if(name[1] == 'form') {
this.searchCard.clearValue()
let searchValues = this.metaAction.gf(`data.searchValue`).toJS()
this.metaAction.sf(`data.other.oldSearchValue`, fromJS(searchValues))
this.metaAction.sf(`data.searchValue.assetProperty`, fromJS(option))
if(!option.value){
this.metaAction.sf(`data.searchValue.assetClass`, fromJS(option))
}
this.getSearchAssetClass(option, assetClass)
}
}
//资产分类切换
assetClassChange = async (path, option) => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产处置清单', '资产分类'])
this.metaAction.sf(path, fromJS(option))
let list = [],
assetProperty = this.metaAction.gf('data.form.assetProperty').toJS()
let name = path.split(".")
if(name[1] == 'form') {
this.searchCard.clearValue()
let searchValues = this.metaAction.gf(`data.searchValue`).toJS()
this.metaAction.sf(`data.other.oldSearchValue`, fromJS(searchValues))
this.metaAction.sf('data.searchValue.assetClass', fromJS(option))
this.getSearchAssetClass(assetProperty, option)
}
}
//资产分类查询
getSearchAssetClass = async (assetProperty, assetClass, option) => {
let assetClassAll = this.metaAction.gf('data.other.assetClassAll').toJS(),
oldFilter = this.metaAction.gf('data.filter').toJS(),
filter = {}, ids = ''
//if(option && !option.page) option.page = filter.page
if(option) filter = option
if(oldFilter.page) filter.page = oldFilter.page
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
}
if(assetProperty && assetProperty.label != '全部'){
filter.assetPropertyId = assetProperty.value
}
filter.page = {
currentPage: 1,
pageSize: 20
}
this.refresh(filter)
}
//打印
print = async () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产处置清单', '打印'])
let printFilter = this.getPrintExportsFilter('print')
if(printFilter){
let res = await this.webapi.asset.print(printFilter)
}
}
//导出
exports = async () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产处置清单', '导出'])
let exportsFilter = this.getPrintExportsFilter('exports')
if(exportsFilter){
let res = await this.webapi.asset.exports(exportsFilter)
}
}
selectAsset = () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产处置清单', '资产选择'])
}
selectAssetDisposeType = () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产处置清单', '处置方式'])
}
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.page) delete filter.page
columnDto.map(item=>{
if(item.isVisible) columnDetails.push(item.fieldName)
})
filter.columnDetails = columnDetails
return filter
}
/**
* current 每个月份
* pointTime 指定比较的时间
* type 'pre' 前 'next' 后
* return 返回 true 代表禁用
*/
disabledDateDay = (current, pointTime, type) => {
if (type == 'pre') {
if (!pointTime) {
return false
}
let currentDate = current&¤t.format('YYYY-MM-DD')
currentDate&¤tDate.replace(/-/g,'')
let pointTimeDate = pointTime&&pointTime.format('YYYY-MM-DD')
pointTimeDate&&pointTimeDate.replace(/-/g,'')
return false
} else {
let currentDate = current&¤t.format('YYYY-MM-DD')
currentDate&¤tDate.replace(/-/g,'')
let pointTimeDate = pointTime&&pointTime.format('YYYY-MM-DD')
pointTimeDate&&pointTimeDate.replace(/-/g,'')
return currentDate < pointTimeDate
}
}
//渲染凭证号
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) => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产处置清单', '查看凭证'])
let docIdsArr = docIds.split(',')
this.component.props.setPortalContent &&
this.component.props.setPortalContent('填制凭证', 'app-proof-of-charge', { accessType: 1, initData: { id: docIdsArr[index] } })
}
selectRow = (rowIndex) => (e) => {
this.injections.reduce('selectRow', rowIndex, e.target.checked)
}
getSearchCard = (childrenRef) => {
this.searchCard = childrenRef
}
//分页修改
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)
}
filterOptionSummary = (input, option) => {
if (option && option.props && option.props.label) {
return option.props.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
return true
}
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: 'assetDispositionList' })
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 })
}
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: 'profitAndLoss'})
}
}
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
}