|
|
@ -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) {
|
|
|
|