237 lines
7.2 KiB
Vue
237 lines
7.2 KiB
Vue
<template>
|
|
<div class="full-width">
|
|
<div
|
|
v-for="ingredient in ingredients"
|
|
:key="`volume:${volume.id},ingredient:${ingredient.id}`"
|
|
class="full-width row justify-evenly q-py-xs"
|
|
>
|
|
<div class="full-width row justify-evenly">
|
|
<div v-if="ingredient.drink_ingredient" class="col">
|
|
<div class="full-width row justify-evenly q-py-xs">
|
|
<div class="col">
|
|
{{ get_drink_ingredient_name(ingredient.drink_ingredient.drink_ingredient_id) }}
|
|
<q-popup-edit
|
|
v-model="ingredient.drink_ingredient.drink_ingredient_id"
|
|
buttons
|
|
label-cancel="Abbrechen"
|
|
label-set="Speichern"
|
|
@save="updateIngredient(ingredient, volume)"
|
|
>
|
|
<q-select
|
|
v-model="ingredient.drink_ingredient.drink_ingredient_id"
|
|
class="col q-px-sm"
|
|
label="Getränk"
|
|
filled
|
|
dense
|
|
:options="drinks"
|
|
option-label="name"
|
|
option-value="id"
|
|
emit-value
|
|
map-options
|
|
/>
|
|
</q-popup-edit>
|
|
</div>
|
|
<div class="col">
|
|
{{ ingredient.drink_ingredient.volume.toFixed(3) }}L
|
|
<q-popup-edit
|
|
v-model="ingredient.drink_ingredient.volume"
|
|
buttons
|
|
label-cancel="Abbrechen"
|
|
label-set="Speichern"
|
|
@save="updateIngredient(ingredient, volume)"
|
|
>
|
|
<q-input
|
|
v-model.number="ingredient.drink_ingredient.volume"
|
|
class="col q-px-sm"
|
|
label="Volume"
|
|
type="number"
|
|
filled
|
|
dense
|
|
suffix="L"
|
|
step="0.01"
|
|
min="0"
|
|
/>
|
|
</q-popup-edit>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div v-else-if="ingredient.extra_ingredient" class="col">
|
|
<div class="full-width row justify-evenly q-py-xs">
|
|
<div class="col">
|
|
{{ ingredient.extra_ingredient.name }}
|
|
</div>
|
|
<div class="col">{{ ingredient.extra_ingredient.price.toFixed(3) }}€</div>
|
|
</div>
|
|
<q-popup-edit
|
|
v-model="ingredient.extra_ingredient"
|
|
buttons
|
|
label-cancel="Abbrechen"
|
|
label-set="Speichern"
|
|
@save="updateIngredient(ingredient, volume)"
|
|
>
|
|
<q-select
|
|
v-model="ingredient.extra_ingredient"
|
|
filled
|
|
dense
|
|
:options="extra_ingredients"
|
|
option-label="name"
|
|
/>
|
|
</q-popup-edit>
|
|
</div>
|
|
<div class="col-1 row justify-end q-pa-xs">
|
|
<q-btn
|
|
icon="mdi-delete"
|
|
round
|
|
size="xs"
|
|
color="negative"
|
|
@click="deleteIngredient(ingredient, volume)"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<q-separator />
|
|
</div>
|
|
<div class="full-width row justify-end q-py-xs">
|
|
<q-btn size="sm" icon-right="add" color="positive" label="Zutat hinzufügen">
|
|
<q-menu anchor="center middle" self="center middle">
|
|
<div class="full-width row justify-around q-gutter-sm q-pa-sm">
|
|
<div class="col">
|
|
<q-select
|
|
v-model="newIngredient"
|
|
filled
|
|
dense
|
|
label="Zutat"
|
|
:options="[...drinks, ...extra_ingredients]"
|
|
option-label="name"
|
|
/>
|
|
</div>
|
|
<div class="col">
|
|
<q-input
|
|
v-if="newIngredient && newIngredient.volume"
|
|
v-model.number="newIngredientVolume"
|
|
filled
|
|
dense
|
|
label="Volume"
|
|
type="number"
|
|
steps="0.01"
|
|
min="0"
|
|
suffix="L"
|
|
/>
|
|
<q-input
|
|
v-else-if="newIngredient && newIngredient.price"
|
|
filled
|
|
dense
|
|
label="Preis"
|
|
disable
|
|
min="0"
|
|
steps="0.1"
|
|
:value="newIngredient.price.toFixed(3)"
|
|
suffix="€"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="full-width row jusitfy-between q-gutter-sm q-pa-sm">
|
|
<q-btn v-close-popup label="Abbrechen" @click="cancelAddIngredient" />
|
|
<q-btn
|
|
v-close-popup
|
|
label="Speichern"
|
|
color="positive"
|
|
@click="addIngredient(volume)"
|
|
/>
|
|
</div>
|
|
</q-menu>
|
|
</q-btn>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { computed, defineComponent, PropType, ref } from 'vue';
|
|
import { usePricelistStore } from '../../store';
|
|
|
|
export default defineComponent({
|
|
name: 'Ingredients',
|
|
props: {
|
|
ingredients: {
|
|
type: Array as PropType<FG.Ingredient[]>,
|
|
required: true,
|
|
},
|
|
volume: {
|
|
type: Object /*as PropType<DrinkPriceVolume>*/,
|
|
required: true,
|
|
},
|
|
},
|
|
setup() {
|
|
const store = usePricelistStore();
|
|
/*
|
|
const emptyIngredient: FG.Ingredient = {
|
|
id: -1,
|
|
drink_ingredient: undefined,
|
|
extra_ingredient: undefined,
|
|
};
|
|
const newIngredient = ref<FG.Drink | FG.ExtraIngredient>();
|
|
const newIngredientVolume = ref<number>(0);
|
|
function addIngredient(volume: DrinkPriceVolume) {
|
|
if ((<FG.Drink>newIngredient.value)?.volume && newIngredient.value) {
|
|
store.actions.setIngredient(
|
|
{
|
|
id: -1,
|
|
drink_ingredient: {
|
|
id: -1,
|
|
drink_ingredient_id: newIngredient.value.id,
|
|
volume: newIngredientVolume.value,
|
|
},
|
|
extra_ingredient: undefined,
|
|
},
|
|
volume
|
|
);
|
|
} else if (newIngredient.value) {
|
|
store.actions.setIngredient(
|
|
{
|
|
id: -1,
|
|
drink_ingredient: undefined,
|
|
extra_ingredient: >newIngredient.value,
|
|
},
|
|
volume
|
|
);
|
|
}
|
|
cancelAddIngredient();
|
|
}
|
|
function cancelAddIngredient() {
|
|
setTimeout(() => {
|
|
(newIngredient.value = undefined), (newIngredientVolume.value = 0);
|
|
}, 200);
|
|
}
|
|
function updateIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) {
|
|
store.actions.updateIngredient(ingredient, volume);
|
|
}
|
|
function deleteIngredient(ingredient: FG.Ingredient, volume: DrinkPriceVolume) {
|
|
store.actions.deleteIngredient(ingredient, volume);
|
|
}
|
|
const drinks = computed(() =>
|
|
store.drinks.filter((drink) => {
|
|
return drink.cost_price_pro_volume.value;
|
|
})
|
|
);
|
|
const extra_ingredients = computed(() => store.extraIngredients);
|
|
|
|
function get_drink_ingredient_name(id: number) {
|
|
return store.drinks.find((a) => a.id === id)?.name;
|
|
}
|
|
|
|
return {
|
|
addIngredient,
|
|
drinks,
|
|
extra_ingredients,
|
|
newIngredient,
|
|
newIngredientVolume,
|
|
cancelAddIngredient,
|
|
updateIngredient,
|
|
deleteIngredient,
|
|
get_drink_ingredient_name,
|
|
};*/
|
|
},
|
|
});
|
|
</script>
|
|
|
|
<style scoped></style>
|