diff --git a/src/stores/FinancialStore.js b/src/stores/FinancialStore.js index 6ab2b63..1e61886 100644 --- a/src/stores/FinancialStore.js +++ b/src/stores/FinancialStore.js @@ -143,10 +143,10 @@ class FinancialStore { 'domestic': { url: '/service-Analyse2/domestic_person_num', keySort: true, dynamicsX: false }, }; - servicePersonNum = { curTab: 'inbound', - 'inbound': { loading: false, dataSource: [], total: {} }, - 'outbound': { loading: false, dataSource: [], total: {} }, - 'domestic': { loading: false, dataSource: [], total: {} }, + servicePersonNum = { curTab: 'inbound', loading: false, + 'inbound': { loading: false, dataSource: [], rawData: [], NoEmptyData: [], }, + 'outbound': { loading: false, dataSource: [], rawData: [], NoEmptyData: [], }, + 'domestic': { loading: false, dataSource: [], rawData: [], NoEmptyData: [], }, }; setCurTab(v) { @@ -154,9 +154,47 @@ class FinancialStore { } resetPersonNumData = () => { - this.servicePersonNum.inbound = { loading: false, dataSource: [], total: {} }; - this.servicePersonNum.outbound = { loading: false, dataSource: [], total: {} }; - this.servicePersonNum.domestic = { loading: false, dataSource: [], total: {} }; + this.servicePersonNum.inbound = { loading: false, dataSource: [], rawData: [], NoEmptyData: [], }; + this.servicePersonNum.outbound = { loading: false, dataSource: [], rawData: [], NoEmptyData: [], }; + this.servicePersonNum.domestic = { loading: false, dataSource: [], rawData: [], NoEmptyData: [], }; + }; + + setPersonNumTableDataSource = (notnull) => { + const mkey = this.servicePersonNum.curTab; + if (comm.isEmpty(this.servicePersonNum[mkey].dataSource)) { + return false; + } + this.servicePersonNum[mkey].dataSource = (notnull === false ? this.servicePersonNum[mkey].rawData : this.servicePersonNum[mkey].NoEmptyData); + }; + + handleRows = (json) => { + const mkey = this.servicePersonNum.curTab; + const sumFun = (_data, key='sum') => ['orgz', 'orgzPDays', 'hosts', 'hostsPDays'].reduce((r, skey) => ({ ...r, [skey]: _data.reduce((a, c) => a + (c[skey] || 0), 0) }), { + groupsKey: key, // `sumResult`, + groupsLabel: '合计', + }); + const percentRow = (row, sumResult) => { + return ['orgz', 'orgzPDays', 'hosts', 'hostsPDays'].reduce((r, skey) => ({ ...r, [`${skey}Percent`]: sumResult[skey] ? comm.fixTo4Decimals(row[skey] / sumResult[skey]) : 0 }), row); + }; + + const sumResult = sumFun(json.result, 'sumResult'); + const emptyRows = json.result.filter(ele => ele.groupsLabel === '' || ele.groupsLabel === '未知'); + const sumEmptyResult = sumFun(emptyRows, 'sumEmptyResult'); + const NotEmptyRows = json.result.filter(ele => ele.groupsLabel !== '' && ele.groupsLabel !== '未知'); + const sumNotEmptyRows = sumFun(NotEmptyRows, 'sumNotEmptyRows'); + + const result = NotEmptyRows.map((row) => ({...row, ...percentRow(row, sumNotEmptyRows)})).map((row) => { + const newData = ['orgz', 'orgzPDays', 'hosts', 'hostsPDays'].reduce( + (r, skey) => ({ ...r, [skey]: row[`${skey}Percent`] ? row[skey] + comm.fixToInt(sumEmptyResult[skey] * row[`${skey}Percent`]) : row[skey] }), + row + ); + return newData; + }); + + const totalRow = Object.keys(json.resultTotal).length > 1 ? { ...json.resultTotal, groupsKey: `total${mkey}` } : (mkey === 'domestic' ? sumResult : { groupsKey: 'empty'}); + const IndividualServiceRow = {orgz: json.resultTotal.IndividualService, groupsKey: `individualService${mkey}`, groupsLabel: '单项服务人数', }; + + return { sumResult, result, rawData: [].concat([IndividualServiceRow, totalRow], json.result), NoEmptyData: [].concat([IndividualServiceRow, totalRow], result) }; }; /** @@ -166,21 +204,19 @@ class FinancialStore { const mkey = this.servicePersonNum.curTab; const url = this.serviceModelMapper[mkey].url; + this.servicePersonNum.loading = true; this.servicePersonNum[this.servicePersonNum.curTab].loading = true; const json = await fetchJSON(url, {...queryData, DateType: 'startDate'}); - const sumResult = ['orgz', 'orgzPDays', 'hosts', 'hostsPDays'].reduce((r, skey) => ({ ...r, [skey]: json.result.reduce((a, c) => a + (c[skey] || 0), 0) }), { - groupsKey: `sumResult`, - groupsLabel: '合计', - }); + const { rawData, NoEmptyData } = this.handleRows(json); - const totalRow = Object.keys(json.resultTotal).length > 1 ? { ...json.resultTotal, groupsKey: `total${mkey}` } : (mkey === 'domestic' ? sumResult : { groupsKey: 'empty'}); - const IndividualServiceRow = {orgz: json.resultTotal.IndividualService, groupsKey: `individualService${mkey}`, groupsLabel: '单项服务人数', }; if (json.errcode === 0) { runInAction(() => { + this.servicePersonNum.loading = false; this.servicePersonNum[this.servicePersonNum.curTab].loading = false; - this.servicePersonNum[this.servicePersonNum.curTab].dataSource = [].concat([IndividualServiceRow, totalRow], json.result); - this.servicePersonNum[this.servicePersonNum.curTab].total = json.resultTotal; + this.servicePersonNum[this.servicePersonNum.curTab].dataSource = rawData; + this.servicePersonNum[this.servicePersonNum.curTab].rawData = rawData; + this.servicePersonNum[this.servicePersonNum.curTab].NoEmptyData = NoEmptyData; }); } return json; diff --git a/src/views/ServicePersonNum.jsx b/src/views/ServicePersonNum.jsx index 964cc07..2597b6d 100644 --- a/src/views/ServicePersonNum.jsx +++ b/src/views/ServicePersonNum.jsx @@ -1,7 +1,7 @@ -import { useContext, useEffect } from 'react'; +import { useContext, useEffect, useState } from 'react'; import { observer } from 'mobx-react'; import { stores_Context } from '../config'; -import { Spin, Table, Row, Col, Tabs } from 'antd'; +import { Spin, Table, Row, Col, Tabs, Switch } from 'antd'; import SearchForm from './../components/search/SearchForm'; import { TableExportBtn } from './../components/Data'; import { empty } from '../utils/commons'; @@ -19,6 +19,7 @@ export default observer((props) => { const { formValues, formValuesToSub } = searchFormStore; const { servicePersonNum } = financialStore; const { curTab } = servicePersonNum; + const [ifNull, setIfNull] = useState(false); useEffect(() => { // DistributionStore.setFormDates(formValuesToSub); @@ -29,8 +30,12 @@ export default observer((props) => { const pageRefresh = (queryData = formValuesToSub) => { // console.log(queryData, 'qqqq'); financialStore.getPersonNum(queryData); + + financialStore.setPersonNumTableDataSource(false); + setIfNull(false); }; + const columns = [ { title: apartOptionsMapped[curTab].label, dataIndex: 'groupsLabel', children: [{ title: `${formValuesToSub.Date1}~${formValuesToSub.Date2.substring(0, 10)}`, dataIndex: 'groupsLabel' }] }, { @@ -75,14 +80,28 @@ export default observer((props) => { } }} tabBarExtraContent={{ - right: , + right: ( + <> + { + financialStore.setPersonNumTableDataSource(e); + setIfNull(e); + }} + /> + + + ), }} type="card" items={apartOptions.map((ele) => { return { ...ele, children: ( - +