From ac072369365ad5d4eea41a399d418a9ac48505fa Mon Sep 17 00:00:00 2001 From: Sirttas Date: Tue, 4 Jun 2024 14:39:48 +0200 Subject: [PATCH] total in acquisition table --- src/components/table/VirtualScrollTable.vue | 15 ++++- .../acquisition/AcquisitionResultTable.vue | 56 ++++++++++++++++++- src/style.css | 3 + 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/components/table/VirtualScrollTable.vue b/src/components/table/VirtualScrollTable.vue index d2d960d..4c2032f 100644 --- a/src/components/table/VirtualScrollTable.vue +++ b/src/components/table/VirtualScrollTable.vue @@ -6,7 +6,8 @@ interface Props { list?: any[]; itemHeight: number; headerHeight?: number; - bottom?: string; + footerHeight?: number; + bottom?: string; // FIXME: use css variable } @@ -35,11 +36,16 @@ const computedHeaderHeight = computed(() => { return h + 'px'; }) +const computedFooterHeight = computed(() => { + const h = props.footerHeight ?? 0; + + return h + 'px'; +}) const computedWrapperProps = computed(() => ({ ...wrapperProps.value, style: { ...wrapperProps.value.style, - height: `calc(${wrapperProps.value.style.height} + ${computedHeaderHeight.value} + 1px)` + height: `calc(${wrapperProps.value.style.height} + ${computedHeaderHeight.value} + ${computedFooterHeight.value} + 1px)` } })) const itemHeightStyle = computed(() => { @@ -72,6 +78,10 @@ div.table-container { @apply sticky z-10; top: -1px; } + >tfoot { + @apply bg-slate-600 sticky z-10; + bottom: -1px; + } >*>tr, >*>tr>td { height: v-bind(itemHeightStyle); } @@ -79,6 +89,7 @@ div.table-container { } &::-webkit-scrollbar-track { margin-top: v-bind(computedHeaderHeight); + margin-bottom: v-bind(computedFooterHeight); } } \ No newline at end of file diff --git a/src/market/acquisition/AcquisitionResultTable.vue b/src/market/acquisition/AcquisitionResultTable.vue index 594cff5..884673c 100644 --- a/src/market/acquisition/AcquisitionResultTable.vue +++ b/src/market/acquisition/AcquisitionResultTable.vue @@ -120,12 +120,39 @@ const { sortedArray, headerProps, showColumn } = useSort(computed(() => }) const getLineColor = (result: Result) => { if (result.precentProfit >= (threshold.value / 100)) { - return 'line-green'; + return 'line-green'; } else if (result.precentProfit < 0) { return 'line-red'; } return ''; } +const total = computed(() => { + if (sortedArray.value.length <= 1) { + return null; + } + + const first = sortedArray.value[0]; + + if (!first) { + return null; + } + + const sameItem = sortedArray.value.every(r => r.type.id === first.type.id); + const quantity = sameItem ? sortedArray.value.reduce((acc, r) => acc + r.quantity, 0) : 0; + const totalRemaining = sameItem ? sortedArray.value.reduce((acc, r) => acc + r.remaining, 0) : 0; + const price = sortedArray.value.reduce((acc, r) => acc + r.price * r.remaining, 0) / totalRemaining; + const precentProfit = marketTaxStore.calculateProfit(price, first.sell); + const iskProfit = sortedArray.value.reduce((acc, r) => acc + r.iskProfit, 0); + + return { + sameItem, + price, + remaining: totalRemaining, + quantity, + precentProfit, + iskProfit + }; +});