Files
gemory/src/pages/market/Acquisitions.vue
2024-06-18 12:02:56 +02:00

47 lines
1.6 KiB
Vue

<script setup lang="ts">
import { MarketTypePrice, getMarketTypes, useApraisalStore } from "@/market";
import { AcquiredType, AcquisitionResultTable, BuyModal, SellModal, useAcquiredTypesStore } from '@/market/acquisition';
import { ref, watch } from 'vue';
const buyModal = ref<typeof BuyModal>();
const sellModal = ref<typeof SellModal>();
const apraisalStore = useApraisalStore();
const acquiredTypesStore = useAcquiredTypesStore();
const items = ref<AcquiredType[]>([]);
const refresh = async () => await acquiredTypesStore.refresh();
watch(() => acquiredTypesStore.acquiredTypes, async itms => {
if (itms.length === 0) {
return;
}
const prices = await apraisalStore.getPrices(await getMarketTypes(itms.map(i => i.type)));
items.value = itms.map(i => {
const price = prices.find(p => p.type.id === i.type) as MarketTypePrice;
return {
...i,
type: price.type,
buy: price.buy,
sell: price.sell
};
});
}, { immediate: true })
</script>
<template>
<div class="mt-4">
<div class="flex">
<button class="ms-auto" @click="refresh">Refresh</button>
</div>
<template v-if="items.length > 0">
<AcquisitionResultTable :items="items" @buy="(types, price, buy, sell) => buyModal?.open(types[0].type, { 'Price': price, 'Buy': buy, 'Sell': sell })" @sell="types => sellModal?.open(types)" ignoredColums="date" />
<BuyModal ref="buyModal" />
<SellModal ref="sellModal" />
</template>
</div>
</template>