2021-02-13 13:11:25 +00:00
|
|
|
<template>
|
2021-03-18 16:23:57 +00:00
|
|
|
<div>
|
2021-03-28 11:40:41 +00:00
|
|
|
<q-table
|
2021-03-31 12:18:55 +00:00
|
|
|
class="full-width"
|
2021-03-28 11:40:41 +00:00
|
|
|
title="Getränke"
|
|
|
|
:columns="columns_drinks"
|
|
|
|
:rows="drinks"
|
|
|
|
row-key="name"
|
|
|
|
:visible-columns="visibleColumn"
|
2021-03-31 12:18:55 +00:00
|
|
|
:filter="search"
|
|
|
|
:filter-method="filter"
|
2021-03-28 11:40:41 +00:00
|
|
|
>
|
|
|
|
<template #top-right>
|
2021-03-31 12:18:55 +00:00
|
|
|
<div class="row q-gutter-sm">
|
|
|
|
<search-input
|
|
|
|
v-model="search"
|
|
|
|
:keys="[...columns_drinks, ...columns_volumes, ...columns_prices]"
|
|
|
|
/>
|
|
|
|
<q-select
|
|
|
|
v-model="visibleColumn"
|
|
|
|
multiple
|
|
|
|
filled
|
|
|
|
dense
|
|
|
|
options-dense
|
|
|
|
display-value="Sichtbarkeit"
|
|
|
|
emit-value
|
|
|
|
map-options
|
|
|
|
:options="[...columns_drinks, ...columns_volumes, ...columns_prices]"
|
|
|
|
option-value="name"
|
|
|
|
options-cover
|
|
|
|
/>
|
|
|
|
</div>
|
2021-03-28 11:40:41 +00:00
|
|
|
</template>
|
2021-03-21 22:25:22 +00:00
|
|
|
<template #body-cell-volumes="props">
|
|
|
|
<q-td :props="props">
|
|
|
|
<q-table
|
|
|
|
:columns="columns_volumes"
|
|
|
|
:rows="props.row.volumes"
|
|
|
|
hide-header
|
|
|
|
:hide-bottom="props.row.volumes.length < 5"
|
|
|
|
flat
|
2021-03-28 14:43:30 +00:00
|
|
|
:visible-columns="visibleColumn"
|
2021-03-21 22:25:22 +00:00
|
|
|
>
|
|
|
|
<template #body-cell-prices="props_volumes">
|
|
|
|
<q-td :props="props_volumes">
|
|
|
|
<q-table
|
|
|
|
:columns="columns_prices"
|
|
|
|
:rows="props_volumes.row.prices"
|
|
|
|
hide-header
|
|
|
|
:hide-bottom="props_volumes.row.prices.length < 5"
|
|
|
|
flat
|
2021-03-28 14:43:30 +00:00
|
|
|
:visible-columns="visibleColumn"
|
2021-03-21 22:25:22 +00:00
|
|
|
>
|
|
|
|
<template #body-cell-public="props_prices">
|
|
|
|
<q-td :props="props_prices">
|
|
|
|
<q-toggle v-model="props_prices.row.public" disable />
|
|
|
|
</q-td>
|
|
|
|
</template>
|
|
|
|
</q-table>
|
|
|
|
</q-td>
|
|
|
|
</template>
|
|
|
|
</q-table>
|
2021-02-13 13:11:25 +00:00
|
|
|
</q-td>
|
2021-03-18 16:23:57 +00:00
|
|
|
</template>
|
2021-03-28 11:40:41 +00:00
|
|
|
<template #body-cell-picture="drinks_props">
|
|
|
|
<q-td :props="drinks_props" style="min-width: 256px">
|
|
|
|
<q-img
|
|
|
|
loading="lazy"
|
|
|
|
:src="
|
|
|
|
drinks_props.row.uuid
|
|
|
|
? `/api/pricelist/picture/${drinks_props.row.uuid}?size=256`
|
|
|
|
: 'no-image.svg'
|
|
|
|
"
|
|
|
|
placeholder-src="no-image.svg"
|
2021-03-31 12:18:55 +00:00
|
|
|
fit="contain"
|
|
|
|
style="max-height: 300px"
|
2021-03-28 11:40:41 +00:00
|
|
|
>
|
|
|
|
<template #error>
|
|
|
|
<div class="absolute-full flex flex-center bg-negative text-white">
|
|
|
|
Cannot load image
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</q-img>
|
|
|
|
</q-td>
|
|
|
|
</template>
|
2021-02-13 13:11:25 +00:00
|
|
|
</q-table>
|
2021-03-18 16:23:57 +00:00
|
|
|
</div>
|
2021-02-13 13:11:25 +00:00
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
2021-03-28 14:43:30 +00:00
|
|
|
import { defineComponent, onBeforeMount, computed, ref } from 'vue';
|
2021-03-14 14:12:41 +00:00
|
|
|
import { usePricelistStore } from '../store';
|
2021-03-30 13:40:02 +00:00
|
|
|
import { useMainStore } from 'src/stores';
|
2021-03-31 12:18:55 +00:00
|
|
|
import SearchInput from './SearchInput.vue';
|
|
|
|
import { filter } from '../utils/filter';
|
2021-03-30 20:32:18 +00:00
|
|
|
function sort(a: string | number, b: string | number) {
|
|
|
|
if (a > b) return 1;
|
|
|
|
if (b > a) return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
2021-02-13 13:11:25 +00:00
|
|
|
export default defineComponent({
|
2021-03-18 16:23:57 +00:00
|
|
|
name: 'Pricelist',
|
2021-03-31 12:18:55 +00:00
|
|
|
components: { SearchInput },
|
2021-03-18 16:23:57 +00:00
|
|
|
filters: {
|
2021-02-13 13:11:25 +00:00
|
|
|
setVolume(volume: number) {
|
2021-03-18 16:23:57 +00:00
|
|
|
if (volume * 10 > 1) {
|
|
|
|
return `${volume}l`;
|
|
|
|
}
|
|
|
|
return `${volume * 100}cl`;
|
2021-02-13 13:11:25 +00:00
|
|
|
},
|
|
|
|
setCurrency(price: number) {
|
2021-03-18 16:23:57 +00:00
|
|
|
return `${price.toFixed(2)}€`;
|
2021-03-21 22:25:22 +00:00
|
|
|
},
|
2021-03-18 16:23:57 +00:00
|
|
|
},
|
2021-03-28 14:43:30 +00:00
|
|
|
props: {
|
|
|
|
public: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
2021-03-28 17:53:04 +00:00
|
|
|
setup() {
|
2021-03-28 14:43:30 +00:00
|
|
|
let user: string | null;
|
2021-03-18 16:23:57 +00:00
|
|
|
onBeforeMount(() => {
|
2021-03-14 14:12:41 +00:00
|
|
|
void store.getDrinks();
|
2021-03-28 14:43:30 +00:00
|
|
|
try {
|
|
|
|
user = mainStore.currentUser.userid;
|
|
|
|
} catch {
|
|
|
|
user = null;
|
|
|
|
}
|
2021-03-31 12:18:55 +00:00
|
|
|
|
|
|
|
if (user) {
|
|
|
|
store.getPriceCalcColumn(user);
|
|
|
|
}
|
2021-03-18 16:23:57 +00:00
|
|
|
});
|
2021-03-31 12:18:55 +00:00
|
|
|
const store = usePricelistStore();
|
2021-03-14 14:12:41 +00:00
|
|
|
const drinks = computed(() => store.drinks);
|
2021-03-21 22:25:22 +00:00
|
|
|
const columns_drinks = [
|
2021-03-28 11:40:41 +00:00
|
|
|
{
|
|
|
|
name: 'picture',
|
|
|
|
label: 'Bild',
|
2021-03-30 20:32:18 +00:00
|
|
|
align: 'center',
|
2021-03-28 11:40:41 +00:00
|
|
|
},
|
2021-03-18 16:23:57 +00:00
|
|
|
{
|
|
|
|
name: 'name',
|
|
|
|
label: 'Getränk',
|
2021-03-21 22:25:22 +00:00
|
|
|
field: 'name',
|
|
|
|
align: 'center',
|
2021-03-30 20:32:18 +00:00
|
|
|
sortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'drink_type',
|
|
|
|
label: 'Kategorie',
|
|
|
|
field: 'type',
|
|
|
|
format: (val: FG.DrinkType) => `${val.name}`,
|
|
|
|
sortable: true,
|
|
|
|
sort: (a: FG.DrinkType, b: FG.DrinkType) => sort(a.name, b.name),
|
2021-03-21 22:25:22 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'volumes',
|
|
|
|
label: 'Preise',
|
|
|
|
field: 'volumes',
|
|
|
|
align: 'center',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const columns_volumes = [
|
|
|
|
{
|
|
|
|
name: 'volume',
|
|
|
|
label: 'Inhalt',
|
|
|
|
field: 'volume',
|
|
|
|
format: (val: number) => `${val.toFixed(3)}L`,
|
|
|
|
align: 'left',
|
2021-03-18 16:23:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'prices',
|
|
|
|
label: 'Preise',
|
2021-03-21 22:25:22 +00:00
|
|
|
field: 'prices',
|
|
|
|
},
|
2021-03-18 16:23:57 +00:00
|
|
|
];
|
2021-03-21 22:25:22 +00:00
|
|
|
const columns_prices = [
|
|
|
|
{
|
|
|
|
name: 'price',
|
|
|
|
label: 'Preis',
|
|
|
|
field: 'price',
|
|
|
|
format: (val: number) => `${val.toFixed(2)}€`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'description',
|
|
|
|
label: 'Beschreibung',
|
|
|
|
field: 'description',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'public',
|
|
|
|
label: 'Öffentlich',
|
|
|
|
field: 'public',
|
|
|
|
},
|
|
|
|
];
|
2021-03-28 14:43:30 +00:00
|
|
|
|
|
|
|
const canBeVisible = createVisibleColumns();
|
|
|
|
const _visibleColumns = ref(canBeVisible);
|
2021-03-28 11:40:41 +00:00
|
|
|
const visibleColumn = computed({
|
2021-03-28 14:43:30 +00:00
|
|
|
get: () => {
|
|
|
|
if (user) {
|
|
|
|
return store.pricecalc_columns;
|
|
|
|
} else {
|
|
|
|
return _visibleColumns.value;
|
|
|
|
}
|
|
|
|
},
|
2021-03-28 11:40:41 +00:00
|
|
|
set: (val) => {
|
2021-03-28 14:43:30 +00:00
|
|
|
if (user) {
|
|
|
|
store.updatePriceCalcColumn(user, val);
|
|
|
|
} else {
|
|
|
|
_visibleColumns.value = val;
|
|
|
|
}
|
2021-03-28 11:40:41 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
const mainStore = useMainStore();
|
2021-03-28 14:43:30 +00:00
|
|
|
|
|
|
|
function createVisibleColumns() {
|
|
|
|
const retVal: Array<string> = [];
|
|
|
|
columns_drinks.forEach((drink) => retVal.push(drink.name));
|
|
|
|
columns_volumes.forEach((volume) => retVal.push(volume.name));
|
|
|
|
columns_prices.forEach((price) => {
|
|
|
|
if (user || price.name !== 'public') retVal.push(price.name);
|
|
|
|
});
|
|
|
|
return retVal;
|
|
|
|
}
|
2021-03-31 12:18:55 +00:00
|
|
|
const search = ref({ label: '', value: '', key: '' });
|
|
|
|
|
|
|
|
return {
|
|
|
|
columns_drinks,
|
|
|
|
columns_volumes,
|
|
|
|
columns_prices,
|
|
|
|
drinks,
|
|
|
|
visibleColumn,
|
|
|
|
search,
|
|
|
|
filter,
|
|
|
|
};
|
2021-03-21 22:25:22 +00:00
|
|
|
},
|
2021-03-18 16:23:57 +00:00
|
|
|
});
|
2021-02-13 13:11:25 +00:00
|
|
|
</script>
|