[pricelist][cocktailbuilder] fix new ingredient component

This commit is contained in:
Tim Gröger 2021-04-12 06:45:18 +02:00
parent b40b1064e7
commit 9b0679278c
1 changed files with 8 additions and 35 deletions

View File

@ -5,11 +5,10 @@
</q-card-section> </q-card-section>
<q-card-section> <q-card-section>
<ingredients <ingredients
v-model="volume.ingredients"
class="q-pa-sm" class="q-pa-sm"
:volume="volume" editable
:ingredients="volume.ingredients" @update:modelValue="update"
@addIngredient="addIngredient"
@deleteIngredient="deleteIngredient"
/> />
</q-card-section> </q-card-section>
<q-card-section> <q-card-section>
@ -30,34 +29,14 @@
import { defineComponent, onBeforeMount, ref } from 'vue'; import { defineComponent, onBeforeMount, ref } from 'vue';
import Ingredients from 'src/plugins/pricelist/components/CalculationTable/Ingredients.vue'; import Ingredients from 'src/plugins/pricelist/components/CalculationTable/Ingredients.vue';
import { DrinkPriceVolume, usePricelistStore } from 'src/plugins/pricelist/store'; import { DrinkPriceVolume, usePricelistStore } from 'src/plugins/pricelist/store';
import { calc_min_prices } from '../utils/utils';
export default defineComponent({ export default defineComponent({
name: 'CocktailBuilder', name: 'CocktailBuilder',
components: { Ingredients }, components: { Ingredients },
setup() { setup() {
onBeforeMount(() => { onBeforeMount(() => {
void store.get_min_prices().finally(() => { void store.get_min_prices().finally(() => {
store.min_prices.forEach((min_price) => { volume.value.min_prices = calc_min_prices(volume.value, undefined, store.min_prices);
(<DrinkPriceVolume>volume.value).min_prices.push({
percentage: min_price,
price: /*computed<number>(() => {
let retVal = 0;
let extraIngredientPrice = 0;
volume.value.ingredients.forEach((ingredient) => {
if (ingredient.drink_ingredient) {
const _drink = store.drinks.find(
(a) => a.id === ingredient.drink_ingredient?.ingredient_id
);
retVal +=
ingredient.drink_ingredient.volume * <number>(<unknown>_drink?.cost_per_volume);
}
if (ingredient.extra_ingredient) {
extraIngredientPrice += ingredient.extra_ingredient.price;
}
});
return (retVal * min_price) / 100 + extraIngredientPrice;
}) */ 0,
});
});
}); });
void store.getDrinks(); void store.getDrinks();
void store.getDrinkTypes(); void store.getDrinkTypes();
@ -74,17 +53,11 @@ export default defineComponent({
}; };
const volume = ref(emptyVolume); const volume = ref(emptyVolume);
function addIngredient(ingredient: FG.Ingredient) { function update() {
volume.value.ingredients.push(ingredient); volume.value.min_prices = calc_min_prices(volume.value, undefined, store.min_prices);
}
function deleteIngredient(ingredient: FG.Ingredient) {
const index = volume.value.ingredients.findIndex((a) => a.id === ingredient.id);
if (index > -1) {
volume.value.ingredients.splice(index, 1);
}
} }
return { volume, addIngredient, deleteIngredient }; return { volume, update };
}, },
}); });
</script> </script>