@@ -90,9 +110,11 @@
dense
/>
+
@@ -123,7 +146,7 @@
import { defineComponent, PropType, ref, onBeforeMount, computed } from 'vue';
import { Drink, DrinkPriceVolume, usePricelistStore } from '../store';
import DrinkPriceVolumes from './CalculationTable/DrinkPriceVolumes.vue';
-import { clone, calc_min_prices, DeleteObjects } from '../utils/utils';
+import { clone, calc_min_prices, DeleteObjects, calc_cost_per_volume } from '../utils/utils';
import BuildManual from 'src/plugins/pricelist/components/CalculationTable/BuildManual.vue';
import config from 'src/config';
export default defineComponent({
@@ -141,7 +164,8 @@ export default defineComponent({
toDeleteObjects: DeleteObjects,
drinkPic: File | undefined,
deletePic: boolean
- ) => drink && toDeleteObjects || drinkPic || deletePic,
+ ) => (drink && toDeleteObjects) || drinkPic || deletePic,
+ delete: () => true,
cancel: () => true,
},
setup(props, { emit }) {
@@ -235,6 +259,42 @@ export default defineComponent({
return 'no-image.svg';
});
+ const can_delete = computed(() => {
+ if (edit_drink.value) {
+ if (edit_drink.value.id < 0) {
+ return false;
+ }
+ const _edit_drink = edit_drink.value;
+ const test = _edit_drink.volumes ? _edit_drink.volumes.length === 0 : true;
+ console.log(test);
+ return test;
+ }
+ return false;
+ });
+
+ function delete_drink() {
+ emit('delete');
+ }
+
+ const auto_cost_per_volume = computed(
+ () =>
+ !!(
+ edit_drink.value?.cost_per_package &&
+ edit_drink.value?.package_size &&
+ edit_drink.value?.volume
+ )
+ );
+
+ const cost_per_volume = computed({
+ get: () => {
+ if (auto_cost_per_volume.value) {
+ return calc_cost_per_volume(edit_drink.value);
+ }
+ return (edit_drink.value).cost_per_volume;
+ },
+ set: (val: number) => ((edit_drink.value).cost_per_volume = val),
+ });
+
return {
edit_drink,
save,
@@ -251,6 +311,11 @@ export default defineComponent({
drinkPic,
imagePreview,
delete_pic,
+ types: computed(() => store.drinkTypes),
+ can_delete,
+ delete_drink,
+ auto_cost_per_volume,
+ cost_per_volume,
};
},
});
diff --git a/src/plugins/pricelist/store.ts b/src/plugins/pricelist/store.ts
index b44979d..86ebc66 100644
--- a/src/plugins/pricelist/store.ts
+++ b/src/plugins/pricelist/store.ts
@@ -147,15 +147,6 @@ export const usePricelistStore = defineStore({
});
},
async deletePrice(price: FG.DrinkPrice) {
- /*api
- .delete(`pricelist/prices/${price.id}`)
- .then(() => {
- const index = volume.prices.findIndex((a) => a.id == price.id);
- if (index > -1) {
- volume.prices.splice(index, 1);
- }
- })
- .catch((err) => console.warn(err));*/
await api.delete(`pricelist/prices/${price.id}`);
},
async deleteVolume(volume: DrinkPriceVolume, drink: Drink) {
@@ -166,19 +157,9 @@ export const usePricelistStore = defineStore({
}
},
async deleteIngredient(ingredient: FG.Ingredient) {
- /*api
- .delete(`pricelist/ingredients/${ingredient.id}`)
- .then(() => {
- const index = volume.ingredients.findIndex((a) => a.id === ingredient.id);
- if (index > -1) {
- volume.ingredients.splice(index, 1);
- }
- })
- .catch((err) => console.warn(err));
- */
await api.delete(`pricelist/ingredients/${ingredient.id}`);
},
- async setDrink(drink: FG.Drink) {
+ async setDrink(drink: Drink) {
const { data } = await api.post('pricelist/drinks', {
...drink,
});
@@ -189,6 +170,7 @@ export const usePricelistStore = defineStore({
});
this.drinks.push(_drink);
calc_all_min_prices(this.drinks, this.min_prices);
+ return _drink;
},
async updateDrink(drink: Drink) {
const { data } = await api.put(`pricelist/drinks/${drink.id}`, {
diff --git a/src/plugins/pricelist/utils/clone.js b/src/plugins/pricelist/utils/clone.js
deleted file mode 100644
index e69de29..0000000