perf: 数据透视: 增加日期

main
Lei OT 2 months ago
parent 8a0f919a42
commit 876216458e

@ -44,11 +44,11 @@ export const TableExportBtn = ({label, columns, dataSource, btnTxt, ...props}) =
...r, ...r,
...(v.children ? v.children.reduce((rc, vc, ci) => ({ ...(v.children ? v.children.reduce((rc, vc, ci) => ({
...rc, ...rc,
...(vc?.titleX ? {[`${v?.titleX || v.title},${vc.titleX}`]: vc.titleX } : {[(v?.titleX || v.title) + (ci || '')]: `${vc?.titleX || vc?.title || ''}`}), ...(vc?.titleX ? {[`${v?.titleX || v.title},${vc.titleX}`]: vc.titleX } : {[(v?.titleX || v.title) + (vc.key || ci || '')]: `${vc?.titleX || vc?.title || ''}`}),
}), {}) : {}) }), {}) : {})
}), {}); }), {});
const flatCols = columns.flatMap((v, k) => const flatCols = columns.flatMap((v, k) =>
v.children ? v.children.map((vc, ci) => ({ ...vc, title: `${v?.titleX || v.title}` + (vc?.titleX ? `,${vc.titleX}` : (ci || '')) })) : {...v, title: `${v?.titleX || v.title}`} v.children ? v.children.map((vc, ci) => ({ ...vc, title: `${v?.titleX || v.title}` + (vc?.titleX ? `,${vc.titleX}` : (vc.key || ci || '')) })) : {...v, title: `${v?.titleX || v.title}`}
); );
// .filter((c) => c.dataIndex) // .filter((c) => c.dataIndex)
// !['string', 'number'].includes(typeof vc.title) ? `${v?.titleX || v.title}` : `${v?.titleX || v.title}-${vc.title || ''}` // !['string', 'number'].includes(typeof vc.title) ? `${v?.titleX || v.title}` : `${v?.titleX || v.title}-${vc.title || ''}`

