UNPKG

ttk-app-core

Version:
714 lines (667 loc) 28.9 kB
import React from 'react' import { action as MetaAction, AppLoader } from 'edf-meta-engine' import { Map, fromJS } from 'immutable' import config from './config' import { TableOperate, Select, Button, Modal, Checkbox } 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' import { LoadingMask } from 'edf-component' 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 let addEventListener = this.component.props.addEventListener if (addEventListener) { addEventListener('onTabFocus', :: this.onTabFocus) addEventListener('enlargeClick', () => this.onResize({})) } injections.reduce('init') this.getInitOption() } componentWillUnmount = () => { let removeEventListener = this.component.props.removeEventListener if (removeEventListener) { removeEventListener('onTabAdd') } 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 } } 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') } } } onTabFocus = (params) => { this.getInitOption('tabFocus',params.toJS()) } // 初始化基础信息选项 getInitOption = async (type='load',params) => { let forwardingFlag = await this.webapi.balanceSumRpt.getCarryForwardingFlag() if(forwardingFlag){ this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') } //科目 const accountList = await this.webapi.balanceSumRpt.queryAccountList({}) const currencyParams = { isContainComprehensiveCurrency: true } //币种列表 const currencyList = await this.webapi.balanceSumRpt.queryForCurrency(currencyParams) //科目级次 const accountDepthList = await this.webapi.balanceSumRpt.queryAccountDepth() const maxDocPeriod = await this.getMaxDocPeriod() const enabledPeriod = await this.getEnablePeriod() let res = null, isChangeSipmleDate = this.metaAction.gf('data.other.changeSipmleDate') if (type == 'tabFocus') { //页签切换,判断简单日期是否修改过。 if (isChangeSipmleDate) { res = { accountList, currencyList, accountDepthList, enabledPeriod } } else { res = { accountList, currencyList, accountDepthList, enabledPeriod, maxDocPeriod } } if(params && params.initSearchValue){ this.injections.reduce('initOption', { ...res }) //联查加载 this.setInitSearchData(params.initSearchValue) } } else { res = { accountList, currencyList, accountDepthList, enabledPeriod, maxDocPeriod } if (this.component.props.initSearchValue) { this.injections.reduce('initOption', { ...res }) //联查加载 this.setInitSearchData(this.component.props.initSearchValue) } } //打开页签加载 if (!params&& !this.component.props.initSearchValue){ this.injections.reduce('initOption', { ...res }) const prevValue=this.metaAction.gf('data.searchValue').toJS() this.setSearchField(prevValue.onlyShowEndAccount) this.injections.reduce('searchUpdate', { ...prevValue }) } this.sortParmas() } setInitSearchData = async(currentValue)=>{ let prevValue = this.metaAction.gf('data.searchValue').toJS() prevValue.date_start = currentValue.date_start prevValue.date_end = currentValue.date_end prevValue.beginAccountCode = currentValue.beginAccountCode prevValue.endAccountCode = currentValue.endAccountCode prevValue.currencyId = currentValue.currencyId || '0' prevValue.beginAccountGrade = '1' prevValue.endAccountGrade = '5' prevValue.onlyShowEndAccount = [] prevValue.showZero = ['1'] prevValue.showAuxAccCalc = ['1'] prevValue.printType = 0 this.setSearchField(prevValue.onlyShowEndAccount) let prevShowOption = this.metaAction.gf('data.showOption').toJS() prevShowOption = { currency:false, quantity:false} this.injections.reduce('optionsUpdate', { ...prevShowOption }) this.injections.reduce('searchUpdate', { ...prevValue }) } getEnablePeriod = async () => { const currentOrg = this.metaAction.context.get("currentOrg") const enabledPeriod = currentOrg.enabledYear + '-' + `${currentOrg.enabledMonth}`.padStart(2, '0') return enabledPeriod } //获取凭证所在的最大期间座位默认日期 getMaxDocPeriod = async () => { // const docVoucherDate = await this.webapi.balanceSumRpt.getDocVoucherDate() // const maxDocPeriod = docVoucherDate.year + '-' + `${docVoucherDate.period}`.padStart(2, '0') const res = await this.webapi.balanceSumRpt.getDisplayDate() // console.log(maxDocPeriod) return res.DisplayDate } //获取时间选项 getNormalDateValue = () => { const data = this.metaAction.gf('data.searchValue').toJS() const arr = [] arr.push(data.date_start) arr.push(data.date_end) return arr } normalSearchChange = (path, value) => { if (path == 'date') { let date = { date_end: value[1], date_start: value[0] } const searchValue = this.metaAction.gf('data.searchValue').toJS() //记录是否变更过日期 this.metaAction.sf('data.other.changeSipmleDate',true) this.injections.reduce('searchUpdate', { ...searchValue, ...date }) 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 } } /** * current 每个月份 * pointTime 指定比较的时间 * type 'pre' 前 'next' 后 * return 返回 true 代表禁用 */ disabledDate = (current, pointTime, type) => { const enableddate = this.metaAction.gf('data.other.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) => { let time = date if (typeof date == 'string') { time = moment(new Date(date)) } return parseInt(`${time.year()}${time.month() < 10 ? `0${time.month()}` : `${time.month()}`}`) } // 点击刷新按钮 refreshBtnClick = () => { this.sortParmas() } renderCheckBox1 = () => { return ( <Checkbox.Group className="app-proof-of-list-accountQuery-search-checkbox" onChange={this.setSearchField}> <Checkbox value="1" >仅显示末级科目</Checkbox> </Checkbox.Group> ) } renderCheckBox2 = () => { return ( <Checkbox.Group className="app-proof-of-list-accountQuery-search-checkbox"> <Checkbox value="1">显示余额为0,发生额不为0的记录</Checkbox> </Checkbox.Group> ) } renderCheckBox3 = () => { return ( <Checkbox.Group className="app-proof-of-list-accountQuery-search-checkbox"> <Checkbox value="1">显示辅助核算</Checkbox> </Checkbox.Group> ) } searchValueChange = (value) => { let prevValue = this.metaAction.gf('data.searchValue').toJS() const currencyList = this.metaAction.gf('data.other.tmpCurrencyList').toJS() if(value){ const item = currencyList.find(index => { return index.id == value.currencyId }) this.injections.reduce('showOptionsChange', { path: `data.showOption.multi`, value: item && item.id == '0' ? false : item.isBaseCurrency == true ? false : true }) if ((item && item.id == '0') || item.isBaseCurrency){ this.injections.reduce('showOptionsChange', { path: `data.showOption.currency`, value: false }) _hmt && _hmt.push(['_trackEvent', '财务', '余额表', '高级查询选择综合本位币或人民币']) }else{ _hmt && _hmt.push(['_trackEvent', '财务', '余额表', '高级查询选择外币']) } //埋点需求 // 余额表 + 高级查询 + 仅显示末级科目 // 余额表 + 高级查询 + 显示余额为0,发生额不为0的记录 // 余额表 + 高级查询 + 示辅助核算 // 余额表 + 高级查询 + 选择综合本位币或人民币 // 余额表 + 高级查询 + 选择外币 if (value.onlyShowEndAccount && value.onlyShowEndAccount.length > 0){ _hmt && _hmt.push(['_trackEvent', '财务', '余额表', '高级查询仅显示末级科目']) } if (value.showZero && value.showZero.length > 0) { _hmt && _hmt.push(['_trackEvent', '财务', '余额表', '高级查询显示余额为0,发生额不为0的记录']) } if (value.showAuxAccCalc && value.showAuxAccCalc.length > 0) { _hmt && _hmt.push(['_trackEvent', '财务', '余额表', '高级查询显示辅助核算']) } this.injections.reduce('searchUpdate', { ...prevValue, ...value }) this.sortParmas({ ...prevValue, ...value }) //记录是否变更过日期 this.metaAction.sf('data.other.changeSipmleDate', true) }else{ this.setSearchField(prevValue.onlyShowEndAccount) } } filterOption = (inputValue, option) => { if (option && option.props && option.props.value) { let accountingSubjects = this.metaAction.gf('data.other.startAccountList') let itemData = accountingSubjects.find(o => o.get('value') == option.props.value) let accountName ='' if (itemData.get('label') && itemData.get('value')){ accountName = itemData.get('label').replace(itemData.get('value'),'') } if ((itemData.get('value') && itemData.get('value').indexOf(inputValue) == 0) || (accountName.replace(new RegExp(inputValue, 'g'), '').indexOf(inputValue) !=-1)) { //将滚动条置顶 let select = document.getElementsByClassName('ant-select-dropdown-menu') if (select.length > 0 && select[0].scrollTop > 0) { select[0].scrollTop = 0 } return true } else { return false } } return true } sortParmas = (search, type) => { // * @apiParam {Number} beginYear 起始年份 // * @apiParam {Number} beginPeriod 起始期间 // * @apiParam {Number} endYear 结束年份 // * @apiParam {Number} endPeriod 结束期间 // * @apiParam {String} beginAccountCode 起始科目编码 // * @apiParam {String} endAccountCode 结束科目编码 // * @apiParam {Number} currencyId=0 币种 id,0 代表本位币 // * @apiParam {Number} beginAccountGrade 起始科目级次 // * @apiParam {Number} endAccountGrade 结束科目级次 // * @apiParam {Boolean} onlyShowEndAccount=false 是否仅显示末级科目 // * @apiParam {Boolean} showZero=true 余额为 0 是否显示 if (!search) { search = this.metaAction.gf('data.searchValue').toJS() } const changeData = { 'date_start': { 'beginDate': (data) => data ? data.format('YYYY-MM') : null, 'beginYear': (data) => data ? data.format('YYYY') : null, 'beginPeriod': (data) => data ? data.format('MM') : null, }, 'date_end': { 'endDate': (data) => data ? data.format('YYYY-MM') : null, 'endYear': (data) => data ? data.format('YYYY') : null, 'endPeriod': (data) => data ? data.format('MM') : null, } } const searchValue = sortSearchOption(search, changeData) const showOption = this.metaAction.gf('data.showOption').toJS() if (!showOption.quantity && !showOption.currency) { searchValue.printType = 0 } else if (showOption.quantity && !showOption.currency) { searchValue.printType = 1 } else if (!showOption.quantity && showOption.currency) { searchValue.printType = 2 } else if (showOption.quantity && showOption.currency) { searchValue.printType = 3 } searchValue.onlyShowEndAccount = searchValue.onlyShowEndAccount && searchValue.onlyShowEndAccount.length > 0 ? 'true' : 'false' searchValue.showZero = searchValue.showZero && searchValue.showZero.length > 0 ? 'true' : 'false' searchValue.showAuxAccCalc = searchValue.showAuxAccCalc && searchValue.showAuxAccCalc.length > 0 ? 'true' : 'false' if (type == 'get') { return { ...searchValue } } this.requestData({ ...searchValue }).then((res) => { if (res && res.details){ this.injections.reduce('load', res) } setTimeout(() => { this.onResize() }, 20) }) } requestData = async (params) => { let res // LoadingMask.show() let loading = this.metaAction.gf('data.loading') if(!loading){ this.injections.reduce('tableLoading', true) } res = await this.webapi.balanceSumRpt.queryRptList(params) // LoadingMask.hide() this.injections.reduce('tableLoading', false) return res } shareClick = (e) => { switch (e.key) { case 'weixinShare': this.weixinShare() break; case 'mailShare': this.mailShare() break; } } weixinShare = async () => { let forwardingFlag = await this.webapi.balanceSumRpt.getCarryForwardingFlag() if(forwardingFlag){ this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') return } if (this.metaAction.gf('data.list').toJS().length == 0) { this.metaAction.toast('warning', '当前暂无数据可分享') return } let data = await this.sortParmas(null, 'get') const ret = this.metaAction.modal('show', { title: '微信/QQ分享', width: 300, footer: null, children: this.metaAction.loadApp('app-weixin-share', { store: this.component.props.store, initData: '/v1/gl/report/balancesumrpt/share', params: data }) }) _hmt && _hmt.push(['_trackEvent', '财务', '余额表', '分享微信/QQ']) } mailShare = async () => { let forwardingFlag = await this.webapi.balanceSumRpt.getCarryForwardingFlag() if(forwardingFlag){ this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') return } if (this.metaAction.gf('data.list').toJS().length == 0) { this.metaAction.toast('warning', '当前暂无数据可分享') return } let data = await this.sortParmas(null, 'get') const ret = this.metaAction.modal('show', { title: '邮件分享', width: 400, children: this.metaAction.loadApp('app-mail-share', { store: this.component.props.store, params: data, shareUrl: '/v1/gl/report/balancesumrpt/share', mailShareUrl: '/v1/gl/report/balancesumrpt/sendShareMail', printShareUrl: '/v1/gl/report/balancesumrpt/print', period: `${data.beginDate.replace('-','.')}-${data.endDate.replace('-','.')}`, }) }) _hmt && _hmt.push(['_trackEvent', '财务', '余额表', '分享邮件分享']) } moreActionOpeate = (e) => { this[e.key] && this[e.key]() } showOptionsChange = (key, value) => { this.injections.reduce('tableLoading', true) this.injections.reduce('showOptionsChange', { path: `data.showOption.${key}`, value: value }) const prevValue = this.metaAction.gf('data.showOption').toJS() this.injections.reduce('optionsUpdate', { ...prevValue }) setTimeout(() => { this.injections.reduce('tableLoading', false) },500) } setSearchField = (array) => { if(array && array.length==1){ //勾选末级科目置灰科目级次 this.injections.reduce('showOptionsChange', { path: 'data.other.gradeStyleStatus', value: true }) }else{ this.injections.reduce('showOptionsChange', { path: 'data.other.gradeStyleStatus', value: false }) } this.metaAction.sf('data.searchValue.onlyShowEndAccount',fromJS(array)) } checkBoxisShow = (key) => { const showCheckbox = this.metaAction.gf('data.showOption').toJS() return { display: showCheckbox[key] ? 'inline-block' : 'none' } } export = async () => { let tempWindow = window.open() let forwardingFlag = await this.webapi.balanceSumRpt.getCarryForwardingFlag() if(forwardingFlag){ this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') tempWindow.close() return }else{ if (this.metaAction.gf('data.list').toJS().length == 0) { this.metaAction.toast('warning', '当前没有可导出数据') tempWindow.close() return } const params = this.sortParmas(null, 'get') params.tempWindow = tempWindow await this.webapi.balanceSumRpt.export(params) } _hmt && _hmt.push(['_trackEvent', '财务', '余额表', '导出所有科目']) } print = async () => { let tempWindow = window.open() let forwardingFlag = await this.webapi.balanceSumRpt.getCarryForwardingFlag() if(forwardingFlag){ this.metaAction.toast('warning', '您修改了数据,系统正在重新计算,请稍后') tempWindow.close() return }else{ const params = this.sortParmas(null, 'get') if (this.metaAction.gf('data.list').toJS().length == 0) { this.metaAction.toast('warning', '当前没有可打印数据') tempWindow.close() return } params.tempWindow = tempWindow await this.webapi.balanceSumRpt.print(params) } _hmt && _hmt.push(['_trackEvent', '财务', '余额表', '打印所有科目']) } accountCodeSpan = (text, row, index) => { let obj = null let num = this.metaAction.gf('colSpan') if (row && row.accountName == '合计') { obj = { children: <span title={row.accountName}>{row.accountName}</span>, props: { colSpan: num } } } else { obj = { children: <span title={text}>{text}</span>, props: { colSpan: 1 } } } return obj } accountNameSpan = (text, row, index) => { let obj if (text == "合计") { obj = { props: { colSpan: 0, rowSpan: 1 } } } else { obj = { children: ( <a href="javascript:;" onClick={() => this.openMoreContent(row)}> <span title={text}>{text}</span> </a> ), props: { rowSpan: 1, colSpan: 1 } } } return obj } rowSpanExtend = (text, row, index) => { let obj if (row && row.accountName == '合计') { obj = { props: { colSpan: 0 } } } else { obj = { children: (<span title={text}>{text}</span>) } } return obj } rowShowTitle = (text, row, index) => { let obj = { children: (<span title={text}>{text}</span>) } return obj } tableColumns = () => { let arr const showOption = this.metaAction.gf('data.showOption').toJS() let pams = [this.accountCodeSpan, this.accountNameSpan, this.rowSpanExtend, this.rowShowTitle] if (!showOption.quantity && !showOption.currency) { this.injections.reduce('normalSearchChange', { path: 'colSpan', value: 2 }) arr = renderColumns('defalut', ...pams) } else if (showOption.quantity && !showOption.currency) { this.injections.reduce('normalSearchChange', { path: 'colSpan', value: 3 }) arr = renderColumns('quantity', ...pams) } else if (!showOption.quantity && showOption.currency) { this.injections.reduce('normalSearchChange', { path: 'colSpan', value: 3 }) arr = renderColumns('currency', ...pams) } else if (showOption.quantity && showOption.currency) { this.injections.reduce('normalSearchChange', { path: 'colSpan', value: 4 }) arr = renderColumns('quantityCurrency', ...pams) } return arr } onResize = (e) => { let keyRandomTab = Math.floor(Math.random() * 10000) this.keyRandomTab = keyRandomTab setTimeout(() => { if (keyRandomTab == this.keyRandomTab) { this.getTableScroll('app-balancesum-rpt-table-tbody', 'ant-table-thead', 0, '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) }, 200) 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) { } } //获取基础档案数据 calAuxBaseArchives = (data) => { const constant = ['supplierId', 'inventoryId', 'customerId', 'departmentId', 'projectId', 'personId', 'isExCalc1', 'isExCalc2', 'isExCalc3', 'isExCalc4', 'isExCalc5', 'isExCalc6', 'isExCalc7', 'isExCalc8', 'isExCalc9', 'isExCalc10'] let initAuxData = {} for (let [key, value] of Object.entries(data)) { const zidingyiArr = value if (constant.includes(key) && zidingyiArr && zidingyiArr != -1) { initAuxData[key] = `${zidingyiArr}` } } return initAuxData } openMoreContent = (row) => { const searchValue = this.metaAction.gf('data.searchValue').toJS() const showOption = this.metaAction.gf('data.showOption').toJS() if (!row) { return } if (row.isAuxCalcData) { const initAuxData = this.calAuxBaseArchives(row) //联查辅助明细账 this.component.props.setPortalContent && this.component.props.setPortalContent('辅助明细账', 'app-auxdetailaccount-rpt', { accessType: 1, linkInSearchValue: { accountCode: row.linkAccountCode, date_start: searchValue.date_start, date_end: searchValue.date_end, assitForm: initAuxData }}) } else { //联查明细账 this.component.props.setPortalContent && this.component.props.setPortalContent('明细账', 'app-detailaccount-rpt', { accessType: 1, initSearchValue: { accountCode: row.accountCode, currencyId: searchValue.currencyId, date_end: searchValue.date_end, date_start: searchValue.date_start, }, showOption: { num: showOption.quantity, currency: showOption.currency } }) } } } 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 }