|
|
|
|
@ -2,7 +2,7 @@ import {makeAutoObservable, runInAction, toJS } from "mobx";
|
|
|
|
|
import { fetchJSON } from '@haina/utils-request';
|
|
|
|
|
import * as config from "../config";
|
|
|
|
|
import { groupsMappedByKey, sitesMappedByCode, pivotBy } from './../libs/ht';
|
|
|
|
|
import { sortBy, formatPercent, groupBy, isEmpty, uniqWith, formatPercentToFloat } from "@haina/utils-commons";
|
|
|
|
|
import { sortBy, formatPercent, groupBy, isEmpty, uniqWith, formatPercentToFloat, fixTo2Decimals } from "@haina/utils-commons";
|
|
|
|
|
import { show_vs_tag, } from "./../utils/commons";
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
|
|
@ -14,6 +14,26 @@ const getDetailData = async (param) => {
|
|
|
|
|
return json.errcode === 0 ? json.result : [];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const calcSummaryRow = (data1, data2) => {
|
|
|
|
|
const summaryFields = ['ConfirmOrder', 'SumOrder', 'SumML', 'transactions', 'SumPersonNum', 'ConfirmPersonNum', 'ConfirmOrderKPIvalue', 'OrderKPIvalue', 'MLKPIvalue'];
|
|
|
|
|
|
|
|
|
|
const xSummary = summaryFields.reduce((r, skey) => ({ ...r, [skey]: data1.reduce((a, c) => a + c[skey], 0) }), {});
|
|
|
|
|
xSummary.ConfirmRates = xSummary.SumOrder ? fixTo2Decimals((xSummary.ConfirmOrder / xSummary.SumOrder) * 100) : 0;
|
|
|
|
|
xSummary.ConfirmRates_txt = xSummary.ConfirmRates; // + '%';
|
|
|
|
|
xSummary.confirmTourdays = '-';
|
|
|
|
|
xSummary.SingleML = '-';
|
|
|
|
|
xSummary._data = data1;
|
|
|
|
|
const xSummary2 = summaryFields.reduce((r, skey) => ({ ...r, [skey]: data2.reduce((a, c) => a + c[skey], 0) }), {});
|
|
|
|
|
xSummary2.ConfirmRates = xSummary2.SumOrder ? fixTo2Decimals((xSummary2.ConfirmOrder / xSummary2.SumOrder) * 100) : 0;
|
|
|
|
|
xSummary2.ConfirmRates_txt = xSummary2.ConfirmRates; // + '%';
|
|
|
|
|
xSummary2.confirmTourdays = '-';
|
|
|
|
|
xSummary2.SingleML = '-';
|
|
|
|
|
xSummary2._data = data2;
|
|
|
|
|
|
|
|
|
|
xSummary.vsData = xSummary2;
|
|
|
|
|
return xSummary;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CustomerStore {
|
|
|
|
|
|
|
|
|
|
constructor(rootStore) {
|
|
|
|
|
@ -476,6 +496,7 @@ class CustomerStore {
|
|
|
|
|
// country: { loading: false, data: [], rawData: [], mergedData: [], filterColValues: [] },
|
|
|
|
|
// },
|
|
|
|
|
pivotResult: [],
|
|
|
|
|
countrySummary: [],
|
|
|
|
|
filterColValues: [],
|
|
|
|
|
rawDataArr: [],
|
|
|
|
|
};
|
|
|
|
|
@ -556,31 +577,36 @@ class CustomerStore {
|
|
|
|
|
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 [{ pivotResult: pivot1, rowValues: rowValues1 }, { pivotResult: pivot2, rowValues: rowValues2 }] = [result1, result2].map(_result => {
|
|
|
|
|
const [{ pivotResult: pivot1, rowValues: rowValues1 }, { pivotResult: pivot2, rowValues: rowValues2 }] = [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, columnValues: [[rowValues,], columnsKeys, dateKeys] } = pivotBy(rawData, [[pivotRow, pivotCol], [], []]);
|
|
|
|
|
const {
|
|
|
|
|
data: pivotResult,
|
|
|
|
|
columnValues: [[rowValues], columnsKeys, dateKeys],
|
|
|
|
|
} = pivotBy(rawData, [[pivotRow, pivotCol], [], []]);
|
|
|
|
|
return { pivotResult, rowValues };
|
|
|
|
|
});
|
|
|
|
|
const allRowValues = Array.from(new Set([...rowValues1, ...rowValues2]));
|
|
|
|
|
// console.log(' ------ xx', rowValues1);
|
|
|
|
|
const rows1 = groupBy(pivot1, pivotRow);
|
|
|
|
|
const rows2 = groupBy(pivot2, pivotRow);
|
|
|
|
|
const pivotResultWithCompare = isEmpty(pivot2) ? pivot1 : allRowValues.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);
|
|
|
|
|
}, []);
|
|
|
|
|
const pivotResultWithCompare = isEmpty(pivot2)
|
|
|
|
|
? pivot1
|
|
|
|
|
: allRowValues.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(
|
|
|
|
|
@ -588,6 +614,27 @@ class CustomerStore {
|
|
|
|
|
(a, b) => JSON.stringify(a) === JSON.stringify(b)
|
|
|
|
|
).sort((a, b) => a.text.localeCompare(b.text, 'zh-CN'));
|
|
|
|
|
|
|
|
|
|
if (pivotRow === 'country') {
|
|
|
|
|
const aseanKK = ['新加坡', '马来西亚', '印度尼西亚', '菲律宾', '越南', '泰国', '文莱', '柬埔寨', '东帝汶', '老挝', '缅甸'];
|
|
|
|
|
const [asean1, asean2] = [
|
|
|
|
|
pivot1.filter((ele) => aseanKK.includes(ele.country)),
|
|
|
|
|
pivot2.filter((ele) => aseanKK.includes(ele.country)),
|
|
|
|
|
];
|
|
|
|
|
const aseanSummary = calcSummaryRow(asean1, asean2);
|
|
|
|
|
aseanSummary.key = '东南亚11国';
|
|
|
|
|
aseanSummary.country = '东南亚11国';
|
|
|
|
|
|
|
|
|
|
const eurusdKK = ['美国', '加拿大', '澳大利亚', '英国'];
|
|
|
|
|
const [eurusd1, eurusd2] = [
|
|
|
|
|
pivot1.filter((ele) => eurusdKK.includes(ele.country)),
|
|
|
|
|
pivot2.filter((ele) => eurusdKK.includes(ele.country)),
|
|
|
|
|
];
|
|
|
|
|
const eurusdSummary = calcSummaryRow(eurusd1, eurusd2);
|
|
|
|
|
eurusdSummary.key = '欧美4国';
|
|
|
|
|
eurusdSummary.country = '欧美4国';
|
|
|
|
|
|
|
|
|
|
this.sales_regular_data.countrySummary = [aseanSummary, eurusdSummary];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.sales_regular_data.pivotResult = pivotResultWithCompare;
|
|
|
|
|
this.sales_regular_data.filterColValues = filterColValues;
|
|
|
|
|
|