From 921106af1d7a7683d6da02e40b9493e03a356f17 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Sat, 7 Oct 2023 14:18:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=88=86=E5=B8=83:=20?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=90=8C=E6=AF=94,=20=E7=8E=AF=E6=AF=94.=20+?= =?UTF-8?q?=E9=A1=BE=E9=97=AE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Data.jsx | 2 +- src/components/kpi/OverviewPanel.jsx | 2 +- src/components/kpi/SubjectTable/Count.jsx | 2 +- src/components/kpi/SubjectTable/Profit.jsx | 2 +- src/components/kpi/SubjectTable/Rates.jsx | 2 +- src/stores/Distribution.js | 61 +++++++++++++------- src/views/Distribution.jsx | 65 +++++++++++++--------- 7 files changed, 85 insertions(+), 51 deletions(-) diff --git a/src/components/Data.jsx b/src/components/Data.jsx index 0dda6ff..e5c4891 100644 --- a/src/components/Data.jsx +++ b/src/components/Data.jsx @@ -19,7 +19,7 @@ export const VSTag = (props) => { {data1} vs {data2} */} } color={tagColor}> - {diffPercent} % + {diffPercent}%{' '}{diffData} ); diff --git a/src/components/kpi/OverviewPanel.jsx b/src/components/kpi/OverviewPanel.jsx index e0cac54..ff41007 100644 --- a/src/components/kpi/OverviewPanel.jsx +++ b/src/components/kpi/OverviewPanel.jsx @@ -148,7 +148,7 @@ export default observer((props) => { }))(dataSource?.[0] || {}); tableData.unshift(yearRow); console.log('sub', tableData, delKpiIds); - // return false; // debug: + // return false; // debug:0 KPIStore.onSubmit(tableData, {delQueue: delKpiIds}).then((res) => { if (res) { message.success('保存成功'); diff --git a/src/components/kpi/SubjectTable/Count.jsx b/src/components/kpi/SubjectTable/Count.jsx index 2c6fc50..cb8a363 100644 --- a/src/components/kpi/SubjectTable/Count.jsx +++ b/src/components/kpi/SubjectTable/Count.jsx @@ -156,7 +156,7 @@ export default observer((props) => { return r.concat(allMonth, yearRow); }, []); // console.log('sub', tableData, 'del:', delKpiIds); - // return false; // debug: + // return false; // debug:0 KPIStore.onSubmit(tableData, { delQueue: delKpiIds }).then((res) => { if (res) { message.success('保存成功'); diff --git a/src/components/kpi/SubjectTable/Profit.jsx b/src/components/kpi/SubjectTable/Profit.jsx index 79de9c8..331daa2 100644 --- a/src/components/kpi/SubjectTable/Profit.jsx +++ b/src/components/kpi/SubjectTable/Profit.jsx @@ -156,7 +156,7 @@ export default observer((props) => { return r.concat(allMonth, yearRow); }, []); // console.log('sub', tableData, 'del:', delKpiIds); - // return false; // debug: + // return false; // debug:0 KPIStore.onSubmit(tableData, { delQueue: delKpiIds }).then((res) => { if (res) { message.success('保存成功'); diff --git a/src/components/kpi/SubjectTable/Rates.jsx b/src/components/kpi/SubjectTable/Rates.jsx index f9a5e26..2cac5ac 100644 --- a/src/components/kpi/SubjectTable/Rates.jsx +++ b/src/components/kpi/SubjectTable/Rates.jsx @@ -155,7 +155,7 @@ export default observer((props) => { return r.concat(allMonth, yearRow); }, []); // console.log('sub', tableData, 'del:', delKpiIds); - // return false; // debug: + // return false; // debug:0 KPIStore.onSubmit(tableData, { delQueue: delKpiIds }).then((res) => { if (res) { message.success('保存成功'); diff --git a/src/stores/Distribution.js b/src/stores/Distribution.js index 3afff20..aa0b17a 100644 --- a/src/stores/Distribution.js +++ b/src/stores/Distribution.js @@ -1,6 +1,8 @@ import { makeAutoObservable, runInAction, toJS } from 'mobx'; 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 = { 'tourDays': { url: '/service-Analyse2/GetTradeApartByTourDays' }, @@ -13,7 +15,7 @@ const modelMapper = { 'destinationCountry': { url: '/service-Analyse2/GetTradeApartByDestinationCountry' }, }; class Distribution { - constructor(appStore){ + constructor(appStore) { this.appStore = appStore; makeAutoObservable(this); } @@ -26,10 +28,17 @@ class Distribution { const mkey = this.curTab; this[mkey] = { loading: true, dataSource: [] }; param.operator = param?.operator || -1; - param.DateToY1 = '2022-08-01'; // todo: 同比, 环比的参数 - param.DateToY2 = '2022-08-31 23:59:59'; - param.DateToQ1 = '2023-07-01'; // todo: 同比, 环比的参数 - param.DateToQ2 = '2023-07-31 23:59:59'; + 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(() => { @@ -37,7 +46,7 @@ class Distribution { 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 = calcDiff({ result: pickResult, resultToY: json.resultToY, resultToQ: json.resultToQ }); this.pageLoading = false; }); } @@ -54,7 +63,7 @@ class Distribution { 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'])); + const daysData = json.result.filter((ele) => ele.confirmDays).map((row) => pick(row, ['o_id', 'tourdays', 'applyDays', 'personNum', 'country', 'startDate'])); this.scatterDays = daysData; }); } @@ -82,7 +91,7 @@ class Distribution { pageLoading = false; - detailData = { loading: false, dataSource: [], }; + detailData = { loading: false, dataSource: [] }; scatterDays = []; tourDays = { loading: false, dataSource: [] }; @@ -102,24 +111,38 @@ const calcDiff = ({ result, resultToY, resultToQ }) => { if (isEmpty(resultToY) || isEmpty(resultToQ)) { // return result; } - const resultMapped = result.reduce((r,v) => ({...r, [v.key]: v}), {}); - const resultToYMapped = resultToY.reduce((r,v) => ({...r, [v.key]: v}), {}); - const resultToQMapped = resultToQ.reduce((r,v) => ({...r, [v.key]: v}), {}); - const afterCalc = result.map(row => { + 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((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, - 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, - 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, - 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; }; diff --git a/src/views/Distribution.jsx b/src/views/Distribution.jsx index fd7e10b..faeb07d 100644 --- a/src/views/Distribution.jsx +++ b/src/views/Distribution.jsx @@ -56,38 +56,49 @@ export default observer(() => { }; const columns = [ { title: '', dataIndex: 'label' }, - { title: '团数', dataIndex: 'ConfirmOrder', render: (v, r) => ( - <> - - {v} - - - 同比: - - - 环比: - - - - - - ) }, + { + title: '团数', + dataIndex: 'ConfirmOrder', + render: (v, r) => ( + <> + + + {v} + + + + + 同比: + + + 环比: + + + + + + ), + }, { title: '业绩', dataIndex: 'SumML', render: (v, r) => ( <> - - {dataFieldAlias.SumML.formatter(v)} - - - 同比: - - - 环比: - - - + + + {dataFieldAlias.SumML.formatter(v)} + + + + + 同比: + + + 环比: + + + + ), },