You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
6.8 KiB
JavaScript
150 lines
6.8 KiB
JavaScript
import { makeAutoObservable, runInAction, toJS } from 'mobx';
|
|
import * as req from '../utils/request';
|
|
import { DATE_FORMAT } from './../config';
|
|
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' },
|
|
};
|
|
class Distribution {
|
|
constructor(appStore) {
|
|
this.appStore = appStore;
|
|
makeAutoObservable(this);
|
|
}
|
|
|
|
/**
|
|
* 各个类型的分布
|
|
*/
|
|
getApartData = async (param) => {
|
|
this.pageLoading = true;
|
|
const mkey = this.curTab;
|
|
this[mkey] = { loading: true, dataSource: [] };
|
|
param.operator = param?.operator || -1;
|
|
if (isEmpty(param.Date1) || isEmpty(param.Date2)) {
|
|
return false;
|
|
}
|
|
// 环比的参数: 计算上一个时间段
|
|
const [DateToQ1, DateToQ2] = [moment(param.Date1).subtract(moment(param.Date2).diff(param.Date1, 'days') + 1, 'days'), moment(param.Date1).subtract(1, 'days')];
|
|
// 同比的参数: 去年同期
|
|
const [DateToY1, DateToY2] = [moment(param.Date1).subtract(1, 'year'), moment(param.Date2).subtract(1, 'year')];
|
|
param.DateToY1 = DateToY1.format(DATE_FORMAT);
|
|
param.DateToY2 = DateToY2.format(`${DATE_FORMAT} 23:59:59`);
|
|
param.DateToQ1 = DateToQ1.format(DATE_FORMAT);
|
|
param.DateToQ2 = DateToQ2.format(`${DATE_FORMAT} 23:59:59`);
|
|
const json = await req.fetchJSON(modelMapper[mkey].url, param);
|
|
if (json.errcode === 0) {
|
|
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.pageLoading = false;
|
|
});
|
|
}
|
|
return this[mkey];
|
|
};
|
|
|
|
/**
|
|
* 明细
|
|
*/
|
|
getDetailData = async (param) => {
|
|
this.detailData.loading = true;
|
|
const json = await req.fetchJSON('/service-Analyse2/GetTradeApartDetail', param);
|
|
if (json.errcode === 0) {
|
|
runInAction(() => {
|
|
this.detailData.loading = false;
|
|
this.detailData.dataSource = json.result;
|
|
const daysData = json.result.filter((ele) => ele.confirmDays).map((row) => pick(row, ['o_id', 'tourdays', 'applyDays', 'personNum', 'country', 'startDate']));
|
|
this.scatterDays = daysData;
|
|
});
|
|
}
|
|
return this.detailData;
|
|
};
|
|
|
|
resetData = () => {
|
|
// this.detailData = { loading: false, dataSource: [] };
|
|
// this.scatterDays = [];
|
|
|
|
this.tourDays = { loading: false, dataSource: [] };
|
|
this.PML = { loading: false, dataSource: [] };
|
|
this.ConfirmDays = { loading: false, dataSource: [] };
|
|
this.ApplyDays = { loading: false, dataSource: [] };
|
|
this.PersonNum = { loading: false, dataSource: [] };
|
|
this.destination = { loading: false, dataSource: [] };
|
|
this.GlobalDestination = { loading: false, dataSource: [] };
|
|
this.destinationCountry = { loading: false, dataSource: [] };
|
|
};
|
|
|
|
curTab = 'tourDays';
|
|
setCurTab(v) {
|
|
this.curTab = v;
|
|
}
|
|
|
|
pageLoading = false;
|
|
|
|
detailData = { loading: false, dataSource: [] };
|
|
scatterDays = [];
|
|
|
|
tourDays = { loading: false, dataSource: [] };
|
|
PML = { loading: false, dataSource: [] };
|
|
ConfirmDays = { loading: false, dataSource: [] };
|
|
ApplyDays = { loading: false, dataSource: [] };
|
|
PersonNum = { loading: false, dataSource: [] };
|
|
destination = { loading: false, dataSource: [] };
|
|
GlobalDestination = { loading: false, dataSource: [] };
|
|
destinationCountry = { loading: false, dataSource: [] };
|
|
}
|
|
|
|
/**
|
|
* 计算 同比, 环比
|
|
*/
|
|
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 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));
|
|
const resultToQMapped = resultToQ.reduce((r, v) => ({ ...r, [v.key]: v }), cloneDeep(initialMapped));
|
|
const afterCalc = initialDataWithAllKeys.map((row) => {
|
|
const diff = {
|
|
SumMLY: resultToYMapped?.[row.key]?.SumML || 0,
|
|
SumMLToY: resultToYMapped?.[row.key]?.SumML ? fixTo2Decimals(((resultMapped[row.key].SumML - resultToYMapped[row.key].SumML) / resultToYMapped[row.key].SumML) * 100) : 0,
|
|
SumMLQ: resultToQMapped?.[row.key]?.SumML || 0,
|
|
SumMLToQ: resultToQMapped?.[row.key]?.SumML ? fixTo2Decimals(((resultMapped[row.key].SumML - resultToQMapped[row.key].SumML) / resultToQMapped[row.key].SumML) * 100) : 0,
|
|
SumMLDiffY: resultMapped[row.key].SumML - resultToYMapped[row.key].SumML,
|
|
SumMLDiffQ: resultMapped[row.key].SumML - resultToQMapped[row.key].SumML,
|
|
|
|
ConfirmOrderY: resultToYMapped?.[row.key]?.ConfirmOrder || 0,
|
|
ConfirmOrderToY: resultToYMapped?.[row.key]?.ConfirmOrder
|
|
? fixTo2Decimals(((resultMapped[row.key].ConfirmOrder - resultToYMapped[row.key].ConfirmOrder) / resultToYMapped[row.key].ConfirmOrder) * 100)
|
|
: 0,
|
|
ConfirmOrderQ: resultToQMapped?.[row.key]?.ConfirmOrder || 0,
|
|
ConfirmOrderToQ: resultToQMapped?.[row.key]?.ConfirmOrder
|
|
? fixTo2Decimals(((resultMapped[row.key].ConfirmOrder - resultToQMapped[row.key].ConfirmOrder) / resultToQMapped[row.key].ConfirmOrder) * 100)
|
|
: 0,
|
|
ConfirmOrderDiffY: resultMapped[row.key].ConfirmOrder - resultToYMapped[row.key].ConfirmOrder,
|
|
ConfirmOrderDiffQ: resultMapped[row.key].ConfirmOrder - resultToQMapped[row.key].ConfirmOrder,
|
|
};
|
|
return { ...resultMapped[row.key], ...diff };
|
|
});
|
|
// console.log(afterCalc, '==================');
|
|
return afterCalc;
|
|
};
|
|
|
|
export default Distribution;
|