From 851c5a0588fa021e7876961041e6e70f98b8c8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Wed, 14 Apr 2021 18:53:17 +0200 Subject: [PATCH] [pricelist] sync min_prices if changing --- .../pricelist/components/CalculationTable.vue | 16 ++++++-- .../CalculationTable/BuildManual.vue | 2 +- .../CalculationTable/DrinkPriceVolumes.vue | 10 ++--- .../pricelist/components/DrinkModify.vue | 37 +++++++++++++++---- .../pricelist/pages/InnerPricelist.vue | 2 +- 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/plugins/pricelist/components/CalculationTable.vue b/src/plugins/pricelist/components/CalculationTable.vue index a82ad75..ec221fc 100644 --- a/src/plugins/pricelist/components/CalculationTable.vue +++ b/src/plugins/pricelist/components/CalculationTable.vue @@ -141,7 +141,11 @@ - + @@ -276,7 +280,7 @@ export default defineComponent({ field: 'package_size', sortable: true, sort, - public: false + public: false, }, { name: 'cost_per_package', @@ -327,7 +331,7 @@ export default defineComponent({ }, filterable: true, sortable: false, - public: false + public: false, }, ]; const column_calc = [ @@ -372,7 +376,11 @@ export default defineComponent({ }, }); - const search_keys = computed(() => columns.filter((column) => column.filterable && ((props.public || props.nodetails) ? column.public : true))); + const search_keys = computed(() => + columns.filter( + (column) => column.filterable && (props.public || props.nodetails ? column.public : true) + ) + ); const pagination = ref({ sortBy: 'name', diff --git a/src/plugins/pricelist/components/CalculationTable/BuildManual.vue b/src/plugins/pricelist/components/CalculationTable/BuildManual.vue index 0c3ec0d..1674bca 100644 --- a/src/plugins/pricelist/components/CalculationTable/BuildManual.vue +++ b/src/plugins/pricelist/components/CalculationTable/BuildManual.vue @@ -31,7 +31,7 @@ export default defineComponent({ name: 'BuildManual', props: { steps: { - type: Array as PropType> || undefined, + type: (Array as PropType>) || undefined, required: true, }, editable: { diff --git a/src/plugins/pricelist/components/CalculationTable/DrinkPriceVolumes.vue b/src/plugins/pricelist/components/CalculationTable/DrinkPriceVolumes.vue index a036c25..7532034 100644 --- a/src/plugins/pricelist/components/CalculationTable/DrinkPriceVolumes.vue +++ b/src/plugins/pricelist/components/CalculationTable/DrinkPriceVolumes.vue @@ -7,11 +7,12 @@ swipeable control-color="primary" arrows + :keep-alive="false" >
@@ -93,7 +95,7 @@
) => val, @@ -179,10 +181,8 @@ export default defineComponent({ }); function updateVolume(_volume: DrinkPriceVolume) { - console.log('updateVolume', _volume); const index = volumes.value.findIndex((a) => a.id === _volume.id); if (index > -1) { - console.log('updateVolume old', volumes.value[index]); volumes.value[index].volume = calc_volume(_volume); } change(); diff --git a/src/plugins/pricelist/components/DrinkModify.vue b/src/plugins/pricelist/components/DrinkModify.vue index c155f4a..fb3fcb4 100644 --- a/src/plugins/pricelist/components/DrinkModify.vue +++ b/src/plugins/pricelist/components/DrinkModify.vue @@ -122,9 +122,9 @@ />
- + { //edit_drink.value = JSON.parse(JSON.stringify(props.drink)); edit_drink.value = clone(props.drink); + edit_volumes.value = clone(props.drink.volumes); }); + const key = ref(0); + const store = usePricelistStore(); const toDeleteObjects = ref({ @@ -183,7 +186,9 @@ export default defineComponent({ }); const edit_drink = ref(); + const edit_volumes = ref>([]); function save() { + (edit_drink.value).volumes = edit_volumes.value; emit('save', edit_drink.value, toDeleteObjects.value, drinkPic.value, deletePic.value); } @@ -191,15 +196,25 @@ export default defineComponent({ emit('cancel'); } function updateVolume(index: number) { - if (index > -1 && edit_drink.value) { - edit_drink.value.volumes[index].min_prices = calc_min_prices( - edit_drink.value.volumes[index], - edit_drink.value.cost_per_volume, + if (index > -1 && edit_volumes.value) { + edit_volumes.value[index].min_prices = calc_min_prices( + edit_volumes.value[index], + //edit_drink.value.cost_per_volume, + cost_per_volume.value, store.min_prices ); } } + function updateVolumes() { + setTimeout(() => { + edit_volumes.value?.forEach((_, index) => { + updateVolume(index); + }); + key.value++; + }, 50); + } + function deletePrice(price: FG.DrinkPrice) { toDeleteObjects.value.prices.push(price); } @@ -287,10 +302,14 @@ export default defineComponent({ const cost_per_volume = computed({ get: () => { + let retVal: number; if (auto_cost_per_volume.value) { - return calc_cost_per_volume(edit_drink.value); + retVal = calc_cost_per_volume(edit_drink.value); + } else { + retVal = (edit_drink.value).cost_per_volume; } - return (edit_drink.value).cost_per_volume; + updateVolumes(); + return retVal; }, set: (val: number) => ((edit_drink.value).cost_per_volume = val), }); @@ -316,6 +335,8 @@ export default defineComponent({ delete_drink, auto_cost_per_volume, cost_per_volume, + edit_volumes, + key, }; }, }); diff --git a/src/plugins/pricelist/pages/InnerPricelist.vue b/src/plugins/pricelist/pages/InnerPricelist.vue index 0699258..4e5f324 100644 --- a/src/plugins/pricelist/pages/InnerPricelist.vue +++ b/src/plugins/pricelist/pages/InnerPricelist.vue @@ -6,7 +6,7 @@ import { defineComponent } from 'vue'; import CalculationTable from '../components/CalculationTable.vue'; export default defineComponent({ name: 'InnerPricelist', - components: {CalculationTable}, + components: { CalculationTable }, setup() { return {}; },