Compare commits

...

3 Commits

4
package-lock.json generated

@ -1,12 +1,12 @@
{ {
"name": "haina-dashboard", "name": "haina-dashboard",
"version": "2.11.11", "version": "2.11.12",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "haina-dashboard", "name": "haina-dashboard",
"version": "2.11.11", "version": "2.11.12",
"dependencies": { "dependencies": {
"@ant-design/charts": "^1.4.2", "@ant-design/charts": "^1.4.2",
"@ant-design/pro-components": "^2.6.16", "@ant-design/pro-components": "^2.6.16",

@ -1,6 +1,6 @@
{ {
"name": "haina-dashboard", "name": "haina-dashboard",
"version": "2.11.11", "version": "2.11.12",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@ant-design/charts": "^1.4.2", "@ant-design/charts": "^1.4.2",

@ -27,6 +27,7 @@ import ProtectedRoute from './views/ProtectedRoute';
import Customer_care_inchina from './charts/Customer_care_inchina'; import Customer_care_inchina from './charts/Customer_care_inchina';
import Customer_care_potential from './charts/Customer_care_potential'; import Customer_care_potential from './charts/Customer_care_potential';
import Customer_care_regular from './charts/Customer_care_regular'; import Customer_care_regular from './charts/Customer_care_regular';
import Customer_care_regular_pivot from './charts/Customer_care_regular_pivot';
import Wechat_session from './charts/Wechat_session'; import Wechat_session from './charts/Wechat_session';
import WhatsApp_session from './charts/WhatsApp_session'; import WhatsApp_session from './charts/WhatsApp_session';
import AgentGroupCount from './views/AgentGroupCount'; import AgentGroupCount from './views/AgentGroupCount';
@ -48,7 +49,6 @@ import DataPivot from './views/DataPivot';
import Welcome from './views/Welcome'; import Welcome from './views/Welcome';
import Meeting2024GH from './views/Meeting2024-GH'; import Meeting2024GH from './views/Meeting2024-GH';
import Meeting2025GH from './views/Meeting2025-GH'; import Meeting2025GH from './views/Meeting2025-GH';
import SalesCustomerCareRegular from './views/SalesCustomerCareRegular';
import { stores_Context, APP_VERSION } from './config'; import { stores_Context, APP_VERSION } from './config';
import { WaterMark } from '@ant-design/pro-components'; import { WaterMark } from '@ant-design/pro-components';
import CooperationIcon from './components/icons/CooperationIcon'; import CooperationIcon from './components/icons/CooperationIcon';
@ -128,7 +128,7 @@ const App = () => {
key: 32, key: 32,
label: <NavLink to="/customer_care_regular">老客户</NavLink>, label: <NavLink to="/customer_care_regular">老客户</NavLink>,
}, },
{ key: 'customer_care_regular_sales', label: <NavLink to="/customer_care_regular_sales">老客户-分析</NavLink> }, { key: 'customer_care_regular_pivot', label: <NavLink to="/customer_care_regular_pivot">老客户-分析</NavLink> },
{ {
key: 33, key: 33,
label: <NavLink to="/customer_care_inchina">在华客户</NavLink>, label: <NavLink to="/customer_care_inchina">在华客户</NavLink>,
@ -257,7 +257,7 @@ const App = () => {
<Route element={<ProtectedRoute auth={['admin', 'director_bu', 'customer_care']} />}> <Route element={<ProtectedRoute auth={['admin', 'director_bu', 'customer_care']} />}>
<Route path="/customer_care_inchina" element={<Customer_care_inchina />} /> <Route path="/customer_care_inchina" element={<Customer_care_inchina />} />
<Route path="/customer_care_regular" element={<Customer_care_regular />} /> <Route path="/customer_care_regular" element={<Customer_care_regular />} />
<Route path="/customer_care_regular_sales" element={<SalesCustomerCareRegular />} /> <Route path="/customer_care_regular_pivot" element={<Customer_care_regular_pivot />} />
<Route path="/customer_care_potential" element={<Customer_care_potential />} /> <Route path="/customer_care_potential" element={<Customer_care_potential />} />
<Route path="/whatsapp_session" element={<WhatsApp_session />} /> <Route path="/whatsapp_session" element={<WhatsApp_session />} />
<Route path="/wechat_session" element={<Wechat_session />} /> <Route path="/wechat_session" element={<Wechat_session />} />

@ -117,9 +117,6 @@ const Customer_care_regular = () => {
dataIndex: 'coli_id_Last', dataIndex: 'coli_id_Last',
key: 'coli_id_Last', key: 'coli_id_Last',
width: '5em', width: '5em',
render: (_, r) => ({
children: _,
}),
onCell: (r) => ({ onCell: (r) => ({
style: { backgroundColor: '#5B8FF9' + '1A' }, style: { backgroundColor: '#5B8FF9' + '1A' },
}), }),
@ -129,9 +126,8 @@ const Customer_care_regular = () => {
dataIndex: 'COLI_OrderStartDate_Last', dataIndex: 'COLI_OrderStartDate_Last',
key: 'COLI_OrderStartDate_Last', key: 'COLI_OrderStartDate_Last',
width: '4em', width: '4em',
render: (_, r) => ({ onCell: (_, r) => ({
props: { style: { backgroundColor: '#5B8FF9' + '1A' } }, style: { backgroundColor: '#5B8FF9' + '1A' } ,
children: _,
}), }),
}, },
{ {
@ -139,9 +135,8 @@ const Customer_care_regular = () => {
dataIndex: 'Department_Last', dataIndex: 'Department_Last',
key: 'Department_Last', key: 'Department_Last',
width: '4em', width: '4em',
render: (_, r) => ({ onCell: (_, r) => ({
props: { style: { backgroundColor: '#5B8FF9' + '1A' } }, style: { backgroundColor: '#5B8FF9' + '1A' } ,
children: _,
}), }),
}, },
]; ];
@ -159,9 +154,8 @@ const Customer_care_regular = () => {
dataIndex: 'Repurchase_cycle', dataIndex: 'Repurchase_cycle',
key: 'Repurchase_cycle', key: 'Repurchase_cycle',
width: '4em', width: '4em',
render: (_, r) => ({ onCell: (_, r) => ({
props: { style: { backgroundColor: '#5B8FF9' + '1A' } }, style: { backgroundColor: '#5B8FF9' + '1A' },
children: _,
}), }),
}, },
{ {
@ -169,9 +163,8 @@ const Customer_care_regular = () => {
dataIndex: 'Orders_number', dataIndex: 'Orders_number',
key: 'Orders_number', key: 'Orders_number',
width: '4em', width: '4em',
render: (_, r) => ({ onCell: (_, r) => ({
props: { style: { backgroundColor: '#5B8FF9' + '1A' } }, style: { backgroundColor: '#5B8FF9' + '1A' },
children: _,
}), }),
}, },
{ {
@ -179,9 +172,8 @@ const Customer_care_regular = () => {
dataIndex: 'recommend_time', dataIndex: 'recommend_time',
key: 'recommend_time', key: 'recommend_time',
width: '4em', width: '4em',
render: (_, r) => ({ onCell: (_, r) => ({
props: { style: { backgroundColor: '#5B8FF9' + '1A' } }, style: { backgroundColor: '#5B8FF9' + '1A' },
children: _,
}), }),
}, },
{ {
@ -189,9 +181,8 @@ const Customer_care_regular = () => {
dataIndex: 'Travel_count', dataIndex: 'Travel_count',
key: 'Travel_count', key: 'Travel_count',
width: '4em', width: '4em',
render: (_, r) => ({ onCell: (_, r) => ({
props: { style: { backgroundColor: '#5B8FF9' + '1A' } }, style: { backgroundColor: '#5B8FF9' + '1A' },
children: _,
}), }),
}, },
{ {
@ -199,9 +190,8 @@ const Customer_care_regular = () => {
dataIndex: 'Travel_cycle', dataIndex: 'Travel_cycle',
key: 'Travel_cycle', key: 'Travel_cycle',
width: '4em', width: '4em',
render: (_, r) => ({ onCell: (_, r) => ({
props: { style: { backgroundColor: '#5B8FF9' + '1A' } }, style: { backgroundColor: '#5B8FF9' + '1A' },
children: _,
}), }),
}, },
{ {
@ -209,9 +199,8 @@ const Customer_care_regular = () => {
dataIndex: 'firstStartdate', dataIndex: 'firstStartdate',
key: 'firstStartdate', key: 'firstStartdate',
width: '4em', width: '4em',
render: (_, r) => ({ onCell: (_, r) => ({
props: { style: { backgroundColor: '#5B8FF9' + '1A' } }, style: { backgroundColor: '#5B8FF9' + '1A' },
children: _,
}), }),
}, },
]); ]);

@ -3,8 +3,8 @@ import { observer } from 'mobx-react';
import { stores_Context } from '../config'; import { stores_Context } from '../config';
import { Table, Row, Col, Divider, Switch, Space, Tabs } from 'antd'; import { Table, Row, Col, Divider, Switch, Space, Tabs } from 'antd';
import SearchForm from '../components/search/SearchForm'; import SearchForm from '../components/search/SearchForm';
import { TableExportBtn, VSTag } from './../components/Data'; import { TableExportBtn, VSTag } from '../components/Data';
import { fixTo2Decimals, isEmpty } from './../utils/commons'; import { fixTo2Decimals, isEmpty } from '../utils/commons';
// TdCellDataTable // TdCellDataTable
const TdCell = (tdprops) => { const TdCell = (tdprops) => {
@ -13,16 +13,27 @@ const TdCell = (tdprops) => {
return <td {...restProps} />; return <td {...restProps} />;
}; };
const SalesCustomerCareRegular = (props) => { const pivotOptions = [
{ key: 'operatorName', label: '顾问' },
{ key: 'country', label: '国家' },
];
const pivotColOptions = [
{ key: 'hasOld', value: 'hasOld', label: '老客户+推荐' },
{ key: 'IsOld_txt', value: 'IsOld_txt', label: '老客户' },
{ key: 'isCusCommend_txt', value: 'isCusCommend_txt', label: '推荐' },
];
const CustomerCareRegularPivot = (props) => {
const { 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 { pivotData: pageData } = customer_store.sales_regular_data; const { loading, pivotResult, filterColValues, rawData } = customer_store.sales_regular_data;
const pivotOptions = [{key: 'operatorName', label: '顾问'}, {key: 'country', label: '国家'}];
const [pivotRow, setPivotRow] = useState('operatorName'); const [pivotRow, setPivotRow] = useState('operatorName');
const [pivotCol, setPivotCol] = useState('hasOld');
const [pivotColLabel, setPivotColLabel] = useState('老客户+推荐');
const onTabsChange = (key) => { const onTabsChange = (key) => {
setPivotRow(key); setPivotRow(key);
customer_store.regular_data_pivot(key, pivotCol);
}; };
const [dataSource, setDataSource] = useState([]); const [dataSource, setDataSource] = useState([]);
@ -32,38 +43,40 @@ const SalesCustomerCareRegular = (props) => {
useEffect(() => { useEffect(() => {
if ( ! ifmerge) { if ( ! ifmerge) {
setDataSource(pageData[pivotRow].data); // setDataSource(pageData[pivotRow].data);
setDataForExport( setDataSource(pivotResult);
pageData[pivotRow].data.reduce( // setDataForExport(
(r, c) => // // pageData[pivotRow].data.reduce(
r.concat( // pivotResult.reduce(
[{ ...c, children: undefined }], // (r, c) =>
c.children // r.concat(
.reduce((rc, ele) => rc.concat([{ ...ele, [pivotRow]: ele.rowLabel }], [{ ...ele.vsData, [pivotRow]: ele.vsData.rowLabel, vsData: {} }]), []) // [{ ...c, children: undefined }],
.filter((ele) => ele.SumOrder !== undefined) // (c?.children || [])
), // .reduce((rc, ele) => rc.concat([{ ...ele, [pivotRow]: ele.rowLabel }], [{ ...ele.vsData, [pivotRow]: ele.vsData.rowLabel, vsData: {} }]), [])
[] // .filter((ele) => ele.SumOrder !== undefined)
) // ),
); // []
setDataForExportS(pageData[pivotRow].data.reduce((r, c) => r.concat([{...c, children: undefined}], [{ ...c.vsData, vsData: {} }]), []).filter((ele) => ele.SumOrder !== undefined)); // )
// );
setDataForExportS(pivotResult.reduce((r, c) => r.concat([{...c, children: undefined}], [{ ...c.vsData, vsData: {} }]), []).filter((ele) => ele.SumOrder !== undefined));
} else { } else {
setDataSource(pageData[pivotRow].mergedData); // setDataSource(pageData[pivotRow].mergedData);
setDataForExport( // setDataForExport(
pageData[pivotRow].mergedData.reduce( // pageData[pivotRow].mergedData.reduce(
(r, c) => // (r, c) =>
r.concat( // r.concat(
[{ ...c, children: undefined }], // [{ ...c, children: undefined }],
c.children.reduce((rc, ele) => rc.concat([{ ...ele, operatorName: ele.rowLabel }], [{ ...ele.vsData, operatorName: ele.vsData.rowLabel, vsData: {} }]), []) // c.children.reduce((rc, ele) => rc.concat([{ ...ele, operatorName: ele.rowLabel }], [{ ...ele.vsData, operatorName: ele.vsData.rowLabel, vsData: {} }]), [])
.filter((ele) => ele.SumOrder !== undefined) // .filter((ele) => ele.SumOrder !== undefined)
), // ),
[] // []
) // )
); // );
setDataForExportS(pageData[pivotRow].mergedData.reduce((r, c) => r.concat([{...c, children: undefined}], [{ ...c.vsData, vsData: {} }]), []).filter((ele) => ele.SumOrder !== undefined)); // setDataForExportS(pageData[pivotRow].mergedData.reduce((r, c) => r.concat([{...c, children: undefined}], [{ ...c.vsData, vsData: {} }]), []).filter((ele) => ele.SumOrder !== undefined));
} }
return () => {}; return () => {};
}, [ifmerge, pageData[pivotRow].data]); }, [ifmerge, pivotResult]);
const rowColumns = [ const rowColumns = [
@ -84,14 +97,14 @@ const SalesCustomerCareRegular = (props) => {
{ title: '来源', dataIndex: 'SourceType', key: 'SourceType' }, { title: '来源', dataIndex: 'SourceType', key: 'SourceType' },
{ title: '页面类型', dataIndex: 'COLI_LineClass', key: 'COLI_LineClass' }, { title: '页面类型', dataIndex: 'COLI_LineClass', key: 'COLI_LineClass' },
]; ];
const calcDelta = (r, key) => !isEmpty(Number(r.vsData[key])) ? fixTo2Decimals((Number(r[key] || 0) - Number(r.vsData[key]))/Number(r.vsData[key]) *100) : null; const calcDelta = (r, key) => !isEmpty(Number(r?.vsData?.[key])) ? fixTo2Decimals((Number(r[key] || 0) - Number(r.vsData[key]))/Number(r.vsData[key]) *100) : null;
const renderVS = (v, r, key) => { const renderVS = (v, r, key) => {
const delta = calcDelta(r, key); const delta = calcDelta(r, key);
return <> return <>
<Space direction={'vertical'}> <Space direction={'vertical'}>
<span> <span>
{v || 0} {v || 0}
{r.vsData[key] ? <span type="secondary"> VS {r.vsData[key]}</span> : null} {r?.vsData?.[key] ? <span type="secondary"> VS {r.vsData[key]}</span> : null}
</span> </span>
{delta && <VSTag diffPercent={delta} />} {delta && <VSTag diffPercent={delta} />}
</Space> </Space>
@ -123,14 +136,15 @@ const SalesCustomerCareRegular = (props) => {
dates: { hide_vs: false }, dates: { hide_vs: false },
}, },
}} }}
onSubmit={(_err, obj, form, str) => { onSubmit={async (_err, obj, form, str) => {
customer_store.setSearchValues(obj, form, 'sales_regular_data'); customer_store.setSearchValues(obj, form, 'sales_regular_data');
customer_store.get_sales_regular_data_vs(obj, pivotRow); await customer_store.get_sales_regular_data_vs(obj, pivotRow);
customer_store.regular_data_pivot(pivotRow, pivotCol);
}} }}
/> />
</Col> </Col>
</Row> </Row>
<Tabs <Tabs tabBarExtraContent={{ left: (<div style={{ width: '6rem'}}></div>)}}
type={'card'} type={'card'}
activeKey={pivotRow} activeKey={pivotRow}
onChange={onTabsChange} onChange={onTabsChange}
@ -142,7 +156,7 @@ const SalesCustomerCareRegular = (props) => {
{/* <h2>{ele.label}-老客户, 含推荐</h2> */} {/* <h2>{ele.label}-老客户, 含推荐</h2> */}
<> <>
<Divider orientation={'right'} style={{backgroundColor: '#fff', margin: 0, padding: '10px 0'}} > <Divider orientation={'right'} style={{backgroundColor: '#fff', margin: 0, padding: '10px 0'}} >
{pageData[pivotRow].data.length > 0 && pivotRow === 'operatorName' && ( {/* {dataSource.length > 0 && pivotRow === 'operatorName' && (
<Switch <Switch
unCheckedChildren="各账户" unCheckedChildren="各账户"
checkedChildren="合并" checkedChildren="合并"
@ -153,43 +167,58 @@ const SalesCustomerCareRegular = (props) => {
}} }}
/> />
)} )}
<Divider type={'vertical'} /> <Divider type={'vertical'} /> */}
<TableExportBtn <TableExportBtn
btnTxt="导出明细" btnTxt="导出明细"
label={`${formValuesToSub.Date1}-老客户-明细`} label={`${formValuesToSub.Date1}-老客户-明细`}
{...{ columns: [{ title: ele.label, dataIndex: pivotRow, key: pivotRow }, ...rowColumns], dataSource: pageData[pivotRow].rawData }} {...{ columns: [{ title: ele.label, dataIndex: pivotRow, key: pivotRow }, ...rowColumns], dataSource: rawData }}
/> />
<Divider type={'vertical'} /> {/* <Divider type={'vertical'} />
<TableExportBtn <TableExportBtn
btnTxt="导出下表-展开" btnTxt="导出下表-展开"
label={`${formValuesToSub.Date1}-${ele.label}.老客户`} label={`${formValuesToSub.Date1}-${ele.label}.老客户`}
{...{ columns: [{ title: ele.label, dataIndex: pivotRow, key: pivotRow }, ...columns], dataSource: dataForExport }} {...{ columns: [{ title: ele.label, dataIndex: pivotRow, key: pivotRow }, ...columns], dataSource: dataForExport }}
/> /> */}
<Divider type={'vertical'} /> <Divider type={'vertical'} />
<TableExportBtn <TableExportBtn
btnTxt="导出下表-总" btnTxt="导出下表"
label={`${formValuesToSub.Date1}-${ele.label}.老客户`} label={`${formValuesToSub.Date1}-${ele.label}.${pivotColLabel}`}
{...{ columns: [{ title: ele.label, dataIndex: pivotRow, key: pivotRow }, ...columns], dataSource: dataForExportS }} {...{ columns: [{ title: ele.label, dataIndex: pivotRow, key: pivotRow }, ...columns], dataSource: dataForExportS }}
/> />
</Divider> </Divider>
</> </>
<Table <Tabs style={{ backgroundColor: '#fff' }}
sticky tabPosition={'left'} defaultActiveKey={'mix'} activeKey={pivotCol}
dataSource={dataSource} onChange={(sub) => {
loading={pageData[ele.key].loading} setPivotCol(sub);
columns={[ setPivotColLabel(pivotColOptions.find((ele) => ele.key === sub).label);
{ customer_store.regular_data_pivot(pivotRow, sub);
key: ele.key, }}
title: ele.label, items={pivotColOptions.map((col, i) => {
dataIndex: ele.key, // const SubjectTableComponent = subjectComponents[ele.key];
width: '6em', return {
filters: pageData[ele.key].filterColValues, ...col,
onFilter: (value, record) => value.includes(record[ele.key]), children: (
filterSearch: true, <Table
}, sticky
...columns, dataSource={dataSource}
]} loading={loading}
pagination={false} columns={[
{
key: ele.key,
title: ele.label,
dataIndex: ele.key,
width: '6em',
filters: filterColValues,
onFilter: (value, record) => value.includes(record[ele.key]),
filterSearch: true,
},
...columns,
]}
pagination={false}
/>)
};
})}
/> />
</> </>
), ),
@ -199,4 +228,4 @@ const SalesCustomerCareRegular = (props) => {
</> </>
); );
}; };
export default observer(SalesCustomerCareRegular); export default observer(CustomerCareRegularPivot);

@ -1,4 +1,4 @@
import {makeAutoObservable, runInAction} from "mobx"; import {makeAutoObservable, runInAction, toJS } from "mobx";
import { fetchJSON } from '../utils/request'; import { fetchJSON } from '../utils/request';
import * as config from "../config"; import * as config from "../config";
import { groupsMappedByKey, sitesMappedByCode, pivotBy } from './../libs/ht'; import { groupsMappedByKey, sitesMappedByCode, pivotBy } from './../libs/ht';
@ -457,8 +457,8 @@ class CustomerStore {
// 销售-老客户 // 销售-老客户
sales_regular_data = { sales_regular_data = {
loading: false, loading: false,
data: [], // data: [],
mergedData: [], // mergedData: [],
rawData: [], rawData: [],
searchValues: { searchValues: {
DepartmentList: ['1', '2', '28', '7'].map(kk => groupsMappedByKey[kk]), DepartmentList: ['1', '2', '28', '7'].map(kk => groupsMappedByKey[kk]),
@ -466,78 +466,53 @@ class CustomerStore {
DateType: { key: 'applyDate', label: '提交日期'}, DateType: { key: 'applyDate', label: '提交日期'},
IncludeTickets: { key: '0', label: '不含门票' }, IncludeTickets: { key: '0', label: '不含门票' },
}, },
pivotData: { // pivotData: {
operatorName: { loading: false, data: [], rawData: [], mergedData: [], filterColValues: [] }, // operatorName: { loading: false, data: [], rawData: [], mergedData: [], filterColValues: [] },
country: { loading: false, data: [], rawData: [], mergedData: [], filterColValues: [] }, // country: { loading: false, data: [], rawData: [], mergedData: [], filterColValues: [] },
}, // },
pivotResult: [],
filterColValues: [],
rawDataArr: [],
}; };
get_sales_regular_data_vs = async (param, pivotRow = 'operatorName') => { get_sales_regular_data_vs = async (param, pivotRow = 'operatorName', pivotCol = 'hasOld') => {
this.sales_regular_data.pivotData[pivotRow].loading = true; this.sales_regular_data.loading = true;
const hasCompare = !isEmpty(param.DateDiff1); const hasCompare = !isEmpty(param.DateDiff1);
const [result1, result2] = await Promise.all([ const [result1, result2] = await Promise.all([
this.get_sales_regular_data(param, pivotRow), this.get_sales_regular_data(param),
hasCompare ? this.get_sales_regular_data({...param, Date1: param.DateDiff1, Date2: param.DateDiff2}, pivotRow) : { mergeDataBySales: [], mergeDataBySalesAccount: [], filterHasOld: []}, hasCompare ? this.get_sales_regular_data({...param, Date1: param.DateDiff1, Date2: param.DateDiff2}) : { filterHasOld: []},
]); ]);
const allTypes = ['老客户', '老客户推荐'];
// 独立的账户
const allSales = Array.from(new Set([...result1.mergeDataBySales.map(row=>row[pivotRow]), ...result2.mergeDataBySales.map(row=>row[pivotRow])]));
const sales1 = groupBy(result1.mergeDataBySales, pivotRow);
const sales2 = groupBy(result2.mergeDataBySales, pivotRow);
const mergeDataBySales = allSales.reduce((r, sale) => {
const _default = { [pivotRow]: sale, rowLabel: sales1?.[sale]?.rowLabel || sales2?.[sale]?.rowLabel, children: sales1?.[sale]?.children || [], key: sale};
const operatorRow = {...(sales1?.[sale]?.[0] || _default), vsData: sales2?.[sale]?.[0] || {}};
// 展开的两项: '老客户', '老客户推荐'
const series1Children = sales1?.[sale]?.[0]?.children || [];
const series2Children = sales2?.[sale]?.[0]?.children || [];
const children = allTypes.reduce((r, type) => {
const _default = { [pivotRow]: type, rowLabel: type, key: type};
const _typeRow = series1Children.find(sc => sc[pivotRow] === type) || _default;
const _typeVSRow = series2Children.find(sc => sc[pivotRow] === type) || {};
return r.concat({..._typeRow, vsData: _typeVSRow});
}, []);
operatorRow.children = children;
return r.concat(operatorRow);
}, []);
// 合并顾问的账户 // 合并顾问的账户
let mergeDataBySalesAccount = []; // let mergeDataBySalesAccount = [];
if (pivotRow === 'operatorName') { // if (pivotRow === 'operatorName') {
const allSalesMerged = Array.from(new Set([...result1.mergeDataBySalesAccount.map(row=>row.operatorName), ...result2.mergeDataBySalesAccount.map(row=>row.operatorName)])); // const allSalesMerged = Array.from(new Set([...result1.mergeDataBySalesAccount.map(row=>row.operatorName), ...result2.mergeDataBySalesAccount.map(row=>row.operatorName)]));
const salesM1 = groupBy(result1.mergeDataBySalesAccount, 'operatorName'); // const salesM1 = groupBy(result1.mergeDataBySalesAccount, 'operatorName');
const salesM2 = groupBy(result2.mergeDataBySalesAccount, 'operatorName'); // const salesM2 = groupBy(result2.mergeDataBySalesAccount, 'operatorName');
mergeDataBySalesAccount = allSalesMerged.reduce((r, sale) => { // mergeDataBySalesAccount = allSalesMerged.reduce((r, sale) => {
const _default = { operatorName: sale, rowLabel: salesM1?.[sale]?.rowLabel || salesM2?.[sale]?.rowLabel, children: salesM1?.[sale]?.children || [], key: sale}; // const _default = { operatorName: sale, rowLabel: salesM1?.[sale]?.rowLabel || salesM2?.[sale]?.rowLabel, children: salesM1?.[sale]?.children || [], key: sale};
const operatorRow = {...(salesM1?.[sale]?.[0] || _default), vsData: salesM2?.[sale]?.[0] || {}}; // const operatorRow = {...(salesM1?.[sale]?.[0] || _default), vsData: salesM2?.[sale]?.[0] || {}};
// 展开的两项: '老客户', '老客户推荐' // // 展开的两项: '老客户', '老客户推荐'
const series1Children = salesM1?.[sale]?.[0]?.children || []; // const series1Children = salesM1?.[sale]?.[0]?.children || [];
const series2Children = salesM2?.[sale]?.[0]?.children || []; // const series2Children = salesM2?.[sale]?.[0]?.children || [];
const children = allTypes.reduce((r, type) => { // const children = allTypes.reduce((r, type) => {
const _default = { operatorName: type, rowLabel: type, key: type}; // const _default = { operatorName: type, rowLabel: type, key: type};
const _typeRow = series1Children.find(sc => sc.operatorName === type) || _default; // const _typeRow = series1Children.find(sc => sc.operatorName === type) || _default;
const _typeVSRow = series2Children.find(sc => sc.operatorName === type) || {}; // const _typeVSRow = series2Children.find(sc => sc.operatorName === type) || {};
return r.concat({..._typeRow, vsData: _typeVSRow}); // return r.concat({..._typeRow, vsData: _typeVSRow});
}, []); // }, []);
operatorRow.children = children; // operatorRow.children = children;
return r.concat(operatorRow); // return r.concat(operatorRow);
}, []); // }, []);
} // }
const filterColValues = uniqWith(
mergeDataBySales.map((rr) => ({ text: rr[pivotRow], value: rr[pivotRow] })), this.sales_regular_data.loading = false;
(a, b) => JSON.stringify(a) === JSON.stringify(b) this.sales_regular_data.rawData = [].concat(result1.filterHasOld, result2.filterHasOld);
).sort((a, b) => a.text.localeCompare(b.text, 'zh-CN')); this.sales_regular_data.rawDataArr = [result1, result2];
this.sales_regular_data.pivotData[pivotRow].loading = false;
this.sales_regular_data.pivotData[pivotRow].rawData = [].concat(result1.filterHasOld, result2.filterHasOld);
this.sales_regular_data.pivotData[pivotRow].data = mergeDataBySales;
this.sales_regular_data.pivotData[pivotRow].mergedData = isEmpty(mergeDataBySalesAccount) ? mergeDataBySales : mergeDataBySalesAccount;
this.sales_regular_data.pivotData[pivotRow].filterColValues = filterColValues;
}; };
get_sales_regular_data = async (param, pivotRow = 'operatorName') => { get_sales_regular_data = async (param) => {
const seriesKey = `${param.Date1}${param.Date2}`; const seriesKey = `${param.Date1}${param.Date2}`;
const rawData = await getDetailData({...param, }); const rawData = await getDetailData({...param, });
const filterHasOld = rawData.filter(ele => (ele.IsOld === '1' || ele.isCusCommend === '1')).map(e => ({ const filterHasOld = rawData.filter(ele => (ele.IsOld === '1' || ele.isCusCommend === '1')).map(e => ({
@ -546,38 +521,69 @@ class CustomerStore {
operatorNameB: e.operatorName.replace(/\([^)]*\)/gi, '').toLowerCase(), operatorNameB: e.operatorName.replace(/\([^)]*\)/gi, '').toLowerCase(),
})); }));
const { data: hasOldData, } = pivotBy(filterHasOld, [['hasOld', pivotRow], [], []]);
const { data: IsOldData, } = pivotBy(filterHasOld.filter(ele => ele.IsOld === '1'), [[pivotRow, 'IsOld_txt', ], [], []]);
const { data: isCusCommendData, } = pivotBy(filterHasOld.filter(ele => ele.isCusCommend === '1'), [[pivotRow, 'isCusCommend_txt', ], [], []]);
// console.log('IsOldData====', IsOldData, '\nisCusCommend', isCusCommendData);
// console.log('data====', rawData, '\ncolumnValues', columnValues, '\nsummaryRows', summaryRows, '\nsummaryColumns', summaryColumns, '\nsummaryMix', summaryMix, '\nhasOld',filterHasOld);
const mergeDataBySales = hasOldData.map((ele) => ({
...ele,
seriesKey,
children: [].concat(
IsOldData.filter((ele1) => ele1[pivotRow] === ele[pivotRow]).map(o => ({...o, [pivotRow]: o.IsOld_txt, key: o.rowLabel, seriesKey,})),
isCusCommendData.filter((ele2) => ele2[pivotRow] === ele[pivotRow]).map(o => ({...o, [pivotRow]: o.isCusCommend_txt, key: o.rowLabel, seriesKey,}))
),
}));
// 合并顾问的账户 // 合并顾问的账户
let mergeDataBySalesAccount = []; // let mergeDataBySalesAccount = [];
if (pivotRow === 'operatorName') { // if (pivotRow === 'operatorName') {
const { data: hasOldDataSales, } = pivotBy(filterHasOld, [['hasOld', 'operatorNameB'], [], []]); // const { data: hasOldDataSales, } = pivotBy(filterHasOld, [['hasOld', 'operatorNameB'], [], []]);
const { data: IsOldDataSales, } = pivotBy(filterHasOld.filter(ele => ele.IsOld === '1'), [['operatorNameB', 'IsOld_txt', ], [], []]); // 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 { data: isCusCommendDataSales, } = pivotBy(filterHasOld.filter(ele => ele.isCusCommend === '1'), [['operatorNameB', 'isCusCommend_txt', ], [], []]);
mergeDataBySalesAccount = hasOldDataSales.map((ele) => ({ // mergeDataBySalesAccount = hasOldDataSales.map((ele) => ({
...ele, // ...ele,
operatorName: ele.operatorNameB, // operatorName: ele.operatorNameB,
seriesKey, // seriesKey,
children: [].concat( // children: [].concat(
IsOldDataSales.filter((ele1) => ele1.operatorNameB === ele.operatorNameB).map(o => ({...o, operatorName: o.IsOld_txt, key: o.rowLabel, seriesKey,})), // IsOldDataSales.filter((ele1) => ele1.operatorNameB === ele.operatorNameB).map(o => ({...o, operatorName: o.IsOld_txt, key: o.rowLabel, seriesKey,})),
isCusCommendDataSales.filter((ele2) => ele2.operatorNameB === ele.operatorNameB).map(o => ({...o, operatorName: o.isCusCommend_txt, key: o.rowLabel, seriesKey,})) // isCusCommendDataSales.filter((ele2) => ele2.operatorNameB === ele.operatorNameB).map(o => ({...o, operatorName: o.isCusCommend_txt, key: o.rowLabel, seriesKey,}))
), // ),
})); // }));
} // }
// console.log('IsOldDataSales====', IsOldDataSales, '\nisCusCommendDataSales', isCusCommendDataSales); // console.log('IsOldDataSales====', IsOldDataSales, '\nisCusCommendDataSales', isCusCommendDataSales);
return { mergeDataBySales, mergeDataBySalesAccount, filterHasOld }; // console.log('mergeDataByRow====\n', mergeDataByRow);
// return { mergeDataBySales, mergeDataBySalesAccount, filterHasOld };
return { filterHasOld };
};
regular_data_pivot = (pivotRow, pivotCol) => {
// console.clear();
// this.sales_regular_data.rawData;
// console.log('regular_data_pivot -------------------------------------------------------------- rawData 000 ', toJS(this.sales_regular_data.rawData));
// console.log('regular_data_pivot ---- ', pivotRow, pivotCol);
const [result1, result2] = this.sales_regular_data.rawDataArr;
const allRows = Array.from(new Set([...result1.filterHasOld.map(row=>row[pivotRow]), ...result2.filterHasOld.map(row=>row[pivotRow])]));
// console.log(' ------ allRows', allRows);
const [pivot1, pivot2] = [result1, result2].map(_result => {
const dataColField = pivotCol.replace('_txt', '');
const rawData = pivotCol === 'hasOld' ? _result.filterHasOld : _result.filterHasOld.filter((ele) => ele[dataColField] === '1');
const { data: pivotResult } = pivotBy(rawData, [[pivotRow, pivotCol], [], []]);
return pivotResult;
});
const rows1 = groupBy(pivot1, pivotRow);
const rows2 = groupBy(pivot2, pivotRow);
const pivotResultWithCompare = isEmpty(pivot2) ? pivot1 : allRows.reduce((r, rowName) => {
const _default = { [pivotRow]: rowName, rowLabel: rows1?.[rowName]?.rowLabel || rows2?.[rowName]?.rowLabel, children: rows1?.[rowName], key: rowName};
const operatorRow = {...(rows1?.[rowName]?.[0] || _default), vsData: rows2?.[rowName]?.[0] || {}};
// 展开的两项: '老客户', '老客户推荐'
// const series1Children = rows1?.[rowName]?.[0]?.children || [];
// const series2Children = rows2?.[rowName]?.[0]?.children || [];
// const children = allTypes.reduce((r, type) => {
// const _default = { [pivotRow]: type, rowLabel: type, key: type};
// const _typeRow = series1Children.find(sc => sc[pivotRow] === type) || _default;
// const _typeVSRow = series2Children.find(sc => sc[pivotRow] === type) || {};
// return r.concat({..._typeRow, vsData: _typeVSRow});
// }, []);
// operatorRow.children = children;
return r.concat(operatorRow);
}, []);
// console.log(' ------ pivot1', pivot1, '\npivot2', pivot2, '\npivotResultWithCompare', pivotResultWithCompare);
const filterColValues = uniqWith(
allRows.map((rr) => ({ text: rr, value: rr })),
(a, b) => JSON.stringify(a) === JSON.stringify(b)
).sort((a, b) => a.text.localeCompare(b.text, 'zh-CN'));
this.sales_regular_data.pivotResult = pivotResultWithCompare;
this.sales_regular_data.filterColValues = filterColValues;
}; };
setSearchValues(obj, values, target) { setSearchValues(obj, values, target) {

Loading…
Cancel
Save