@ -1,3 +1,4 @@
import moment from 'moment';
import { fixTo4Decimals, fixTo1Decimals, fixToInt, groupBy, sortBy, cloneDeep, pick, unique, flush, fixTo2Decimals, isEmpty } from '../utils/commons'; import { fixTo4Decimals, fixTo1Decimals, fixToInt, groupBy, sortBy, cloneDeep, pick, unique, flush, fixTo2Decimals, isEmpty } from '../utils/commons';
/** /**
@ -294,10 +295,14 @@ export const pivotBy = (_data, [rows, columns, date]) => {
// if (groupbyKeys.includes('PPPriceRange')) { // if (groupbyKeys.includes('PPPriceRange')) {
// } // }
// 补充计算的字段 // 补充计算的字段
const RTXF_WB_values = cloneDeep(_data).map(ele => ele.RTXF_WB); const RTXF_WB_values = cloneDeep(_data).map(ele => ele.RTXF_WB); // 人天消费
// const max_RTXF_WB = Math.max(...RTXF_WB_values); // const max_RTXF_WB = Math.max(...RTXF_WB_values);
const RTXF_WB_range = calculateRangeScale(RTXF_WB_values); const RTXF_WB_range = calculateRangeScale(RTXF_WB_values);
let data = cloneDeep(_data).map(ele => { let data = cloneDeep(_data).map(ele => {
ele.startYearMonth = ele.startDate ? moment(ele.startDate).format('YYYY-MM') : '';
ele.startMonth = ele.startDate ? moment(ele.startDate).format('MM') : '';
ele.applyYearMonth = ele.applyDate ? moment(ele.applyDate).format('YYYY-MM') : '';
ele.applyMonth = ele.applyDate ? moment(ele.applyDate).format('MM') : '';
ele.PPPrice = (Number(ele.orderState) === 1 && ele.tourdays && ele.personNum) ? fixToInt(ele.quotePrice / ele.tourdays / ele.personNum) : -1; // 报价: 人均天 ele.PPPrice = (Number(ele.orderState) === 1 && ele.tourdays && ele.personNum) ? fixToInt(ele.quotePrice / ele.tourdays / ele.personNum) : -1; // 报价: 人均天
ele.PPPriceRange = calcPPPriceRange(ele.PPPrice); ele.PPPriceRange = calcPPPriceRange(ele.PPPrice);
ele.RTXF_WB_range = findRange(ele.RTXF_WB, RTXF_WB_range); ele.RTXF_WB_range = findRange(ele.RTXF_WB, RTXF_WB_range);
@ -316,7 +321,7 @@ export const pivotBy = (_data, [rows, columns, date]) => {
}); });
// 数组的字段值, 拆分处理 // 数组的字段值, 拆分处理
if (groupbyKeys.includes('destinationCountry_AsJOSN')) { if (groupbyKeys.includes('destinationCountry_AsJOSN')) {
data = _data.reduce((r, v, i) => { data = data.reduce((r, v, i) => {
const vjson = isEmpty(v.destinationCountry_AsJOSN) ? [] : v.destinationCountry_AsJOSN; const vjson = isEmpty(v.destinationCountry_AsJOSN) ? [] : v.destinationCountry_AsJOSN;
const xv = (vjson).reduce((rv, cv, vi) => { const xv = (vjson).reduce((rv, cv, vi) => {
rv.push({...v, destinationCountry_AsJOSN: cv, key: vi === 0 ? v.key : `${v.key}@${cv}`}); rv.push({...v, destinationCountry_AsJOSN: cv, key: vi === 0 ? v.key : `${v.key}@${cv}`});
@ -328,7 +333,7 @@ export const pivotBy = (_data, [rows, columns, date]) => {
}, []); }, []);
} }
if (groupbyKeys.includes('destinations_AsJOSN')) { if (groupbyKeys.includes('destinations_AsJOSN')) {
data = _data.reduce((r, v, i) => { data = data.reduce((r, v, i) => {
const vjson = isEmpty(v.destinations_AsJOSN) ? [] : v.destinations_AsJOSN; const vjson = isEmpty(v.destinations_AsJOSN) ? [] : v.destinations_AsJOSN;
const xv = (vjson).reduce((rv, cv, vi) => { const xv = (vjson).reduce((rv, cv, vi) => {
rv.push({...v, destinations_AsJOSN: cv, key: vi === 0 ? v.key : `${v.key}@${cv}`}); rv.push({...v, destinations_AsJOSN: cv, key: vi === 0 ? v.key : `${v.key}@${cv}`});

@ -21,6 +21,10 @@ const filterFields = [
{ key: 'COLI_LineClass', label: '页面渠道' }, { key: 'COLI_LineClass', label: '页面渠道' },
{ key: 'guestGroupType', label: '客群类别' }, { key: 'guestGroupType', label: '客群类别' },
{ key: 'travelMotivation', label: '出行目的' }, { key: 'travelMotivation', label: '出行目的' },
{ key: 'startMonth', label: '出行日期-月份' },
{ key: 'startYearMonth', label: '出行日期-年月' },
{ key: 'applyMonth', label: '预订日期-月份' },
{ key: 'applyYearMonth', label: '预订日期-年月' },
{ key: 'operatorName', label: '顾问' }, { key: 'operatorName', label: '顾问' },
{ key: 'WebCode', label: '来源站点' }, { key: 'WebCode', label: '来源站点' },
{ key: 'IsOld_txt', label: '是否老客户' }, { key: 'IsOld_txt', label: '是否老客户' },
@ -195,7 +199,10 @@ export default observer((props) => {
setPivotRow({}); setPivotRow({});
setPivotRowDataSource([]); setPivotRowDataSource([]);
// //
const sortColData = summaryColumns.sort(sortBy(defaultValKey)).reverse(); const _col1 = pivotDateColumns[1][0] || '';
const _sortByDateOrVal = (_col1.includes('Month') || _col1.includes('Date')) ? _col1 : defaultValKey;
let sortColData = summaryColumns.sort(sortBy(_sortByDateOrVal));
sortColData = _sortByDateOrVal === defaultValKey ? sortColData.reverse() : sortColData;
const colDataMapped = isEmpty(pivotDateColumns[1]) ? sortColData[0] : sortColData.reduce((r, v) => ({...r, [v[pivotDateColumns[1][0]]]: v}), {}); const colDataMapped = isEmpty(pivotDateColumns[1]) ? sortColData[0] : sortColData.reduce((r, v) => ({...r, [v[pivotDateColumns[1][0]]]: v}), {});
setPivotTableColumnSummary(colDataMapped); setPivotTableColumnSummary(colDataMapped);
// //
@ -459,11 +466,11 @@ export default observer((props) => {
dataIndex: 'applyDate', dataIndex: 'applyDate',
key: 'applyDate', key: 'applyDate',
}, },
// { {
// title: '', title: '出发日期',
// dataIndex: 'CGI_ArriveDate', dataIndex: 'startDate',
// key: 'CGI_ArriveDate', key: 'startDate',
// }, },
], ],
}; };
@ -709,7 +716,6 @@ export default observer((props) => {
/> />
</Spin> </Spin>
</section> </section>
{ !pivotDateColumns[0].includes('destinationCountry_AsJOSN') && !pivotDateColumns[0].includes('destinations_AsJOSN') &&
<section> <section>
<Spin spinning={loading}> <Spin spinning={loading}>
<h3> <h3>
@ -725,7 +731,6 @@ export default observer((props) => {
<Table {...detailsTableProps} dataSource={pivotRowDataSource} components={{ body: { cell: TdCell } }} /> <Table {...detailsTableProps} dataSource={pivotRowDataSource} components={{ body: { cell: TdCell } }} />
</Spin> </Spin>
</section> </section>
}
</div> </div>
); );
}); });

Loading…
Cancel
Save