diff --git a/src/components/Data.jsx b/src/components/Data.jsx index aed3558..7b2ae3f 100644 --- a/src/components/Data.jsx +++ b/src/components/Data.jsx @@ -44,11 +44,11 @@ export const TableExportBtn = ({label, columns, dataSource, btnTxt, ...props}) = ...r, ...(v.children ? v.children.reduce((rc, vc, ci) => ({ ...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) => - 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) // !['string', 'number'].includes(typeof vc.title) ? `${v?.titleX || v.title}` : `${v?.titleX || v.title}-${vc.title || ''}` diff --git a/src/libs/ht.js b/src/libs/ht.js index a9cd8ac..20d66e8 100644 --- a/src/libs/ht.js +++ b/src/libs/ht.js @@ -1,3 +1,4 @@ +import moment from 'moment'; 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')) { // } // 补充计算的字段 - 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 RTXF_WB_range = calculateRangeScale(RTXF_WB_values); 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.PPPriceRange = calcPPPriceRange(ele.PPPrice); 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')) { - data = _data.reduce((r, v, i) => { + data = data.reduce((r, v, i) => { const vjson = isEmpty(v.destinationCountry_AsJOSN) ? [] : v.destinationCountry_AsJOSN; const xv = (vjson).reduce((rv, cv, vi) => { 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')) { - data = _data.reduce((r, v, i) => { + data = data.reduce((r, v, i) => { const vjson = isEmpty(v.destinations_AsJOSN) ? [] : v.destinations_AsJOSN; const xv = (vjson).reduce((rv, cv, vi) => { rv.push({...v, destinations_AsJOSN: cv, key: vi === 0 ? v.key : `${v.key}@${cv}`}); diff --git a/src/views/DataPivot.jsx b/src/views/DataPivot.jsx index 1fac8f3..31dd60f 100644 --- a/src/views/DataPivot.jsx +++ b/src/views/DataPivot.jsx @@ -21,6 +21,10 @@ const filterFields = [ { key: 'COLI_LineClass', label: '页面渠道' }, { key: 'guestGroupType', label: '客群类别' }, { key: 'travelMotivation', label: '出行目的' }, + { key: 'startMonth', label: '出行日期-月份' }, + { key: 'startYearMonth', label: '出行日期-年月' }, + { key: 'applyMonth', label: '预订日期-月份' }, + { key: 'applyYearMonth', label: '预订日期-年月' }, { key: 'operatorName', label: '顾问' }, { key: 'WebCode', label: '来源站点' }, { key: 'IsOld_txt', label: '是否老客户' }, @@ -195,7 +199,10 @@ export default observer((props) => { setPivotRow({}); 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}), {}); setPivotTableColumnSummary(colDataMapped); // 行列的选项值 @@ -459,11 +466,11 @@ export default observer((props) => { dataIndex: 'applyDate', key: 'applyDate', }, - // { - // title: '出发日期', - // dataIndex: 'CGI_ArriveDate', - // key: 'CGI_ArriveDate', - // }, + { + title: '出发日期', + dataIndex: 'startDate', + key: 'startDate', + }, ], }; @@ -709,7 +716,6 @@ export default observer((props) => { /> - { !pivotDateColumns[0].includes('destinationCountry_AsJOSN') && !pivotDateColumns[0].includes('destinations_AsJOSN') &&

@@ -725,7 +731,6 @@ export default observer((props) => { - } ); });