flaschengeist-frontend/src/plugins/pricelist/components/Pricelist.vue

62 lines
1.4 KiB
Vue
Raw Normal View History

<template>
<div>
2021-03-18 13:46:54 +00:00
<q-table title="Getränke" :columns="columns" :rows="drinks" row-key="name">
2021-03-14 12:52:58 +00:00
<template #body-cell-prices="{ row: { prices } }">
<q-td>
<div v-for="price in prices" :key="price.id" class="row">
<div class="col">
2021-03-14 12:52:58 +00:00
{{ setVolume(price.volume) }}
</div>
<div class="col">
2021-03-14 12:52:58 +00:00
{{ setCurrency(price.price) }}
</div>
<div class="col">
{{ price.description }}
</div>
</div>
</q-td>
</template>
</q-table>
</div>
</template>
<script lang="ts">
2021-03-14 14:12:41 +00:00
import { defineComponent, onBeforeMount, computed } from 'vue';
import { usePricelistStore } from '../store';
2021-03-14 12:52:58 +00:00
export default defineComponent({
name: 'Pricelist',
filters: {
setVolume(volume: number) {
if (volume * 10 > 1) {
return `${volume}l`;
}
return `${volume * 100}cl`;
},
setCurrency(price: number) {
return `${price.toFixed(2)}`;
2021-03-18 13:46:54 +00:00
}
},
2021-03-14 12:52:58 +00:00
setup() {
2021-03-14 14:12:41 +00:00
const store = usePricelistStore();
onBeforeMount(() => {
2021-03-14 14:12:41 +00:00
void store.getDrinks();
});
2021-03-14 14:12:41 +00:00
const drinks = computed(() => store.drinks);
const columns = [
{
name: 'name',
label: 'Getränk',
2021-03-18 13:46:54 +00:00
field: 'name'
},
{
name: 'prices',
label: 'Preise',
2021-03-18 13:46:54 +00:00
field: 'prices'
}
];
return { columns, drinks };
2021-03-18 13:46:54 +00:00
}
});
</script>