perf: 老客户/推荐-销售业绩: 合并账户

feature/hotel-cruise
Lei OT 1 year ago
parent c2317d40a7
commit 9e3bb33043

@ -1,7 +1,7 @@
import {makeAutoObservable, runInAction} from "mobx"; import {makeAutoObservable, runInAction} from "mobx";
import { fetchJSON } from '../utils/request'; import { fetchJSON } from '../utils/request';
import * as config from "../config"; import * as config from "../config";
import { groupsMappedByKey, dataFieldAlias, sitesMappedByCode, pivotBy } from './../libs/ht'; import { groupsMappedByKey, sitesMappedByCode, pivotBy } from './../libs/ht';
/** /**
* 用于透视的数据 * 用于透视的数据
@ -258,6 +258,7 @@ class CustomerStore {
sales_regular_data = { sales_regular_data = {
loading: false, loading: false,
data: [], data: [],
mergedData: [],
rawData: [], rawData: [],
searchValues: { searchValues: {
DepartmentList: ['1', '2', '28', '7'].map(kk => groupsMappedByKey[kk]), DepartmentList: ['1', '2', '28', '7'].map(kk => groupsMappedByKey[kk]),
@ -269,12 +270,13 @@ class CustomerStore {
get_sales_regular_data = async (param) => { get_sales_regular_data = async (param) => {
this.sales_regular_data.loading = true; this.sales_regular_data.loading = true;
const rawData = await getDetailData({...param, IncludeTickets: 1}); const rawData = await getDetailData({...param, IncludeTickets: 1});
const filterHasOld = rawData.filter(ele => (ele.IsOld === '1' || ele.isCusCommend === '1')); const filterHasOld = rawData.filter(ele => (ele.IsOld === '1' || ele.isCusCommend === '1')).map(e => ({...e, operatorNameB: e.operatorName.replace(/\([^)]*\)/gi, '').toLowerCase()}));
const { data: hasOldData, columnValues, summaryRows, summaryColumns, pivotKeys, summaryMix } = pivotBy(filterHasOld, [['hasOld', 'operatorName'], [], []]);
const { data: hasOldData, } = pivotBy(filterHasOld, [['hasOld', 'operatorName'], [], []]);
const { data: IsOldData, } = pivotBy(filterHasOld.filter(ele => ele.IsOld === '1'), [['operatorName', 'IsOld_txt', ], [], []]); const { data: IsOldData, } = pivotBy(filterHasOld.filter(ele => ele.IsOld === '1'), [['operatorName', 'IsOld_txt', ], [], []]);
const { data: isCusCommendData, } = pivotBy(filterHasOld.filter(ele => ele.isCusCommend === '1'), [['operatorName', 'isCusCommend_txt', ], [], []]); const { data: isCusCommendData, } = pivotBy(filterHasOld.filter(ele => ele.isCusCommend === '1'), [['operatorName', 'isCusCommend_txt', ], [], []]);
// console.log('IsOldData====', IsOldData, '\nisCusCommend', isCusCommendData); // console.log('IsOldData====', IsOldData, '\nisCusCommend', isCusCommendData);
// console.log('data====', data, '\ncolumnValues', columnValues, '\nsummaryRows', summaryRows, '\nsummaryColumns', summaryColumns, '\nsummaryMix', summaryMix, '\nhasOld',filterHasOld); // console.log('data====', rawData, '\ncolumnValues', columnValues, '\nsummaryRows', summaryRows, '\nsummaryColumns', summaryColumns, '\nsummaryMix', summaryMix, '\nhasOld',filterHasOld);
const mergeDataBySales = hasOldData.map((ele) => ({ const mergeDataBySales = hasOldData.map((ele) => ({
...ele, ...ele,
children: [].concat( children: [].concat(
@ -282,9 +284,25 @@ class CustomerStore {
isCusCommendData.filter((ele2) => ele2.operatorName === ele.operatorName).map(o => ({...o, operatorName: o.isCusCommend_txt, key: o.rowLabel})) isCusCommendData.filter((ele2) => ele2.operatorName === ele.operatorName).map(o => ({...o, operatorName: o.isCusCommend_txt, key: o.rowLabel}))
), ),
})); }));
// console.log('merge', mergeDataBySales);
// 合并顾问的账户
const { data: hasOldDataSales, } = pivotBy(filterHasOld, [['hasOld', 'operatorNameB'], [], []]);
const { data: IsOldDataSales, } = pivotBy(filterHasOld.filter(ele => ele.IsOld === '1'), [['operatorNameB', 'IsOld_txt', ], [], []]);
const { data: isCusCommendDataSales, } = pivotBy(filterHasOld.filter(ele => ele.isCusCommend === '1'), [['operatorNameB', 'isCusCommend_txt', ], [], []]);
const mergeDataBySalesAccount = hasOldDataSales.map((ele) => ({
...ele,
operatorName: ele.operatorNameB,
children: [].concat(
IsOldDataSales.filter((ele1) => ele1.operatorNameB === ele.operatorNameB).map(o => ({...o, operatorName: o.IsOld_txt, key: o.rowLabel})),
isCusCommendDataSales.filter((ele2) => ele2.operatorNameB === ele.operatorNameB).map(o => ({...o, operatorName: o.isCusCommend_txt, key: o.rowLabel}))
),
}));
// console.log('IsOldDataSales====', IsOldDataSales, '\nisCusCommendDataSales', isCusCommendDataSales);
// console.log('mergeDataBySalesAccount====', mergeDataBySalesAccount);
this.sales_regular_data.loading = false; this.sales_regular_data.loading = false;
this.sales_regular_data.data = mergeDataBySales; this.sales_regular_data.data = mergeDataBySales;
this.sales_regular_data.mergedData = mergeDataBySalesAccount;
this.sales_regular_data.rawData = filterHasOld; this.sales_regular_data.rawData = filterHasOld;
}; };

@ -1,10 +1,10 @@
import { createContext, useContext, useEffect, useState } from 'react'; import { createContext, useContext, useEffect, useState } from 'react';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { stores_Context } from '../config'; import { stores_Context } from '../config';
import { Table, Row, Col, Divider, Button } from 'antd'; import { Table, Row, Col, Divider, Button, Switch } from 'antd';
import SearchForm from '../components/search/SearchForm'; import SearchForm from '../components/search/SearchForm';
import { TableExportBtn } from './../components/Data'; import { TableExportBtn } from './../components/Data';
import { uniqWith } from './../utils/commons'; import { uniqWith, groupBy } from './../utils/commons';
// TdCellDataTable // TdCellDataTable
const TdCell = (tdprops) => { const TdCell = (tdprops) => {
@ -14,22 +14,45 @@ const TdCell = (tdprops) => {
}; };
const SalesCustomerCareRegular = (props) => { const SalesCustomerCareRegular = (props) => {
const { orders_store, date_picker_store: searchFormStore, customer_store } = useContext(stores_Context); const { date_picker_store: searchFormStore, customer_store } = useContext(stores_Context);
const { formValues, formValuesToSub, siderBroken } = searchFormStore; const { formValues, formValuesToSub, siderBroken } = searchFormStore;
const { sales_regular_data: pageData } = customer_store; const { sales_regular_data: pageData } = customer_store;
const [expandRowKeys, setExpandRowKeys] = useState([]);
const [dataForExport, setDataForExport] = useState([]); const [dataForExport, setDataForExport] = useState([]);
useEffect(() => {
setExpandRowKeys(pageData.data.map((ele) => ele.key));
setDataForExport(pageData.data.reduce((r, c) => r.concat([{...c, children: undefined}], c.children.map(ele => ({...ele, operatorName: ele.rowLabel}))), []));
return () => {};
}, [pageData.data]);
const allOPI1 = uniqWith( const allOPI1 = uniqWith(
pageData.data.map((rr) => ({ text: rr.operatorName, value: rr.operatorName })), pageData.data.map((rr) => ({ text: rr.operatorName, value: rr.operatorName })),
(a, b) => JSON.stringify(a) === JSON.stringify(b) (a, b) => JSON.stringify(a) === JSON.stringify(b)
).sort((a, b) => a.text.localeCompare(b.text)); ).sort((a, b) => a.text.localeCompare(b.text));
const [OPIFilters, setOPIFilters] = useState([]);
const [dataSource, setDataSource] = useState([]);
const [ifmerge, setIfmerge] = useState(false);
useEffect(() => {
if ( ! ifmerge) {
// const allOPI1 = uniqWith(
// pageData.data.map((rr) => ({ text: rr.operatorName, value: rr.operatorName })),
// (a, b) => JSON.stringify(a) === JSON.stringify(b)
// ).sort((a, b) => a.text.localeCompare(b.text));
// setOPIFilters(allOPI1);
setDataSource(pageData.data);
setDataForExport(pageData.data.reduce((r, c) => r.concat([{...c, children: undefined}], c.children.map(ele => ({...ele, operatorName: ele.rowLabel}))), []));
} else {
// const allOPI1 = uniqWith(
// pageData.mergedData.map((rr) => ({ text: rr.operatorName, value: rr.operatorName })),
// (a, b) => JSON.stringify(a) === JSON.stringify(b)
// ).sort((a, b) => a.text.localeCompare(b.text));
// setOPIFilters(allOPI1);
setDataSource(pageData.mergedData);
setDataForExport(pageData.mergedData.reduce((r, c) => r.concat([{...c, children: undefined}], c.children.map(ele => ({...ele, operatorName: ele.rowLabel}))), []));
}
return () => {
};
}, [ifmerge, pageData.data]);
const rowColumns = [ const rowColumns = [
{ title: '顾问', dataIndex: 'operatorName', key: 'operatorName' }, { title: '顾问', dataIndex: 'operatorName', key: 'operatorName' },
{ title: '订单号', dataIndex: 'o_id', key: 'o_id' }, { title: '订单号', dataIndex: 'o_id', key: 'o_id' },
@ -48,7 +71,7 @@ const SalesCustomerCareRegular = (props) => {
{ title: '页面类型', dataIndex: 'COLI_LineClass', key: 'COLI_LineClass' }, { title: '页面类型', dataIndex: 'COLI_LineClass', key: 'COLI_LineClass' },
]; ];
const columns = [ const columns = [
{ key: 'operatorName', title: '顾问', dataIndex: 'operatorName', width: '6em', filters: allOPI1, onFilter: (value, record) => record.operatorName === value, filterSearch: true }, { key: 'operatorName', title: '顾问', dataIndex: 'operatorName', width: '6em', filters: allOPI1, onFilter: (value, record) => value.includes(record.operatorName), filterSearch: true },
{ key: 'SumOrder', title: '订单数', dataIndex: 'SumOrder', width: '5em' }, { key: 'SumOrder', title: '订单数', dataIndex: 'SumOrder', width: '5em' },
{ key: 'ConfirmOrder', title: '成交数', dataIndex: 'ConfirmOrder', width: '5em' }, { key: 'ConfirmOrder', title: '成交数', dataIndex: 'ConfirmOrder', width: '5em' },
{ key: 'ConfirmPersonNum', title: '✔人数(SUM)', dataIndex: 'ConfirmPersonNum', width: '5em' }, { key: 'ConfirmPersonNum', title: '✔人数(SUM)', dataIndex: 'ConfirmPersonNum', width: '5em' },
@ -58,7 +81,7 @@ const SalesCustomerCareRegular = (props) => {
{ key: 'SingleML', title: '单团毛利', dataIndex: 'SingleML', width: '5em' }, { key: 'SingleML', title: '单团毛利', dataIndex: 'SingleML', width: '5em' },
{ key: 'action', title: '', width: '5em', render: (_, r) => { { key: 'action', title: '', width: '5em', render: (_, r) => {
const rowChildren = pageData.rawData.filter(ele => ele.operatorName === r.operatorName); const rowChildren = pageData.rawData.filter(ele => ele.operatorName === r.operatorName);
return r.hasOld ? <TableExportBtn btnTxt='导出' label={`老客户-${r.operatorName}`} {...{ columns: rowColumns, dataSource: rowChildren }} /> : null; return r.hasOld ? <TableExportBtn btnTxt='明细' label={`老客户明细-${r.operatorName}`} {...{ columns: rowColumns, dataSource: rowChildren }} /> : null;
} }, } },
]; ];
return ( return (
@ -89,18 +112,30 @@ const SalesCustomerCareRegular = (props) => {
</Row> </Row>
<h2>销售-老客户, 含推荐</h2> <h2>销售-老客户, 含推荐</h2>
<Divider orientation="right" plain> <Divider orientation="right" plain>
{pageData.data.length > 0 && (
<Switch
unCheckedChildren="各账户"
checkedChildren="合并"
key={'openOrMerge'}
checked={ifmerge}
onChange={(e) => {
setIfmerge(e);
}}
/>
)}
<Divider type={'vertical'} />
<TableExportBtn btnTxt='导出明细' label={`${formValuesToSub.Date1}-销售.老客户-明细`} {...{ columns: rowColumns, dataSource: pageData.rawData }} /> <TableExportBtn btnTxt='导出明细' label={`${formValuesToSub.Date1}-销售.老客户-明细`} {...{ columns: rowColumns, dataSource: pageData.rawData }} />
<Divider type={'vertical'} /> <Divider type={'vertical'} />
<TableExportBtn btnTxt='导出下表' label={`${formValuesToSub.Date1}-销售.老客户`} {...{ columns, dataSource: dataForExport }} /> <TableExportBtn btnTxt='导出下表' label={`${formValuesToSub.Date1}-销售.老客户`} {...{ columns, dataSource: dataForExport }} />
</Divider> </Divider>
<Table <Table
sticky sticky
dataSource={pageData.data} dataSource={dataSource}
loading={pageData.loading} loading={pageData.loading}
columns={columns} columns={columns}
pagination={false} pagination={false}
defaultExpandAllRows // defaultExpandAllRows
expandable={{ defaultExpandAllRows: true, defaultExpandedRowKeys: pageData.data.map((ele) => ele.key) }} // expandable={{ defaultExpandAllRows: true, expandedRowKeys: pageData.data.map((ele) => ele.key), }}
/> />
</> </>
); );

Loading…
Cancel
Save