|
|
|
@ -5,14 +5,14 @@ import moment from 'moment';
|
|
|
|
|
import { isEmpty, pick, sortBy, fixTo2Decimals, cloneDeep, unique } from '../utils/commons';
|
|
|
|
|
|
|
|
|
|
const modelMapper = {
|
|
|
|
|
'tourDays': { url: '/service-Analyse2/GetTradeApartByTourDays' },
|
|
|
|
|
'PML': { url: '/service-Analyse2/GetTradeApartByPML' },
|
|
|
|
|
'ConfirmDays': { url: '/service-Analyse2/GetTradeApartByConfirmDays' },
|
|
|
|
|
'ApplyDays': { url: '/service-Analyse2/GetTradeApartByApplyDays' },
|
|
|
|
|
'PersonNum': { url: '/service-Analyse2/GetTradeApartByPersonNum' },
|
|
|
|
|
'destination': { url: '/service-Analyse2/GetTradeApartByDestination' },
|
|
|
|
|
'GlobalDestination': { url: '/service-Analyse2/GetTradeApartByGlobalDestination' },
|
|
|
|
|
'destinationCountry': { url: '/service-Analyse2/GetTradeApartByDestinationCountry' },
|
|
|
|
|
'tourDays': { url: '/service-Analyse2/GetTradeApartByTourDays', keySort: true },
|
|
|
|
|
'PML': { url: '/service-Analyse2/GetTradeApartByPML', keySort: true },
|
|
|
|
|
'ConfirmDays': { url: '/service-Analyse2/GetTradeApartByConfirmDays', keySort: true },
|
|
|
|
|
'ApplyDays': { url: '/service-Analyse2/GetTradeApartByApplyDays', keySort: true },
|
|
|
|
|
'PersonNum': { url: '/service-Analyse2/GetTradeApartByPersonNum', keySort: true },
|
|
|
|
|
'destination': { url: '/service-Analyse2/GetTradeApartByDestination', keySort: false },
|
|
|
|
|
'GlobalDestination': { url: '/service-Analyse2/GetTradeApartByGlobalDestination', keySort: false },
|
|
|
|
|
'destinationCountry': { url: '/service-Analyse2/GetTradeApartByDestinationCountry', keySort: false },
|
|
|
|
|
};
|
|
|
|
|
class Distribution {
|
|
|
|
|
constructor(appStore) {
|
|
|
|
@ -41,12 +41,13 @@ class Distribution {
|
|
|
|
|
param.DateToQ2 = DateToQ2.format(`${DATE_FORMAT} 23:59:59`);
|
|
|
|
|
const json = await req.fetchJSON(modelMapper[mkey].url, param);
|
|
|
|
|
if (json.errcode === 0) {
|
|
|
|
|
const dataLength = json.result.length;
|
|
|
|
|
const pickResult = dataLength > 20 ? json.result.slice(0, 30) : json.result;
|
|
|
|
|
const dataSource = calcDiff({ result: pickResult, resultToY: json.resultToY, resultToQ: json.resultToQ }, modelMapper[mkey].keySort);
|
|
|
|
|
runInAction(() => {
|
|
|
|
|
const dataLength = json.result.length;
|
|
|
|
|
this[mkey].loading = false;
|
|
|
|
|
this[mkey].originData = json.result;
|
|
|
|
|
const pickResult = dataLength > 20 ? json.result.slice(0, 30) : json.result;
|
|
|
|
|
this[mkey].dataSource = calcDiff({ result: pickResult, resultToY: json.resultToY, resultToQ: json.resultToQ });
|
|
|
|
|
this[mkey].dataSource = dataSource;
|
|
|
|
|
this.pageLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -118,15 +119,14 @@ class Distribution {
|
|
|
|
|
/**
|
|
|
|
|
* 计算 同比, 环比
|
|
|
|
|
*/
|
|
|
|
|
const calcDiff = ({ result, resultToY, resultToQ }) => {
|
|
|
|
|
if (isEmpty(resultToY) || isEmpty(resultToQ)) {
|
|
|
|
|
// return result;
|
|
|
|
|
}
|
|
|
|
|
const initialDataWithAllKeys = unique([].concat(result, resultToY, resultToQ).map((ele) => `${ele.key}@${ele.label}`)).reduce((r, v) => {
|
|
|
|
|
const [key, label] = String(v).split('@');
|
|
|
|
|
r.push({key: Number(key), label, SumML: 0, ConfirmOrder: 0, SumOrder: 0, SumMLPercent: 0, ConfirmOrderPercent: 0, SumOrderPercent: 0});
|
|
|
|
|
return r;
|
|
|
|
|
}, []).sort(sortBy('key'));
|
|
|
|
|
const calcDiff = ({ result, resultToY, resultToQ }, keySort) => {
|
|
|
|
|
const initialDataWithAllKeys = unique([].concat(result, resultToY, resultToQ).map((ele) => `${ele.key}@${ele.label}`))
|
|
|
|
|
.reduce((r, v) => {
|
|
|
|
|
const [key, label] = String(v).split('@');
|
|
|
|
|
r.push({ key: Number(key), label, SumML: 0, ConfirmOrder: 0, SumOrder: 0, SumMLPercent: 0, ConfirmOrderPercent: 0, SumOrderPercent: 0 });
|
|
|
|
|
return r;
|
|
|
|
|
}, [])
|
|
|
|
|
.sort(keySort ? sortBy('key') : undefined);
|
|
|
|
|
const initialMapped = initialDataWithAllKeys.reduce((r, v) => ({ ...r, [v.key]: v }), {});
|
|
|
|
|
const resultMapped = result.reduce((r, v) => ({ ...r, [v.key]: v }), cloneDeep(initialMapped));
|
|
|
|
|
const resultToYMapped = resultToY.reduce((r, v) => ({ ...r, [v.key]: v }), cloneDeep(initialMapped));
|
|
|
|
|