UNPKG

ttk-app-core

Version:
181 lines (154 loc) 7.48 kB
import { Map, fromJS, toJS } from 'immutable' import { reducer as MetaReducer } from 'edf-meta-engine' import config from './config' import { getInitState } from './data' import moment from 'moment' import utils from 'edf-utils' class reducer { constructor(option) { this.metaReducer = option.metaReducer this.config = config.current } init = (state, option) => { const initState = getInitState() return this.metaReducer.init(state, initState) } showOptionsChange = (state, {path, value}) => { return this.metaReducer.sf(state, path, value) } update = (state, { path, value }) => { return this.metaReducer.sf(state, path, fromJS(value)) } settingOptionsUpdate = (state, {visible, data}) => { state = this.metaReducer.sf(state, 'data.assetDetailList', fromJS(data)) state = this.metaReducer.sf(state, 'data.showTableSetting', visible) state = this.getColumnDetails(state, data) return state } newAssetDetailList = (state, res) => { state = this.metaReducer.sf(state, 'data.list', fromJS(res.assetList)) return state } getColumnDetails = (state, columnDetails) => { let newColumn = {} columnDetails.map((item,index) => { newColumn[item.fieldName] = item.isVisible }) state = this.metaReducer.sf(state, 'data.columnsNameObj', fromJS(newColumn)) return state } tableSettingVisible = (state, { value, data }) => { state = this.metaReducer.sf(state, 'data.showTableSetting', value) data = this.metaReducer.gf(state, 'data.assetDetailList') return state } load = (state, value) => { state = this.metaReducer.sf(state, 'data.list', fromJS(value.assetList)) state = this.metaReducer.sf(state, 'data.pagination', fromJS(value.page)) if (value.codeAndNameList) { state = this.metaReducer.sf(state, 'data.other.codeAndNameList', fromJS(value.codeAndNameList)) } if(value.assetDetailList) { value.assetDetailList.forEach((item) => { if (item.fieldName == 'depreciationStr') { if(value.ifMonthDepreciation) { item.isMustSelect = !value.ifMonthDepreciation } else { item.isMustSelect = !value.ifMonthDepreciation item.isVisible = value.ifMonthDepreciation } } }) state = this.metaReducer.sf(state, 'data.assetDetailList', fromJS(value.assetDetailList)) } //state = this.metaReducer.sf(state, 'data.filter', fromJS(response.filter)) return state } // normalSearchChange = (state, { path, value }) => { // return this.metaReducer.sf(state, path, fromJS(value)) // } searchUpdate = (state, value) => { return this.metaReducer.sf(state, 'data.searchValue', fromJS(value)) } initOption = (state, { assetList, systemDate, codeAndNameList, assetProperty, assetClass, pagination,assetDetailList,ts,ifMonthDepreciation,code }) => { state = this.metaReducer.sf(state, 'data.list', fromJS(assetList)) state = this.metaReducer.sf(state, 'data.other.codeAndNameList', fromJS(codeAndNameList)) state = this.metaReducer.sf(state, 'data.pagination', fromJS(pagination)) state = this.metaReducer.sf(state, 'data.systemDate', fromJS(systemDate)) let contextDate = systemDate, currentOrg = this.metaReducer.context.get("currentOrg") if(currentOrg.periodDate && moment(currentOrg.periodDate)<=moment(systemDate)){ contextDate = currentOrg.periodDate } state = this.metaReducer.sf(state, 'data.filter.startBuyData', fromJS(utils.moment.stringToMoment(contextDate)).endOf('month').format('YYYY-MM')) state = this.metaReducer.sf(state, 'data.filter.endBuyData', fromJS(utils.moment.stringToMoment(contextDate)).endOf('month').format('YYYY-MM')) state = this.metaReducer.sf(state, 'data.searchValue.startBuyData', fromJS(utils.moment.stringToMoment(contextDate)).endOf('month')) state = this.metaReducer.sf(state, 'data.searchValue.endBuyData', fromJS(utils.moment.stringToMoment(contextDate)).endOf('month')) assetDetailList.forEach((item) => { if (item.fieldName == 'depreciationStr') { if(ifMonthDepreciation) { item.isMustSelect = !ifMonthDepreciation } else { item.isMustSelect = !ifMonthDepreciation item.isVisible = ifMonthDepreciation } } }) state = this.metaReducer.sf(state, 'data.assetDetailList', fromJS(assetDetailList)) state = this.metaReducer.sf(state, 'data.other.code', fromJS(code)) const columsObj={} assetDetailList.map((item) => { columsObj[item.fieldName] = item.isVisible // if (item.fieldName == 'depreciationFunctionName') { // console.log(ifMonthDepreciation, 'ifMonthDepreciation') // // if (ifMonthDepreciation) { // columsObj[item.fieldName] = ifMonthDepreciation // // } // } }) state = this.metaReducer.sf(state, 'data.columnsNameObj', fromJS(columsObj)) let assetClassAll = this.getLabelList(assetClass) let all = { label: '全部', value: 0 } assetProperty.unshift(all) state = this.metaReducer.sf(state, `data.other.assetProperty`, fromJS(assetProperty)) state = this.metaReducer.sf(state, `data.other.assetClass`, fromJS([all])) state = this.metaReducer.sf(state, `data.other.assetClassAll`, fromJS(assetClassAll)) state = this.metaReducer.sf(state, `data.form.assetProperty`, fromJS(all)) state = this.metaReducer.sf(state, `data.searchValue.assetProperty`, fromJS(all)) state = this.metaReducer.sf(state, `data.form.assetClass`, fromJS(all)) state = this.metaReducer.sf(state, `data.searchValue.assetClass`, fromJS(all)) state = this.metaReducer.sf(state, `data.other.ts`, ts) return state } getLabelList = (list) => { let newList = [] if (list && Array.isArray(list)) { list.map(item => { //资产分类 newList.push({ value: item.id, label: item.name, assetPropertyId: item.assetPropertyId }) }) } return newList } tableOnchange = (state, value) => { state = this.metaReducer.sf(state, 'data.list', fromJS(value.assetList)) state = this.metaReducer.sf(state, 'data.pagination', fromJS(value.page)) //state = this.metaReducer.sf(state, 'data.filter', fromJS(response.filter)) return state } onColumnResizeEnd = (state, res) => { if(res[0]){ state = this.metaReducer.sf(state, 'data.assetDetailList', fromJS(res[0].columnDetails)) } return state } sortReduce = (state, value) => { state = this.metaReducer.sf(state, `data.other.sort`, fromJS(value)) return state } } export default function creator(option) { const metaReducer = new MetaReducer(option), o = new reducer({...option, metaReducer }) return {...metaReducer, ...o } }