UNPKG

ttk-app-core

Version:
590 lines (496 loc) 23.5 kB
import React from 'react' import { action as MetaAction, AppLoader } from 'edf-meta-engine' import { List, fromJS } from 'immutable' import { Menu, Checkbox, DataGrid, Icon } from 'edf-component' import renderGridColumns from './utils/renderGridColumns' 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 injections.reduce('init') this.load() let addEventListener = this.component.props.addEventListener if (addEventListener) { addEventListener('onTabFocus', ::this.onTabFocus) } } onTabFocus = async (data) => { let codeAndNameList = null let filter = this.metaAction.gf('data.filter').toJS() this.metaAction.sf('data.other.loading', true) let res = await this.webapi.assetClassRpt.init(filter) this.metaAction.sf('data.other.loading', false) this.injections.reduce('load', res) } load = () => { this.getInitOption() } getInitOption = async() => { this.metaAction.sf('data.other.loading', true) const date = await this.webapi.assetClassRpt.date() this.metaAction.sf('data.other.loading', false) let newObj = {} let contextDate = date.systemDate, currentOrg = this.metaAction.context.get("currentOrg") if(currentOrg.periodDate && moment(currentOrg.periodDate)<=moment(date.systemDate)){ contextDate = currentOrg.periodDate } newObj.startBuyData = utils.moment.stringToMoment(contextDate).endOf('month').format('YYYY-MM') newObj.endBuyData = utils.moment.stringToMoment(contextDate).endOf('month').format('YYYY-MM') this.metaAction.sf('data.other.loading', true) let res = await this.webapi.assetClassRpt.init(newObj) this.metaAction.sf('data.other.loading', false) if(res) { this.injections.reduce('initOption', res) } } refresh = async (asset) => { let filter = this.metaAction.gf('data.filter').toJS() const searchValue = this.metaAction.gf('data.searchValue').toJS() if(searchValue) filter.startBuyData = this.metaAction.momentToString(searchValue.date_start,'YYYY-MM') if(searchValue) filter.endBuyData = this.metaAction.momentToString(searchValue.date_end,'YYYY-MM') this.metaAction.sf('data.other.loading', true) let res = await this.webapi.assetClassRpt.query(filter) this.metaAction.sf('data.other.loading', false) if(res) { this.injections.reduce('load', res) } } exports = async() => { let filter = this.printAndExport(), list = this.metaAction.gf('data.list').toJS() if(!list.length){ this.metaAction.toast('warning', '当前暂无数据可导出') return } let res = await this.webapi.assetClassRpt.export(filter) this.metaAction.toast('导出成功', res) } print = async() => { const filter = this.printAndExport(), list = this.metaAction.gf('data.list').toJS() if(!list.length){ this.metaAction.toast('warning', '当前暂无数据可打印') return } let res = await this.webapi.assetClassRpt.print(filter) } printAndExport = () => { const filter = this.metaAction.gf('data.filter').toJS() let date_start = this.metaAction.gf('data.other.oldSearchValue.date_start') let date_end = this.metaAction.gf('data.other.oldSearchValue.date_end') let endDate = this.metaAction.gf('data.other.oldSearchValue.endDate') let startDate = this.metaAction.gf('data.other.oldSearchValue.startDate') if(date_start) filter.startBuyData = this.metaAction.momentToString(date_start,'YYYY-MM') if(startDate) filter.startUseData = this.metaAction.momentToString(startDate,'YYYY-MM-DD') if(date_end) filter.endBuyData = this.metaAction.momentToString(date_end,'YYYY-MM') if(endDate) filter.endUseData = this.metaAction.momentToString(endDate,'YYYY-MM-DD') const assetStatList = this.metaAction.gf('data.assetStatList').toJS() const columnDetails = [] assetStatList.forEach((item) => { if (item.isVisible) { columnDetails.push(item.fieldName) } }) filter.columnDetails = columnDetails return filter } //高级查询查询操作 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.date_start) option.startBuyData = this.metaAction.momentToString(value.date_start,'YYYY-MM') if(value.startDate) option.startUseData = this.metaAction.momentToString(value.startDate,'YYYY-MM-DD') if(value.date_end) option.endBuyData = this.metaAction.momentToString(value.date_end,'YYYY-MM') if(value.endDate) option.endUseData = this.metaAction.momentToString(value.endDate,'YYYY-MM-DD') if(value.hasDisposalAsset) option.containNoDepreciation = value.hasDisposalAsset.length ? true : false this.metaAction.sf('data.form.assetProperty', fromJS(assetProperty)) this.metaAction.sf('data.form.assetClass', fromJS(assetClass)) this.metaAction.sf('data.searchValue', fromJS(value)) this.metaAction.sf('data.searchValue.assetProperty', fromJS(assetProperty)) this.metaAction.sf('data.searchValue.assetClass', fromJS(assetClass)) this.getSearchAssetClass(assetProperty, assetClass, option) } } //资产属性切换 assetPropertyChange = async (path, option) => { this.metaAction.sf(path, fromJS(option)) let other = this.metaAction.gf('data.other').toJS(), assetClass = { label: '全部', value: 0, assetPropertyId: 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') { // 清空使用时间和勾选框 if(this.metaAction.gf('data.other.oldSearchValue').toJS().hasDisposalAsset) { this.metaAction.sf('data.searchValue.hasDisposalAsset', 0) } this.metaAction.sf('data.searchValue.startDate', null) this.metaAction.sf('data.searchValue.endDate', null) this.searchCard.clearValue() this.metaAction.sf(`data.searchValue.assetProperty`, fromJS(option)) this.metaAction.sf(`data.searchValue.assetClass`, fromJS(assetClass)) if(!option.value){ this.metaAction.sf(`data.searchValue.assetClass`, fromJS(option)) } this.getSearchAssetClass(option, assetClass) } } //资产分类切换 assetClassChange = async (path, option) => { this.metaAction.sf(path, fromJS(option)) let list = [], assetProperty = this.metaAction.gf('data.form.assetProperty').toJS() let name = path.split(".") if(name[1] == 'form') { // 清空使用时间和勾选框 if(this.metaAction.gf('data.other.oldSearchValue').toJS().hasDisposalAsset) { this.metaAction.sf('data.searchValue.hasDisposalAsset', 0) } this.metaAction.sf('data.searchValue.startDate', null) this.metaAction.sf('data.searchValue.endDate', null) 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 = { containNoDepreciation: 0 }, ids = '', date_start = this.metaAction.gf('data.searchValue.date_start'), date_end = this.metaAction.gf('data.searchValue.date_end'), endDate = this.metaAction.gf('data.searchValue.endDate'), startDate = this.metaAction.gf('data.searchValue.startDate') const other = this.metaAction.gf('data.other.oldSearchValue').toJS() // const searchValue = this.metaAction.gf('data.searchValue').toJS() if(option) filter = option if (other.hasDisposalAsset[0] == '1') { filter.containNoDepreciation = true } else { filter.containNoDepreciation = false } if(date_start) filter.startBuyData = this.metaAction.momentToString(date_start,'YYYY-MM') if(startDate) filter.startUseData = this.metaAction.momentToString(startDate,'YYYY-MM-DD') if(date_end) filter.endBuyData = this.metaAction.momentToString(date_end,'YYYY-MM') if(endDate) filter.endUseData = this.metaAction.momentToString(endDate,'YYYY-MM-DD') 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 } else{ ids = assetClass.value+'' } if(ids) { filter.assetClassIds = ids } if(!option){ if(filter.containNoDepreciation) delete filter.containNoDepreciation if(filter.startUseData) delete filter.startUseData if(filter.endUseData) delete filter.endUseData } this.metaAction.sf('data.other.loading', true) let res = await this.webapi.assetClassRpt.query(filter) this.metaAction.sf('data.other.loading', false) if(res) { this.metaAction.sf(`data.filter`, fromJS(filter)) this.injections.reduce('load', res) } } //高级查询取消操作 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() const { date_start, date_end } = this.metaAction.gf('data.other.oldSearchValue').toJS() const searchValue = this.metaAction.gf('data.searchValue').toJS() 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', fromJS({ ...searchValue, assetProperty, assetClass, date_start: date_start&&moment(date_start), date_end: date_end&&moment(date_end), })) } //高级查询清空操作 clearValueChange = (value) => { const date_start = this.metaAction.gf('data.searchValue.date_start') const date_end = this.metaAction.gf('data.searchValue.date_end') this.searchCard.clearValue() // 清空资产分类和属性 this.metaAction.sf('data.searchValue.assetProperty', fromJS({ label: '全部', value: 0})) this.metaAction.sf('data.searchValue.assetClass', fromJS({ label: '全部', value: 0})) this.metaAction.sf('data.other.assetClass', fromJS([{ label: '全部', value: 0}])) //清空时单选框也清空 if(this.metaAction.gf('data.other.oldSearchValue').toJS().hasDisposalAsset) { this.metaAction.sf('data.searchValue.hasDisposalAsset', 0) } this.metaAction.sf('data.searchValue.date_start', null) this.metaAction.sf('data.searchValue.date_end', null) this.metaAction.sf('data.searchValue.startDate', null) this.metaAction.sf('data.searchValue.endDate', null) } getSearchCard = (childrenRef) => { this.searchCard = childrenRef } /** * current 每个月份 * pointTime 指定比较的时间 * type 'pre' 前 'next' 后 * return 返回 true 代表禁用 */ disabledDate = (current, pointTime, type) => { if( !pointTime ){ return false } if (type == 'pre') { let currentMonth = this.transformDateToNum(current) let pointTimeMonth = this.transformDateToNum(pointTime) return false } else { let currentMonth = this.transformDateToNum(current) let pointTimeMonth = this.transformDateToNum(pointTime) return currentMonth < pointTimeMonth } } disabledDateDay = (current, pointTime, type) => { 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 } } //更改期间 onPanelChange = (value) => { let date = { date_end: value[1], date_start: value[0] } let filter = this.metaAction.gf('data.filter').toJS() // 清空使用时间和勾选框 if(this.metaAction.gf('data.other.oldSearchValue').toJS().hasDisposalAsset) { this.metaAction.sf('data.searchValue.hasDisposalAsset', 0) } this.metaAction.sf('data.searchValue.startDate', null) this.metaAction.sf('data.searchValue.endDate', null) const searchValue = this.metaAction.gf('data.searchValue').toJS() searchValue.assetClassIds= filter.assetClassIds if(date) filter.startBuyData = this.metaAction.momentToString(date.date_start,'YYYY-MM') if(date) filter.endBuyData = this.metaAction.momentToString(date.date_end,'YYYY-MM') //选完日期后高级查询取消时 this.metaAction.sf('data.other.oldSearchValue.date_start', date.date_start.format('YYYY-MM')) this.metaAction.sf('data.other.oldSearchValue.date_end',date.date_end.format('YYYY-MM')) this.metaAction.sf('data.filter', fromJS(filter)) this.injections.reduce('searchUpdate', {...searchValue, ...date }) this.sortParmas({...searchValue, ...date }) } sortParmas = (search) => { // 处理搜索参数 if (!search) { search = this.metaAction.gf('data.searchValue').toJS() } search.date_start = !!search.date_start && search.date_start.format('YYYY-MM') search.startDate = !!search.startDate ? search.startDate.format('YYYY-MM') : null search.date_end = !!search.date_end && search.date_end.format('YYYY-MM') search.endDate = !!search.endDate ? search.endDate.format('YYYY-MM') : null const newObj = {} newObj.startBuyData = search.date_start newObj.endBuyData = search.date_end // newObj.startUseData = search.startDate // newObj.endUseData = search.endDate newObj.assetPropertyIdList = search.assetProperty.value newObj.assetClassIds = search.assetClassIds ? search.assetClassIds : null // newObj.containNoDepreciation = search.hasDisposalAsset ? true : false; this.requestData({ ...newObj }) } // 请求列表中的数据 requestData = async (params) => { this.metaAction.sf('data.other.loading', true) const res = await this.webapi.assetClassRpt.query(params) this.metaAction.sf('data.other.loading', false) this.metaAction.sf(`data.filter`, fromJS(params)) this.injections.reduce('load', res) } transformDateToNum = (date) => { if( !date ){ return 0 } let time = date if (typeof date == 'string') { time = moment(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> ) } tableColumns = (assetStatList, list) => { let other = this.metaAction.gf('data.other').toJS() return renderGridColumns(assetStatList, list, other, this.showTableSetting, this.sortChange) } //表格拖宽 onColumnResizeEnd = async (newColumnWidth, columnKey) => { let columnDto = this.metaAction.gf('data.assetStatList').toJS(), other = this.metaAction.gf('data.other').toJS(), 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.assetClassRpt.batchUpdate(params) this.injections.reduce('onColumnResizeEnd', res) } //排序发生变化 sortChange = async (key, value) => { let params = { 'userOrderField': value == false ? null : key, 'order': value == false ? null : value }, filter = this.metaAction.gf(`data.filter`).toJS() this.injections.reduce('sortReduce', params) if(value){ filter.userOrderField = params.userOrderField filter.order = params.order this.metaAction.sf('data.other.loading', true) const res = await this.webapi.assetClassRpt.query(filter) this.metaAction.sf('data.other.loading', false) this.metaAction.sf(`data.filter`, fromJS(filter)) this.injections.reduce('load', res) } } showTableSetting = async ({ value, data }) => { /* * 更新栏目 */ 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.assetClassRpt.findByParam({ code: 'assetStatList' }) 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.assetClassRpt.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 = () => { this.injections.reduce('tableSettingVisible', { value: false }) } //栏目重置 resetTableSetting = async () => { this.injections.reduce('update',{ path: 'data.showTableSetting', value: false }) const other = this.metaAction.gf('data.other').toJS() //重置栏目 let res = await this.webapi.assetClassRpt.reInitByUser({code: other.code}) this.getInitOption() } combineColumnProp = (data) => { if (!data) return [] let newDataArray = [] data.forEach((ele, index) => { newDataArray.push({ "isVisible": ele.isVisible, "id": ele.id, 'ts': ele.ts }) }) return newDataArray } //获取时间选项 getNormalDateValue = () => { const data = this.metaAction.gf('data.searchValue').toJS() const arr = [] arr.push(data.date_start) arr.push(data.date_end) return arr } getListRowsCount = () => { return this.metaAction.gf('data.list').size } filterOptionSummary = (input, option) => { if (option && option.props && option.props.label) { return option.props.label.toLowerCase().indexOf(input.toLowerCase()) >= 0 } return true } } 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 }