81 lines
2.8 KiB
Vue
81 lines
2.8 KiB
Vue
<script setup lang="ts">
|
|
import { evepraisalAxiosInstance } from '@/service';
|
|
import { useStorage } from '@vueuse/core';
|
|
import { onMounted, ref, watch } from 'vue';
|
|
import { MarketOrderHistory, MarketResult, getHistory, jitaId } from ".";
|
|
import MarketReultTable from "./MarketResultTable.vue";
|
|
import { MarketType, getMarketType, getMarketTypes } from "./type";
|
|
|
|
type MarketItemStorage = {
|
|
typeID: number;
|
|
history: MarketOrderHistory[];
|
|
}
|
|
|
|
const item = ref("");
|
|
const itemsStorage = useStorage<MarketItemStorage[]>('market-items', []);
|
|
const items = ref<MarketResult[]>([]);
|
|
const addOrRelaod = async (type: MarketType) => {
|
|
const typeID = type.id;
|
|
const [history, price] = await Promise.all([
|
|
getHistory(jitaId, typeID),
|
|
evepraisalAxiosInstance.post(`/appraisal.json?market=jita&persist=no&raw_textarea=${type.name}`)
|
|
]);
|
|
const item = {
|
|
type,
|
|
history,
|
|
buy: price.data.appraisal.items[0].prices.buy.max,
|
|
sell: price.data.appraisal.items[0].prices.sell.min
|
|
};
|
|
|
|
if (items.value.some(i => i.type.id === typeID)) {
|
|
items.value = items.value.map(i => i.type.id === typeID ? item : i);
|
|
} else {
|
|
items.value = [ ...items.value, item];
|
|
}
|
|
}
|
|
const reloadAll = async () => {
|
|
items.value = await Promise.all(items.value.map( async i => ({ ...i, history: await getHistory(jitaId, i.type.id) })));
|
|
}
|
|
const addItem = async () => {
|
|
const type = await getMarketType(item.value.split('\t')[0]);
|
|
|
|
item.value = "";
|
|
addOrRelaod(type);
|
|
}
|
|
|
|
watch(items, itms => itemsStorage.value = itms.map(i => ({ typeID: i.type.id, history: i.history })));
|
|
onMounted(async () => {
|
|
if (itemsStorage.value.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const types = await getMarketTypes(itemsStorage.value.map(i => i.typeID));
|
|
const prices: any = (await evepraisalAxiosInstance.post(`/appraisal.json?market=jita&persist=no&raw_textarea=${types.map(t => t.name).join("%0A")}`)).data;
|
|
|
|
items.value = itemsStorage.value.map(i => {
|
|
const type = types.find(t => t.id === i.typeID) as MarketType;
|
|
const price = prices.appraisal.items.find((p: any) => p.typeID === i.typeID);
|
|
|
|
return {
|
|
...i,
|
|
type: type,
|
|
buy: price.prices.buy.max,
|
|
sell: price.prices.sell.min
|
|
};
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="grid mb-2 mt-4">
|
|
<div class="w-auto">
|
|
<span>Item: </span>
|
|
<input type="text" class="w-96" v-model="item" @keyup.enter="addItem" />
|
|
<button class="justify-self-end ms-2" @click="addItem">Add</button>
|
|
</div>
|
|
</div>
|
|
<template v-if="items.length > 0">
|
|
<hr />
|
|
<MarketReultTable :items="items" @relaod="type => addOrRelaod(type)" @relaodAll="reloadAll" />
|
|
</template>
|
|
</template> |