From d80ecf398b3ef83151f8a68517bf70d52172ae34 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Mon, 18 Dec 2023 11:49:36 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=96=87=E6=97=85=E5=B1=80=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E4=BA=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/FinancialStore.js | 16 ++++++++++++++-- src/views/Distribution.jsx | 9 +++------ src/views/ServicePersonNum.jsx | 26 +++++++++++++++----------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/stores/FinancialStore.js b/src/stores/FinancialStore.js index b6bc94e..6ab2b63 100644 --- a/src/stores/FinancialStore.js +++ b/src/stores/FinancialStore.js @@ -153,6 +153,12 @@ class FinancialStore { this.servicePersonNum.curTab = v; } + resetPersonNumData = () => { + this.servicePersonNum.inbound = { loading: false, dataSource: [], total: {} }; + this.servicePersonNum.outbound = { loading: false, dataSource: [], total: {} }; + this.servicePersonNum.domestic = { loading: false, dataSource: [], total: {} }; + }; + /** * 获取服务人数 */ @@ -161,8 +167,14 @@ class FinancialStore { const url = this.serviceModelMapper[mkey].url; this.servicePersonNum[this.servicePersonNum.curTab].loading = true; - const json = await fetchJSON(url, {...queryData, DateType: 'confirmDate'}); - const totalRow = {...json.resultTotal, groupsKey: `total${mkey}`}; + 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 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(() => { diff --git a/src/views/Distribution.jsx b/src/views/Distribution.jsx index c6e3add..4494e80 100644 --- a/src/views/Distribution.jsx +++ b/src/views/Distribution.jsx @@ -43,12 +43,6 @@ export default observer(() => { }); }; - useEffect(() => { - if (empty(DistributionStore[curTab].dataSource)) { - pageRefresh(); - } - }, [curTab]); - useEffect(() => { DistributionStore.setFormDates(formValuesToSub); DistributionStore.resetData(); @@ -57,6 +51,9 @@ export default observer(() => { const onTabsChange = (tab) => { DistributionStore.setCurTab(tab); + if (empty(DistributionStore[tab].dataSource)) { + pageRefresh(); + } }; const RingProgressConfig = { height: 60, diff --git a/src/views/ServicePersonNum.jsx b/src/views/ServicePersonNum.jsx index 4664229..964cc07 100644 --- a/src/views/ServicePersonNum.jsx +++ b/src/views/ServicePersonNum.jsx @@ -1,9 +1,10 @@ -import { useContext } from 'react'; +import { useContext, useEffect } from 'react'; import { observer } from 'mobx-react'; import { stores_Context } from '../config'; import { Spin, Table, Row, Col, Tabs } from 'antd'; import SearchForm from './../components/search/SearchForm'; import { TableExportBtn } from './../components/Data'; +import { empty } from '../utils/commons'; import './kpi.css'; const apartOptions = [ @@ -11,6 +12,7 @@ const apartOptions = [ { key: 'outbound', value: 'outbound', label: '出境' }, { key: 'domestic', value: 'domestic', label: '国内' }, ]; +const apartOptionsMapped = apartOptions.reduce((r, v) => ({...r, [v.value]: v}), {}); export default observer((props) => { const { financial_store: financialStore, date_picker_store: searchFormStore } = useContext(stores_Context); @@ -18,26 +20,26 @@ export default observer((props) => { const { servicePersonNum } = financialStore; const { curTab } = servicePersonNum; + useEffect(() => { + // DistributionStore.setFormDates(formValuesToSub); + financialStore.resetPersonNumData(); + return () => {}; + }, [formValuesToSub]); + const pageRefresh = (queryData = formValuesToSub) => { // console.log(queryData, 'qqqq'); financialStore.getPersonNum(queryData); }; const columns = [ - { title: '名称', dataIndex: 'groupsLabel' }, + { title: apartOptionsMapped[curTab].label, dataIndex: 'groupsLabel', children: [{ title: `${formValuesToSub.Date1}~${formValuesToSub.Date2.substring(0, 10)}`, dataIndex: 'groupsLabel' }] }, { title: '人次数', - children: [ - { title: '外联', dataIndex: 'orgz' }, - { title: '接待', dataIndex: 'hosts' }, - ], + children: [{ title: '组织', dataIndex: 'orgz' }, ...(['inbound', 'domestic'].includes(curTab) ? [{ title: '接待', dataIndex: 'hosts' }] : [])], }, { title: '人天', - children: [ - { title: '外联', dataIndex: 'orgzPDays' }, - { title: '接待', dataIndex: 'hostsPDays' }, - ], + children: [{ title: '组织', dataIndex: 'orgzPDays' }, ...(['inbound', 'domestic'].includes(curTab) ? [{ title: '接待', dataIndex: 'hostsPDays' }] : [])], }, ]; @@ -68,7 +70,9 @@ export default observer((props) => { activeKey={curTab} onChange={(v) => { financialStore.setCurTab(v); - pageRefresh(); + if (empty(servicePersonNum[v].dataSource)) { + pageRefresh(); + } }} tabBarExtraContent={{ right: ,