ttk-app-core
Version:
enterprise develop framework
721 lines (632 loc) • 23.7 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 renderColumns from './utils/renderColumns'
import moment from 'moment'
import utils from 'edf-utils'
import extend from './extend'
import config from './config'
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')
let isGuide = this.component.props.isGuide
this.metaAction.sf('data.other.enabledGuide', isGuide)
this.load()
}
load = async (params) => {
let filter = this.metaAction.gf('data.filter').toJS()
if (params && params.userOrderField) {
filter.userOrderField = params.userOrderField
filter.order = params.order
}
if (params && params.descOrder) {
filter.descOrder = params.descOrder
}
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 (asset) => {
let filter = this.metaAction.gf('data.filter').toJS()
this.metaAction.sf('data.other.loading', true)
let res = await this.webapi.asset.findAssetList(filter)
this.metaAction.sf('data.other.loading', false)
if (res) {
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(),
other = this.metaAction.gf('data.other').toJS()
return renderColumns(columns, list, other, this)
}
/**
* current 每个月份
* pointTime 指定比较的时间
* type 'pre' 前 'next' 后
* return 返回 true 代表禁用
*/
disabledDateDay = (current, pointTime, type) => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '开始使用时间'])
if (type == 'pre') {
if (!pointTime) {
return false
}
let currentDate = current && current.format('YYYY-MM-DD')
currentDate && currentDate.replace(/-/g, '')
let pointTimeDate = pointTime && pointTime.format('YYYY-MM-DD')
pointTimeDate && pointTimeDate.replace(/-/g, '')
return false
} else {
let currentDate = current && current.format('YYYY-MM-DD')
currentDate && currentDate.replace(/-/g, '')
let pointTimeDate = pointTime && pointTime.format('YYYY-MM-DD')
pointTimeDate && pointTimeDate.replace(/-/g, '')
return currentDate < pointTimeDate
}
}
//排序发生变化
sortChange = (key, value) => {
let params = {
'userOrderField': value == false ? null : key,
'order': value == false ? null : value
}
this.injections.reduce('sortReduce', params)
if (value) this.load(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)
}
//导入
imports = async () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片列表', '导入'])
const ret = await this.metaAction.modal('show', {
title: '导入',
width: 560,
okText: '导入',
children: this.metaAction.loadApp('app-asset-import', {
store: this.component.props.store,
}),
})
if (ret) {
let fliters = this.metaAction.gf(`data.filter`).toJS()
let filter = {}
filter.page = fliters.page
this.metaAction.sf(`data.filter`, fromJS(filter))
this.load()
}
}
//打印
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)
}
}
selectAsset = () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '资产'])
}
assetAddType = () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '增加方式'])
}
deprMethod = () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '折旧方法'])
}
assetState = () => {
_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
}
//新增
newClick = async () => {
let title = '新增资产卡片'
this.openCard(title, "new")
}
moreMenuClick = async (v) => {
if (v.key == 'depreciation') {
_hmt && _hmt.push(['_trackEvent', '资产', '更多', '折旧/摊销'])
//折旧摊销
if (!this.config.apps['app-asset-depreciation']) {
throw '依赖app-asset-depreciation app,请使用mk clone app-asset-depreciation命令添加'
}
this.component.props.setPortalContent &&
this.component.props.setPortalContent('折旧摊销清单', 'app-asset-depreciation', { accessType: 'card', noDate: true })
} else if (v.key == 'disposal') {
_hmt && _hmt.push(['_trackEvent', '资产', '更多', '已处置资产清单'])
//已处置资产清单
if (!this.config.apps['app-asset-management-list']) {
throw '依赖app-asset-management-list app,请使用mk clone app-asset-management-list命令添加'
}
this.component.props.setPortalContent &&
this.component.props.setPortalContent('资产处置清单', 'app-asset-management-list')
} else if (v.key == 'del') {
_hmt && _hmt.push(['_trackEvent', '资产', '更多', '卡片删除'])
//卡片批量删除
let selectedArr = this.extendAction.gridAction.getSelected('dataGrid'), arr = [],
list = this.metaAction.gf('data.list').toJS()
selectedArr.map(item => {
//let option = list.filter(m=>{if(item.id == m.id && m.act != "change" && m.changeTypeId != 5100060004 && Number(m.seq)) return m})
let option = list.filter(m => { if (item.id == m.id && Number(m.seq)) return m })
if (option.length) arr.push({ cardId: option[0].cardId })
})
if (!arr.length) {
this.metaAction.toast('warning', '请选择资产')
return
}
this.del(arr)
}
}
//删除
delClick = (option) => (e) => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '删除'])
this.del([{ cardId: option.cardId }])
}
del = async (option) => {
const ret = await this.metaAction.modal('confirm', {
title: '删除',
content: '将删除资产卡片及相关凭证'
})
if (ret) {
option.isReturnValue = true
let response = await this.webapi.asset.delete(option)
if (response && response.result == false) {
this.metaAction.toast('error', response.error.message)
} else {
let tipArr = []
if (response && response['60503']) tipArr.push(response['60503'])
if (response && response['6050301']) tipArr.push(response['6050301'])
if (tipArr.length) {
this.metaAction.toast('warning', this.getDelTip(tipArr))
} else {
this.metaAction.toast('success', '删除成功')
}
this.load()
}
}
}
getDelTip = (tipArr) => {
return (
<div className='app-asset-list-del-tip'>
{tipArr.map((item) => { return <p className='app-asset-list-del-tip-item'>{item}</p> })}
</div>
)
}
//修改
modifyDetail = (option) => () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '修改'])
let status = option.act, title = (status == 'edit') ? '修改资产卡片' : '变动资产卡片'
this.openCard(title, status, option.id, option.cardId)
}
//查看
query = (id) => () => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '查看'])
let title = '资产卡片', status = "query"
this.openCard(title, status, id)
}
openCard = async (title, status, id, cardId) => {
if (status != 'new') {
let isCardEdit = this.metaAction.gf('data.other.isCardEdit')
if(!isCardEdit) return
this.injections.reduce('setStatus', 'data.other.isCardEdit', false)
let res = await this.webapi.asset.isDispatch()
this.injections.reduce('setStatus', 'data.other.isCardEdit', true)
if (!res) {
this.metaAction.toast('warning', '折旧正在处理中,请稍后')
return
}
}
const ret = await this.metaAction.modal('show', {
title: title,
wrapClassName: 'asset-card',
// width: 1200,
className: 'cards',
okText: '确定',
bodyStyle: { padding: '10px 0px 10px 24px' },
closeModal: this.close,
closeBack: (back) => { this.closeTip = back },
footer: '',
children: this.metaAction.loadApp('app-asset-card', {
store: this.component.props.store,
status: status,
id: id ? id : '',
cardId: cardId ? cardId : '',
isGuide: this.metaAction.gf('data.other.enabledGuide'),
isMenuCode: this.component.props.isMenuCode,
closeGuideFunc: this.component.props.closeGuide,
parentAppName: this.component.props.appName,
parentGuideState: this.enabledGuide
}),
})
}
//关闭guide
enabledGuide = () => {
this.metaAction.sf('data.other.enabledGuide', false)
}
close = (ret) => {
this.closeTip()
if (ret) {
if (!ret.isQuery) this.load({ descOrder: true })
}
}
//资产处置
managementClick = (option) => (e) => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '处置'])
this.managementConfirm(option)
}
managementConfirm = async (option) => {
let opt = {}
opt['assetPropertyId'] = option.assetPropertyId
opt['id'] = option.id
let managementConfirm = this.metaAction.gf('data.other.managementConfirm')
if(!managementConfirm) return
this.injections.reduce('setStatus', 'data.other.managementConfirm', false)
let response = await this.webapi.asset.managementConfirm(opt)
this.injections.reduce('setStatus', 'data.other.managementConfirm', true)
if (!response) {
const ret = await this.metaAction.modal('confirm', {
title: '提示',
content: '请先在【折旧摊销管理】菜单内【手工生成凭证】后再进行资产处置'
})
if (ret) {
this.management(option)
}
} else {
this.management(option)
}
}
management = async (option) => {
let res = await this.webapi.asset.isDispatch()
if (!res) {
this.metaAction.toast('warning', '折旧正在处理中,请稍后')
return
}
let clientWidth = document.body.clientWidth,
width = clientWidth < 1280 ? 750 : 900,
height = clientWidth < 1280 ? 470 : (clientWidth < 1680 ? 580 : 640),
className = 'asset-management'
if (option && option.assetPropertyId == 5100010002) {//无形资产样式 类名
className = 'asset-management asset-management-wx'
} else {//固定资产样式 类名
className = 'asset-management asset-management-gd'
}
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,
option: option
}),
})
if (ret) {
if (ret.isView) return
if (!this.config.apps['app-asset-management-list']) {
throw '依赖app-asset-management-list app,请使用mk clone app-asset-management-list命令添加'
}
this.component.props.setPortalContent &&
this.component.props.setPortalContent('资产处置清单', 'app-asset-management-list')
}
}
//记录
recordClick = (option) => (e) => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '记录'])
this.getRecord(option)
}
getRecord = async (option) => {
const ret = await this.metaAction.modal('show', {
title: '记录',
width: 700,
bodyStyle: { height: 400, padding: '12px 0' },
wrapClassName: 'asset-record',
children: this.metaAction.loadApp('app-asset-record', {
store: this.component.props.store,
option: option
}),
})
}
//长期待摊项点击处置按钮时的提示
disposeTip = () => {
this.metaAction.toast('warning', '长期待摊费用暂不提供处置功能,请知悉')
}
renderCheckBox = () => {
return (
<Checkbox.Group>
<Checkbox value="1">包含已处置资产</Checkbox>
</Checkbox.Group>
)
}
//高级查询查询操作
searchValueChange = async (value) => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '高级查询'])
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.endDate) option.endDate = this.metaAction.momentToString(value.endDate, 'YYYY-MM-DD')
if (value.startDate) option.beginDate = this.metaAction.momentToString(value.startDate, 'YYYY-MM-DD')
if (value.assetAddType) option.addTypeId = value.assetAddType
if (value.assets) option.cardId = value.assets
if (value.deprMethod) option.deprMethodId = value.deprMethod
if (value.state) option.isDraft = value.state - 1
//if(value.hasDisposalAsset) option.hasDisposalAsset = value.hasDisposalAsset.length ? 1 : 0
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) => {
_hmt && _hmt.push(['_trackEvent', '资产', '资产卡片', '清空'])
let filter = this.metaAction.gf('data.filter').toJS(),
all = { label: '全部', value: 0 }
this.searchCard.clearValue()
value.state = 0
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()
this.metaAction.sf(`data.searchValue.state`, fromJS(0))
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()
this.metaAction.sf(`data.searchValue.state`, fromJS(0))
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 = { /*hasDisposalAsset: 0*/ }, ids = ''
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.metaAction.sf('data.other.loading', true)
let res = await this.webapi.asset.findAssetList(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 })
}
}
//分页修改
pageChanged = async (currentPage, pageSize) => {
let filter = this.metaAction.gf('data.filter').toJS()
if (pageSize == null || pageSize == undefined) {
pageSize = this.metaAction.gf('data.page').toJS().pageSize
}
filter.page = { currentPage, pageSize }
this.metaAction.sf('data.other.loading', true)
let res = await this.webapi.asset.findAssetList(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 })
}
}
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: 'assetList' })
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 })
}
//栏目重置
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()
}
getSearchCard = (childrenRef) => {
this.searchCard = childrenRef
}
selectRow = (rowIndex) => (e) => {
this.injections.reduce('selectRow', rowIndex, e.target.checked)
}
}
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
}