UNPKG

ttk-app-core

Version:
872 lines (790 loc) 33.1 kB
import React from 'react' import { action as MetaAction, AppLoader } from 'edf-meta-engine' import { fromJS, toJS } from 'immutable' import utils from 'edf-utils' import { LoadingMask } from 'edf-component' import config from './config' import { TableOperate, Select, Button, Modal, Checkbox, PrintOption2 } from 'edf-component' import sortSearchOption from './utils/sortSearchOption' import moment from 'moment' import { FormDecorator } from 'edf-component' import changeToOption from './utils/changeToOption' const Option = Select.Option import { consts } from 'edf-consts' import renderColumns from './utils/renderColumns' class action { constructor(option) { this.metaAction = option.metaAction this.config = config.current this.webapi = this.config.webapi this.voucherAction = option.voucherAction this.selectedOption = [] } onInit = ({ component, injections }) => { this.component = component this.injections = injections injections.reduce('init') this.load() let addEventListener = this.component.props.addEventListener if (addEventListener) { addEventListener('onTabFocus', :: this.onTabFocus) addEventListener('enlargeClick', () => this.onResize({})) } } onTabFocus = (data) => { const currentOrg = this.metaAction.context.get("currentOrg") let enableDateStr = `${currentOrg.enabledYear}-${currentOrg.enabledMonth}` let enableDatePre = this.metaAction.gf('data.other.enableddate') let num1 = this.transformDateToNum(enableDateStr) let num2 = this.transformDateToNum(enableDatePre) if (num1 == num2) { const searchValue = this.metaAction.gf('data.searchValue').toJS() this.searchValueChange(searchValue, 'tabFocus') } else { this.onlySetEnableDate(enableDateStr) this.sortParmas() } } onlySetEnableDate = async (enableDateStr) => { this.injections.reduce('update', { path: 'data.other.enableddate', value: utils.date.transformMomentDate(enableDateStr) }) } load = async () => { let forwardingFlag = await this.webapi.person.getCarryForwardingFlag() if (forwardingFlag) { this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') } this.getInitOption() } componentWillReceiveProps = ({ keydown }) => { if (keydown && keydown.event) { let e = keydown.event if (e.keyCode == 39 || e.keyCode == 40) { this.accountlistBtn('right') } else if (e.keyCode == 37 || e.keyCode == 38) { this.accountlistBtn('left') } } } // 点击刷新按钮 refreshBtnClick = () => { // const searchValue = this.metaAction.gf('data.searchValue').toJS() // this.searchValueChange(searchValue) this.sortParmas() } // 初始化基础信息选项 getInitOption = async () => { const resDate = await this.webapi.person.getDisplayDate() const calDate = this.initDate(resDate.EnableDate, resDate.DisplayDate, false, 'get') const res = await this.webapi.person.init(calDate) const currencylist = changeToOption(res.currencylist, 'name', 'id') const accountlist = res.accountlist const enableddate = resDate.EnableDate this.injections.reduce('initOption', { currencylist, accountlist, enableddate }) // this.initDate(enableddate, displayDate) this.injections.reduce('normalSearchChange', { path: 'data.searchValue.accountcode', value: accountlist[0] ? accountlist[0].code : '' }) // 检测数量和外币checkbox是否显示 this.accountlistChange(accountlist[0] ? accountlist[0].code : '', true) if (accountlist.length > 0) { this.sortParmas() } else { this.injections.reduce('tableLoading', false) } } //初始化选择时间 initDate = (enableddate, displayDate, send, type) => { let enableDate = utils.date.transformMomentDate(enableddate) let now = utils.date.transformMomentDate(displayDate) let date_start, date_end if (enableDate.format('YYYY') == now.format('YYYY')) { date_start = enableDate date_end = now } else { date_start = utils.date.transformMomentDate(now.format('YYYY')) date_end = now } // if( this.transformDateToNum(chu) > utils.date.transformMomentDate(displayDate) ){ // date_start = enableDate // date_end = now // }else{ // date_start = this.transformDateToNum(enableDate) < this.transformDateToNum(chu) ? chu : enableDate // date_end = this.transformDateToNum(enableDate) < this.transformDateToNum(now) ? now : enableDate // } this.injections.reduce('updateArr', [{ path: 'data.searchValue.date_end', value: date_end }, { path: 'data.searchValue.date_start', value: date_start }]) if (type == 'get') { return { begindate: date_start.format('YYYY-MM'), enddate: date_end.format('YYYY-MM'), } } if (send) { const searchValue = this.metaAction.gf('data.searchValue').toJS() this.searchValueChange(searchValue, 'tabFocus') } } // 检测数量和外币checkbox是否显示 accountlistChange = (value, notSend, type, preAccountCode, preAccountList) => { const accountlist = this.metaAction.gf('data.other.accountlist').toJS() const item = accountlist.find(index => { return index.code == value }) const currency = this.metaAction.gf('data.searchValue.currencyId') this.injections.reduce('update', { path: 'data.showCheckbox', value: { quantity: item == -1 || !item ? false : item.isCalcQuantity, multi: currency == '0' || currency == '1' ? false : item == -1 || !item ? false : item.isCalcMulti } }) if (type == 'tabFocus' && value == preAccountCode) { this.tabFocusAccountChange(item, preAccountCode, preAccountList, currency) } else { this.injections.reduce('update', { path: 'data.showOption', value: { num: item == -1 || !item ? false : item.isCalcQuantity, currency: currency == '0' || currency == '1' ? false : item == -1 || !item ? false : item.isCalcMulti } }) } this.injections.reduce('normalSearchChange', { path: 'data.searchValue.accountcode', value }) if (!notSend) { this.sortParmas() } } tabFocusAccountChange = (nowAccount, preAccountCode, preAccountList, currency) => { const item = preAccountList.find(index => { return index.code == preAccountCode }) if (!item) { return } if (item.isCalcQuantity != nowAccount.isCalcQuantity) { this.injections.reduce('update', { path: 'data.showOption.num', value: nowAccount == -1 || !nowAccount ? false : nowAccount.isCalcQuantity }) } if (item.isCalcMulti != nowAccount.isCalcMulti) { this.injections.reduce('update', { path: 'data.showOption.currency', value: currency == '0' || currency == '1' ? false : nowAccount == -1 || !nowAccount ? false : nowAccount.isCalcMulti }) } } //获取时间选项 getNormalDateValue = () => { const data = this.metaAction.gf('data.searchValue').toJS() const arr = [] arr.push(data.date_start) arr.push(data.date_end) return arr } onPanelChange = (value) => { let date = { date_end: value[1], date_start: value[0] } const searchValue = this.metaAction.gf('data.searchValue').toJS() //2018-02-27修改为只要更改时间就需要重新搜索科目,所以需要走高级搜索的逻辑 this.searchValueChange({ ...searchValue, ...date }) // this.injections.reduce('searchUpdate', { ...searchValue, ...date }) // const accountlist = this.metaAction.gf('data.other.accountlist').toJS() // if( accountlist.length == 0 ) { // this.injections.reduce('load', []) // }else{ // this.sortParmas({ ...searchValue, ...date }) // } } getNormalSearchValue = () => { const data = this.metaAction.gf('data.searchValue').toJS() let date = [data.date_start, data.date_end] return { date, query: data.query } } transformDateToNum = (date) => { let time = date if (typeof date == 'string') { time = utils.date.transformMomentDate(date) } return parseInt(`${time.year()}${time.month() < 10 ? `0${time.month()}` : `${time.month()}`}`) } renderCheckBox = () => { return ( <Checkbox.Group className="app-proof-of-list-accountQuery-search-checkbox"> <Checkbox value="1">科目无发生不显示本月合计、本年累计</Checkbox> </Checkbox.Group> ) } // 检查时间发生变化 checkTimeChange = (value) => { const { date_start, date_end } = this.metaAction.gf('data.searchValue').toJS() const date_start_num = this.transformDateToNum(date_start) const date_end_num = this.transformDateToNum(date_end) const searchValue_start = this.transformDateToNum(value.date_start) const searchValue_end = this.transformDateToNum(value.date_end) return date_start_num != searchValue_start || date_end_num != searchValue_end } searchValueChange = async (value, type) => { const preCurrencyId = this.metaAction.gf('data.searchValue.currencyId') const preAccountCode = this.metaAction.gf('data.searchValue.accountcode') let prevValue = this.metaAction.gf('data.searchValue').toJS() if (preCurrencyId != value.currencyId || type == 'tabFocus' || this.checkTimeChange(value)) { const preAccountList = this.metaAction.gf('data.other.accountlist') const res = await this.webapi.person.queryForRpt({ currencyId: value.currencyId, beginDate: value.date_start.format('YYYY-MM'), endDate: value.date_end.format('YYYY-MM') }) this.injections.reduce('update', { path: 'data.other.accountlist', value: res }) // 增加一条逻辑,无论是哪种刷新还是高级搜搜条件发生变化,如果选择的结果中包含原有的科目信息,那么优先显示原有的科目信息 let { calAccountCode, flag } = this.checkAccountCode(res) let params = { ...prevValue, ...value, accountcode: calAccountCode } this.injections.reduce('searchUpdate', params) if (!flag || value.currencyId == 0 || preCurrencyId != value.currencyId || type == 'tabFocus') { this.accountlistChange(calAccountCode, true, type, preAccountCode, preAccountList) } if (value.currencyId == '0' || value.currencyId == '1') { _hmt && _hmt.push(['_trackEvent', '财务', '总账', '高级查询选择综合本位币或人民币']) } else { _hmt && _hmt.push(['_trackEvent', '财务', '总账', '高级查询选择外币']) } if (res.length == 0) { this.injections.reduce('load', []) } else { this.sortParmas(params) } } else { let params = { ...prevValue, ...value } this.injections.reduce('searchUpdate', params) if (value && value.nodatanodisplay && value.nodatanodisplay.length > 0) { _hmt && _hmt.push(['_trackEvent', '财务', '总账', '高级查询选择科目无发生不显示本月合计、本年累计']) } this.sortParmas(params) } } // 检查原有的科目信息是否存在并返回科目code checkAccountCode = (res) => { const accountcode = this.metaAction.gf('data.searchValue.accountcode') if (!accountcode) { return { calAccountCode: res && res[0] && res[0].code ? res[0].code : null, flag: false } } let item = res.find(index => index.code == accountcode) if (item) { return { calAccountCode: item.code, flag: true } } else { return { calAccountCode: res && res[0] && res[0].code ? res[0].code : null, flag: false } } } // 简单搜索条件发生改变 accountlistBtn = (type) => { const accountlist = this.metaAction.gf('data.other.accountlist').toJS() const accountCode = this.metaAction.gf('data.searchValue.accountcode') if (!accountCode) { this.accountlistChange(accountlist[0] ? accountlist[0].code : null) return } let index = accountlist.findIndex(item => item.code == accountCode) let code switch (type) { case 'right': code = accountlist[index + 1] && accountlist[index + 1].code ? accountlist[index + 1].code : accountCode break case 'left': code = accountlist[index - 1] && accountlist[index - 1].code ? accountlist[index - 1].code : accountCode break default: code = accountCode break } if (accountCode == code) { // this.metaAction.toast('warn', '已经是最后一条科目了') } else { this.accountlistChange(code) } } sortParmas = (search, type) => { // 处理搜索参数 if (!search) { search = this.metaAction.gf('data.searchValue').toJS() } const changeData = { 'date_start': { 'begindate': (data) => data ? data.format('YYYY-MM') : null, }, 'date_end': { 'enddate': (data) => data ? data.format('YYYY-MM') : null, } } const searchValue = sortSearchOption(search, changeData) searchValue.nodatanodisplay = searchValue.nodatanodisplay && searchValue.nodatanodisplay.length > 0 ? '1' : '0' if (type == 'get') { return { ...searchValue } } if (!searchValue.accountcode) { return } this.requestData({ ...searchValue }) } // 请求列表中的数据 requestData = async (params) => { // const response = await this.webapi.person.query(params) // this.injections.reduce('load', response) let loading = this.metaAction.gf('data.loading') if (!loading) { this.injections.reduce('tableLoading', true) } const res = await this.webapi.person.getList(params) this.injections.reduce('tableLoading', false) this.injections.reduce('load', res) setTimeout(() => { this.onResize() }, 20) } //请求科目相关信息 queryForRpt = async (value) => { const res = await this.webapi.person.queryForRpt({ currencyId: value }) } shareClick = (e) => { switch (e.key) { case 'weixinShare': this.weixinShare() break; case 'mailShare': this.mailShare() break; } } weixinShare = async () => { let forwardingFlag = await this.webapi.person.getCarryForwardingFlag() if (forwardingFlag) { this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') return } if (this.metaAction.gf('data.list').toJS().length == 0) { this.metaAction.toast('warning', '当前暂无数据可分享') return } let data = this.sortParmas(null, 'get') let displaytype = this.getDisplayType() data.displaytype = `${displaytype}` // let url = await this.webapi.person.weixinShare(data) const ret = this.metaAction.modal('show', { title: '微信/QQ分享', width: 300, footer: null, // closable: false, children: this.metaAction.loadApp('app-weixin-share', { store: this.component.props.store, initData: '/v1/gl/report/glsumrpt/share', params: data }) }) _hmt && _hmt.push(['_trackEvent', '财务', '总账', '分享微信/QQ']) } mailShare = async () => { let forwardingFlag = await this.webapi.person.getCarryForwardingFlag() if (forwardingFlag) { this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') return } if (this.metaAction.gf('data.list').toJS().length == 0) { this.metaAction.toast('warning', '当前暂无数据可分享') return } let params = this.sortParmas(null, 'get') let displaytype = this.getDisplayType() params.displaytype = `${displaytype}` params.printAll = false const ret = this.metaAction.modal('show', { title: '邮件分享', width: 400, // footer: null, // closable: false, children: this.metaAction.loadApp('app-mail-share', { store: this.component.props.store, params: params, shareUrl: '/v1/gl/report/glsumrpt/share', mailShareUrl: '/v1/gl/report/glsumrpt/sendShareMail', printShareUrl: '/v1/gl/report/glsumrpt/print', period: `${params.begindate.replace('-', '.')}-${params.enddate.replace('-', '.')}`, }) }) _hmt && _hmt.push(['_trackEvent', '财务', '总账', '邮件分享']) } moreActionOpeate = (e) => { this[e.key] && this[e.key]() } rowSpan = (text, row, index) => { const obj = { children: <span>{text}</span>, props: { rowSpan: this.calcRowSpan(row.docId, 'docId', index), }, } return obj } normalSearchChange = (path, value) => { // this.injections.reduce('normalSearchChange', { path, value }) if (path == 'date') { this.onPanelChange(value) } } export = async () => { let tempWindow = window.open() let forwardingFlag = await this.webapi.person.getCarryForwardingFlag() if (forwardingFlag) { this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') tempWindow.close() return } else { const params = this.sortParmas(null, 'get') if (!params.accountcode) { this.metaAction.toast('warn', '当前没有可导出数据') tempWindow.close() return } params.displaytype = this.getDisplayType() params.exportAll = false params.tempWindow = tempWindow await this.webapi.person.export(params) } _hmt && _hmt.push(['_trackEvent', '财务', '总账', '导出当前科目']) } getDisplayType = () => { const { num, currency } = this.metaAction.gf('data.showOption').toJS() let displaytype = 0 if (!num && !currency) { displaytype = 0 } else if (num && !currency) { displaytype = 2 } else if (!num && currency) { displaytype = 1 } else if (num && currency) { displaytype = 3 } return displaytype } print = async () => { let tempWindow = window.open() let forwardingFlag = await this.webapi.person.getCarryForwardingFlag() if (forwardingFlag) { this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') tempWindow.close() return } else { const params = this.sortParmas(null, 'get') if (!params.accountcode) { this.metaAction.toast('warn', '当前没有可打印数据') tempWindow.close() return } params.printAll = false params.displaytype = this.getDisplayType() params.tempWindow = tempWindow await this.webapi.person.print(params) } _hmt && _hmt.push(['_trackEvent', '财务', '总账', '打印当前科目']) } checkBoxisShow = (key) => { const showCheckbox = this.metaAction.gf('data.showCheckbox').toJS() return { display: showCheckbox[key] ? 'inline-block' : 'none' } } showOptionsChange = (key, value) => { this.injections.reduce('showOptionsChange', { path: `data.showOption.${key}`, value: value }) setTimeout(() => { this.onResize() }, 20) } // isTotalData = (record) => { // return record.summary == '本月合计' || record.summary == '本年累计' ? 'total_data_weight' : '' // } rowSpan2 = (text, row, index) => { const num = this.calcRowSpan(row.accountDate, 'accountDate', index) const obj = { children: ( <a href="javascript:;" onClick={() => this.openMoreContent(text)}> <span>{text}</span> </a> ), props: { rowSpan: num, }, } return obj } calcRowSpan(text, columnKey, currentRowIndex) { const list = this.metaAction.gf('data.list') if (!list) return const rowCount = list.size if (rowCount == 0 || rowCount == 1) return 1 if (currentRowIndex > 0 && currentRowIndex <= rowCount && text == list.getIn([currentRowIndex - 1, columnKey])) { return 0 } var rowSpan = 1 for (let i = currentRowIndex + 1; i < rowCount; i++) { if (text == list.getIn([i, columnKey])) rowSpan++ else break } return rowSpan } tableColumns = () => { let arr const showOption = this.metaAction.gf('data.showOption').toJS() let type; if (showOption.num && showOption.currency) { arr = renderColumns(4, this.openMoreContent) } else if (showOption.num && !showOption.currency) { arr = renderColumns(3, this.openMoreContent) } else if (!showOption.num && showOption.currency) { arr = renderColumns(2, this.openMoreContent) } else { arr = renderColumns(1, this.openMoreContent) } arr[0].render = this.rowSpan2 return arr } openMoreContent = async (date) => { const searchValue = this.metaAction.gf('data.searchValue').toJS() const showOption = this.metaAction.gf('data.showOption').toJS() this.component.props.setPortalContent && this.component.props.setPortalContent('明细账', 'app-detailaccount-rpt', { accessType: 1, initSearchValue: { accountCode: searchValue.accountcode, currencyId: searchValue.currencyId, noDataNoDisplay: searchValue.nodatanodisplay, date_end: utils.date.transformMomentDate(date), date_start: utils.date.transformMomentDate(date), }, showOption }) } 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-sumaccount-rpt-Body', 'ant-table-thead', 2, 'ant-table-body', 'data.tableOption', e) } }, 200) } 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) { } } /** * current 每个月份 * pointTime 指定比较的时间 * type 'pre' 前 'next' 后 * return 返回 true 代表禁用 */ disabledDate = (current, pointTime, type) => { const enableddate = this.metaAction.gf('data.other.enableddate') // const enableddateNum = this.transformDateToNum(enableddate) if (type == 'pre') { let currentMonth = this.transformDateToNum(current) let enableddateMonth = this.transformDateToNum(enableddate) return currentMonth < enableddateMonth } else { let currentMonth = this.transformDateToNum(current) let pointTimeMonth = this.transformDateToNum(pointTime) let enableddateMonth = this.transformDateToNum(enableddate) return currentMonth < pointTimeMonth || currentMonth < enableddateMonth } } transformDateToNum = (date) => { try { if (!date) { return 0 } let time = date if (typeof date == 'string') { time = utils.date.transformMomentDate(date) } return parseInt(`${time.year()}${time.month() < 10 ? `0${time.month()}` : `${time.month()}`}`) } catch (err) { console.log(err) return 0 } } getNormalSearchValue = () => { const data = this.metaAction.gf('data.searchValue').toJS() let date = [data.date_start, data.date_end] return { date } } filterOptionSummary = (input, option) => { if (option && option.props && option.props.children) { return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0 } return true } printAllAccount = async () => { const _this = this const currencylist = this.metaAction.gf('data.other.currencylist').toJS() this.metaAction.modal('show', { title: '选择格式', width: 500, footer: null, iconType: null, children: <PrintOption2 currency={currencylist} type="打印" callBack={_this.submitPrintOption} /> }) } exportAllAccount = async () => { const _this = this const currencylist = this.metaAction.gf('data.other.currencylist').toJS() this.metaAction.modal('show', { title: '选择格式', width: 500, footer: null, iconType: null, children: <PrintOption2 currency={currencylist} type="导出" callBack={_this.submitExportOption} /> }) } submitExportOption = async (form) => { let tempWindow = window.open() let forwardingFlag = await this.webapi.person.getCarryForwardingFlag() if (forwardingFlag) { this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') tempWindow.close() return } else { const params = this.sortParmas(null, 'get') if (!params.accountcode) { this.metaAction.toast('warn', '当前没有可打印数据') tempWindow.close() return } let { num, currency, currencyId } = form.getValue() if (currencyId == '0') { currency = false } else { currency = true } params.currencyId = currencyId let displaytype = 0 if (!num && !currency) { displaytype = 0 } else if (num && !currency) { displaytype = 2 } else if (!num && currency) { displaytype = 1 } else if (num && currency) { displaytype = 3 } params.displaytype = displaytype params.exportAll = true params.tempWindow = tempWindow await this.webapi.person.export(params) } _hmt && _hmt.push(['_trackEvent', '财务', '总账', '导出所有科目']) } submitPrintOption = async (form) => { let tempWindow = window.open() let forwardingFlag = await this.webapi.person.getCarryForwardingFlag() if (forwardingFlag) { this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') tempWindow.close() return } else { let params = this.sortParmas(null, 'get') params.tempWindow = tempWindow let { num, currency, currencyId } = form.getValue() if (currencyId == '0') { currency = false } else { currency = true } params.currencyId = currencyId let displaytype = 0 if (!num && !currency) { displaytype = 0 } else if (num && !currency) { displaytype = 2 } else if (!num && currency) { displaytype = 1 } else if (num && currency) { displaytype = 3 } params.displaytype = displaytype params.printAll = true await this.webapi.person.print(params) } _hmt && _hmt.push(['_trackEvent', '财务', '总账', '打印所有科目']) } } export default function creator(option) { const metaAction = new MetaAction(option), voucherAction = FormDecorator.actionCreator({ ...option, metaAction }), o = new action({ ...option, metaAction, voucherAction }), ret = { ...metaAction, ...voucherAction, ...o } metaAction.config({ metaHandlers: ret }) return ret }