ttk-app-core
Version:
enterprise develop framework
266 lines (253 loc) • 8.65 kB
JavaScript
import React from 'react'
import { action as MetaAction, AppLoader } from 'edf-meta-engine'
import { Map, fromJS } from 'immutable'
import { LoadingMask } from 'edf-component'
import extend from './extend'
import config from './config'
import moment from 'moment'
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)
}
injections.reduce('init')
this.load()
}
//加载
load = async () => {
this.getEnableDate().then((parmas) => {
this.sortParmas()
})
}
//页签切换
onTabFocus = () => {
this.getEnableDate().then((parmas) => {
this.sortParmas()
})
}
//获取开账期间
getEnableDate = async () => {
const currentOrg = this.metaAction.context.get("currentOrg")
const enabledPeriod=currentOrg.enabledYear + '-' + `${currentOrg.enabledMonth}`.padStart(2, '0')
this.metaAction.sf('data.enableDate', enabledPeriod)
const isChangeSipmleDate = this.metaAction.gf('data.changeSipmleDate')
if (!isChangeSipmleDate){
const docVoucherDate = await this.webapi.apocRptStatement.getDisplayDate()
const maxDocPeriod =docVoucherDate.DisplayDate
this.metaAction.sf('data.period', maxDocPeriod)
}
}
//日期选择
onDatePickerChange = (value) => {
this.metaAction.sf('data.period', value)
this.metaAction.sf('data.changeSipmleDate', true)
this.sortParmas()
}
//刷新
refresh = (value) => {
this.sortParmas()
}
//导出
export = async () => {
if (this.metaAction.gf('data.list').length == 0) {
this.metaAction.toast('warning', '当前没有可导出数据')
return
}
this.sortParmas('get').then((parmas) => {
// LoadingMask.show()
this.webapi.apocRptStatement.export(parmas)
// LoadingMask.hide()
})
}
//打印
print = async () => {
if (this.metaAction.gf('data.list').length == 0) {
this.metaAction.toast('warning', '当前没有可打印数据')
return
}
this.sortParmas('get').then((parmas) => {
// LoadingMask.show()
this.webapi.apocRptStatement.print(parmas)
// LoadingMask.hide()
})
}
shareClick = (e) => {
switch (e.key) {
case 'weixinShare':
this.weixinShare()
break;
case 'mailShare':
this.mailShare()
break;
}
}
weixinShare = async () => {
const ret = this.metaAction.modal('show', {
title: '微信/QQ分享',
width: 320,
// footer: null,
closable: false,
children: this.metaAction.loadApp('app-weixin-share', {
store: this.component.props.store
})
})
}
mailShare = () => {
const ret = this.metaAction.modal('show', {
title: '邮件分享',
width: 470,
closable: false,
children: this.metaAction.loadApp('app-mail-share', {
store: this.component.props.store
})
})
}
colSpan0 = (text, row, index) => {
let obj
if (row && row.accountName == '合计') {
obj = {
children: <span title={row.accountName}>{row.accountName}</span>,
props: {
colSpan: 2,
}
}
} else {
obj = {
children: <span title={text}>{text}</span>,
props: {
colSpan: 1
}
}
}
return obj
}
colSpan1 = (text, row, index) => {
let obj
if (row && row.accountName == '合计') {
obj = {
props: {
colSpan: 0,
}
}
} else {
obj = {
children: <span title={text}>{text}</span>,
props: {
colSpan: 1
}
}
}
return obj
}
tableColumns = () => {
let arr = renderColumns()
arr[0].render = this.colSpan0
arr[1].render = this.colSpan1
return arr
}
sortParmas = async (type) => {
const voucherMoment = moment(this.metaAction.gf('data.period'))
let dateParameters = {
"year": voucherMoment.format('YYYY'),
"period": voucherMoment.format('MM')
}
if (type == 'get') {
return { ...dateParameters }
}
let loading = this.metaAction.gf('data.loading')
if(!loading){
this.injections.reduce('tableLoading', true)
}
const response = await this.webapi.apocRptStatement.query(dateParameters)
this.injections.reduce('tableLoading', false)
this.injections.reduce('load', response)
setTimeout(() => {
this.onResize()
}, 20)
}
componentWillUnmount = () => {
if (window.removeEventListener) {
window.removeEventListener('resize', this.onResize, false)
} else if (window.detachEvent) {
window.detachEvent('onresize', this.onResize)
} else {
window.onresize = undefined
}
}
componentDidMount = () => {
if (window.addEventListener) {
window.addEventListener('resize', this.onResize, false)
} else if (window.attachEvent) {
window.attachEvent('onresize', this.onResize)
} else {
window.onresize = this.onResize
}
}
onResize = (e) => {
let keyRandomTab = Math.floor(Math.random() * 10000)
this.keyRandomTab = keyRandomTab
setTimeout(() => {
if (keyRandomTab == this.keyRandomTab) {
this.getTableScroll('app-proof-of-collect-rpt-table-tbody', 'ant-table-thead', 0, 'ant-table-body', 'data.tableOption', e)
}
}, 20)
}
getTableScroll = (contaienr, head, num, target, path, e) => {
try {
const tableCon = document.getElementsByClassName(contaienr)[0]
if (!tableCon) {
if (e) {
return
}
setTimeout(() => {
this.getTableScroll(contaienr, head, num, target, path)
}, 500)
return
}
const header = tableCon.getElementsByClassName(head)[0]
const body = tableCon.getElementsByClassName(target)[0].getElementsByTagName('table')[0]
const pre = this.metaAction.gf(path).toJS()
const y = tableCon.offsetHeight - header.offsetHeight - num
const bodyHeight = body.offsetHeight
if (bodyHeight > y && y != pre.y) {
this.metaAction.sf(path, fromJS({ ...pre, y }))
} else if (bodyHeight < y && pre.y != null) {
this.metaAction.sf(path, fromJS({ ...pre, y: null }))
} else {
return false
}
} catch (err) {
}
}
}
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
}