统计分布: 显示同比, 环比. +顾问参数

feature/2.0-sales-trade
Lei OT 2 years ago
parent aab6601b10
commit 921106af1d

@ -19,7 +19,7 @@ export const VSTag = (props) => {
{data1} vs {data2} {data1} vs {data2}
</div> */} </div> */}
<Tag icon={<CaretIcon />} color={tagColor}> <Tag icon={<CaretIcon />} color={tagColor}>
{diffPercent} <span>%</span> {diffPercent}<span>%</span>{' '}<span>{diffData}</span>
</Tag> </Tag>
</span> </span>
); );

@ -148,7 +148,7 @@ export default observer((props) => {
}))(dataSource?.[0] || {}); }))(dataSource?.[0] || {});
tableData.unshift(yearRow); tableData.unshift(yearRow);
console.log('sub', tableData, delKpiIds); console.log('sub', tableData, delKpiIds);
// return false; // debug: // return false; // debug:0
KPIStore.onSubmit(tableData, {delQueue: delKpiIds}).then((res) => { KPIStore.onSubmit(tableData, {delQueue: delKpiIds}).then((res) => {
if (res) { if (res) {
message.success('保存成功'); message.success('保存成功');

@ -156,7 +156,7 @@ export default observer((props) => {
return r.concat(allMonth, yearRow); return r.concat(allMonth, yearRow);
}, []); }, []);
// console.log('sub', tableData, 'del:', delKpiIds); // console.log('sub', tableData, 'del:', delKpiIds);
// return false; // debug: // return false; // debug:0
KPIStore.onSubmit(tableData, { delQueue: delKpiIds }).then((res) => { KPIStore.onSubmit(tableData, { delQueue: delKpiIds }).then((res) => {
if (res) { if (res) {
message.success('保存成功'); message.success('保存成功');

@ -156,7 +156,7 @@ export default observer((props) => {
return r.concat(allMonth, yearRow); return r.concat(allMonth, yearRow);
}, []); }, []);
// console.log('sub', tableData, 'del:', delKpiIds); // console.log('sub', tableData, 'del:', delKpiIds);
// return false; // debug: // return false; // debug:0
KPIStore.onSubmit(tableData, { delQueue: delKpiIds }).then((res) => { KPIStore.onSubmit(tableData, { delQueue: delKpiIds }).then((res) => {
if (res) { if (res) {
message.success('保存成功'); message.success('保存成功');

@ -155,7 +155,7 @@ export default observer((props) => {
return r.concat(allMonth, yearRow); return r.concat(allMonth, yearRow);
}, []); }, []);
// console.log('sub', tableData, 'del:', delKpiIds); // console.log('sub', tableData, 'del:', delKpiIds);
// return false; // debug: // return false; // debug:0
KPIStore.onSubmit(tableData, { delQueue: delKpiIds }).then((res) => { KPIStore.onSubmit(tableData, { delQueue: delKpiIds }).then((res) => {
if (res) { if (res) {
message.success('保存成功'); message.success('保存成功');

@ -1,6 +1,8 @@
import { makeAutoObservable, runInAction, toJS } from 'mobx'; import { makeAutoObservable, runInAction, toJS } from 'mobx';
import * as req from '../utils/request'; import * as req from '../utils/request';
import { isEmpty, pick, sortBy, fixTo2Decimals } from '../utils/commons'; import { DATE_FORMAT } from './../config';
import moment from 'moment';
import { isEmpty, pick, sortBy, fixTo2Decimals, cloneDeep, unique } from '../utils/commons';
const modelMapper = { const modelMapper = {
'tourDays': { url: '/service-Analyse2/GetTradeApartByTourDays' }, 'tourDays': { url: '/service-Analyse2/GetTradeApartByTourDays' },
@ -13,7 +15,7 @@ const modelMapper = {
'destinationCountry': { url: '/service-Analyse2/GetTradeApartByDestinationCountry' }, 'destinationCountry': { url: '/service-Analyse2/GetTradeApartByDestinationCountry' },
}; };
class Distribution { class Distribution {
constructor(appStore){ constructor(appStore) {
this.appStore = appStore; this.appStore = appStore;
makeAutoObservable(this); makeAutoObservable(this);
} }
@ -26,10 +28,17 @@ class Distribution {
const mkey = this.curTab; const mkey = this.curTab;
this[mkey] = { loading: true, dataSource: [] }; this[mkey] = { loading: true, dataSource: [] };
param.operator = param?.operator || -1; param.operator = param?.operator || -1;
param.DateToY1 = '2022-08-01'; // todo: 同比, 环比的参数 if (isEmpty(param.Date1) || isEmpty(param.Date2)) {
param.DateToY2 = '2022-08-31 23:59:59'; return false;
param.DateToQ1 = '2023-07-01'; // todo: 同比, 环比的参数 }
param.DateToQ2 = '2023-07-31 23:59:59'; // 环比的参数: 计算上一个时间段
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); const json = await req.fetchJSON(modelMapper[mkey].url, param);
if (json.errcode === 0) { if (json.errcode === 0) {
runInAction(() => { runInAction(() => {
@ -37,7 +46,7 @@ class Distribution {
this[mkey].loading = false; this[mkey].loading = false;
this[mkey].originData = json.result; this[mkey].originData = json.result;
const pickResult = dataLength > 20 ? json.result.slice(0, 30) : 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 = calcDiff({ result: pickResult, resultToY: json.resultToY, resultToQ: json.resultToQ });
this.pageLoading = false; this.pageLoading = false;
}); });
} }
@ -54,7 +63,7 @@ class Distribution {
runInAction(() => { runInAction(() => {
this.detailData.loading = false; this.detailData.loading = false;
this.detailData.dataSource = json.result; this.detailData.dataSource = json.result;
const daysData = json.result.filter(ele => ele.confirmDays).map(row => pick(row, ['o_id', 'tourdays', 'applyDays', 'personNum', 'country', 'startDate'])); const daysData = json.result.filter((ele) => ele.confirmDays).map((row) => pick(row, ['o_id', 'tourdays', 'applyDays', 'personNum', 'country', 'startDate']));
this.scatterDays = daysData; this.scatterDays = daysData;
}); });
} }
@ -82,7 +91,7 @@ class Distribution {
pageLoading = false; pageLoading = false;
detailData = { loading: false, dataSource: [], }; detailData = { loading: false, dataSource: [] };
scatterDays = []; scatterDays = [];
tourDays = { loading: false, dataSource: [] }; tourDays = { loading: false, dataSource: [] };
@ -102,24 +111,38 @@ const calcDiff = ({ result, resultToY, resultToQ }) => {
if (isEmpty(resultToY) || isEmpty(resultToQ)) { if (isEmpty(resultToY) || isEmpty(resultToQ)) {
// return result; // return result;
} }
const resultMapped = result.reduce((r,v) => ({...r, [v.key]: v}), {}); const initialDataWithAllKeys = unique([].concat(result, resultToY, resultToQ).map((ele) => `${ele.key}@${ele.label}`)).reduce((r, v) => {
const resultToYMapped = resultToY.reduce((r,v) => ({...r, [v.key]: v}), {}); const [key, label] = String(v).split('@');
const resultToQMapped = resultToQ.reduce((r,v) => ({...r, [v.key]: v}), {}); r.push({key: Number(key), label, SumML: 0, ConfirmOrder: 0, SumOrder: 0, SumMLPercent: 0, ConfirmOrderPercent: 0, SumOrderPercent: 0});
const afterCalc = result.map(row => { 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 = { const diff = {
SumMLY: resultToYMapped?.[row.key]?.SumML || 0, SumMLY: resultToYMapped?.[row.key]?.SumML || 0,
SumMLToY: resultToYMapped?.[row.key]?.SumML ? fixTo2Decimals((row.SumML-(resultToYMapped[row.key].SumML))/(resultToYMapped[row.key].SumML)*100) : 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, SumMLQ: resultToQMapped?.[row.key]?.SumML || 0,
SumMLToQ: resultToQMapped?.[row.key]?.SumML ? fixTo2Decimals((row.SumML-(resultToQMapped[row.key].SumML))/(resultToQMapped[row.key].SumML)*100) : 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, ConfirmOrderY: resultToYMapped?.[row.key]?.ConfirmOrder || 0,
ConfirmOrderToY: resultToYMapped?.[row.key]?.ConfirmOrder ? fixTo2Decimals((row.ConfirmOrder-(resultToYMapped[row.key].ConfirmOrder))/(resultToYMapped[row.key].ConfirmOrder)*100) : 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, ConfirmOrderQ: resultToQMapped?.[row.key]?.ConfirmOrder || 0,
ConfirmOrderToQ: resultToQMapped?.[row.key]?.ConfirmOrder ? fixTo2Decimals((row.ConfirmOrder-(resultToQMapped[row.key].ConfirmOrder))/(resultToQMapped[row.key].ConfirmOrder)*100) : 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 {...row, ...diff}; return { ...resultMapped[row.key], ...diff };
}); });
console.log(afterCalc, '=================='); // console.log(afterCalc, '==================');
return afterCalc; return afterCalc;
}; };

@ -56,38 +56,49 @@ export default observer(() => {
}; };
const columns = [ const columns = [
{ title: '', dataIndex: 'label' }, { title: '', dataIndex: 'label' },
{ title: '团数', dataIndex: 'ConfirmOrder', render: (v, r) => ( {
<> title: '团数',
<Space size={'large'}> dataIndex: 'ConfirmOrder',
<Text strong>{v}</Text> render: (v, r) => (
<Space direction={'vertical'}> <>
<span> <Row align={'middle'}>
<span>同比: </span> <VSTag diffPercent={r.ConfirmOrderToY} /> <Col flex="1 1 100px">
</span> <Text strong>{v}</Text>
<span> </Col>
<span>环比: </span> <VSTag diffPercent={r.ConfirmOrderToQ} /> <Col flex={'auto'}>
</span> <Space direction={'vertical'}>
</Space> <span>
</Space> <span>同比: </span> <VSTag diffPercent={r.ConfirmOrderToY} diffData={r.ConfirmOrderDiffY} />
</> </span>
<span>
) }, <span>环比: </span> <VSTag diffPercent={r.ConfirmOrderToQ} diffData={r.ConfirmOrderDiffQ} />
</span>
</Space>
</Col>
</Row>
</>
),
},
{ {
title: '业绩', title: '业绩',
dataIndex: 'SumML', dataIndex: 'SumML',
render: (v, r) => ( render: (v, r) => (
<> <>
<Space size={'large'}> <Row align={'middle'}>
<Text strong>{dataFieldAlias.SumML.formatter(v)}</Text> <Col flex="1 1 100px">
<Space direction={'vertical'}> <Text strong>{dataFieldAlias.SumML.formatter(v)}</Text>
<span> </Col>
<span>同比: </span> <VSTag diffPercent={r.SumMLToY} /> <Col flex={'auto'}>
</span> <Space direction={'vertical'}>
<span> <span>
<span>环比: </span> <VSTag diffPercent={r.SumMLToQ} /> <span>同比: </span> <VSTag diffPercent={r.SumMLToY} diffData={dataFieldAlias.SumML.formatter(r.SumMLDiffY)} />
</span> </span>
</Space> <span>
</Space> <span>环比: </span> <VSTag diffPercent={r.SumMLToQ} diffData={dataFieldAlias.SumML.formatter(r.SumMLDiffQ)} />
</span>
</Space>
</Col>
</Row>
</> </>
), ),
}, },

Loading…
Cancel
Save