flaschengeist-frontend/src/plugins/pricelist/components/CalculationTable/DrinkPriceVolumes.vue

150 lines
4.6 KiB
Vue
Raw Normal View History

<template>
<q-carousel
v-model="volume"
transition-prev="slide-right"
transition-next="slide-left"
animated
swipeable
control-color="primary"
navigation
arrows
>
2021-04-09 21:49:49 +00:00
<q-carousel-slide v-for="volume in volumes" :key="volume.id" :name="volume.id">
<q-input
2021-04-09 21:49:49 +00:00
v-model.number="volume.volume"
class="q-pa-sm"
2021-04-09 21:49:49 +00:00
:outlined="!editable"
:filled="editable"
:readonly="!editable"
dense
label="Inhalt"
mask="#.###"
fill-mask="0"
suffix="L"
2021-04-09 21:49:49 +00:00
min="0"
step="0.001"
/>
<div class="full-width row q-gutter-sm q-pa-sm justify-around">
<div v-for="(min_price, index) in volume.min_prices" :key="index">
<q-badge class="text-body1" color="primary"> {{ min_price.percentage }}% </q-badge>
<div class="text-body1">{{ min_price.price.toFixed(3) }}</div>
</div>
</div>
<div class="q-pa-sm">
<div v-for="(price, index) in volume.prices" :key="price.id">
<div class="fit row justify-around q-py-sm">
2021-04-09 21:49:49 +00:00
<div v-if="!editable" class="text-body1 col-xs-12 col-md-3">
{{ price.price.toFixed(2) }}
</div>
<q-input
v-else
v-model.number="price.price"
class="col-xs-12 col-md-3"
type="number"
min="0"
step="0.01"
suffix="€"
filled
dense
label="Preis"
/>
<div class="text-body1 col-xs-12 col-md-2">
<q-toggle
2021-04-09 21:49:49 +00:00
v-model="price.public"
:disable="!editable"
checked-icon="mdi-earth"
unchecked-icon="mdi-earth-off"
/>
</div>
2021-04-09 21:49:49 +00:00
<div v-if="!editable" class="text-body1 col-xs-12 col-md-5">
{{ price.description }}
</div>
2021-04-09 21:49:49 +00:00
<q-input
v-else
v-model="price.description"
class="col-xs-12 col-md-5"
filled
dense
label="Beschreibung"
/>
</div>
<q-separator v-if="index < volume.prices.length - 1" />
</div>
</div>
<div class="q-pa-sm">
<ingredients
v-model="volume.ingredients"
:editable="editable"
@update="updateVolume(volume)"
/>
</div>
</q-carousel-slide>
</q-carousel>
2021-04-09 21:49:49 +00:00
<q-btn-toggle v-model="volume" :options="options" />
</template>
<script lang="ts">
import { computed, defineComponent, PropType, ref, onBeforeMount, unref } from 'vue';
2021-04-09 21:49:49 +00:00
import { DrinkPriceVolume } from 'src/plugins/pricelist/store';
import Ingredients from 'src/plugins/pricelist/components/CalculationTable/Ingredients.vue';
import { calc_volume, clone } from '../../utils/utils';
export default defineComponent({
name: 'DrinkPriceVolume',
components: { Ingredients },
props: {
2021-04-09 21:49:49 +00:00
modelValue: {
type: Array as PropType<Array<DrinkPriceVolume>>,
required: true,
},
2021-04-09 21:49:49 +00:00
editable: {
type: Boolean,
default: false,
},
},
2021-04-09 21:49:49 +00:00
emits: {
'update:modelValue': (val: Array<DrinkPriceVolume>) => val,
},
setup(props, { emit }) {
onBeforeMount(() => {
//volumes.value = <Array<DrinkPriceVolume>>JSON.parse(JSON.stringify(props.modelValue));
volumes.value = clone(props.modelValue);
2021-04-09 21:49:49 +00:00
});
const volumes = ref<Array<DrinkPriceVolume>>([]);
const _volume = ref<number | undefined>();
const volume = computed<number | undefined>({
get: () => {
if (_volume.value !== undefined) {
return _volume.value;
}
2021-04-09 21:49:49 +00:00
if (volumes.value.length > 0) {
return volumes.value[0].id;
}
return undefined;
},
2021-04-09 21:49:49 +00:00
set: (val: number | undefined) => (_volume.value = val),
});
2021-04-09 21:49:49 +00:00
const options = computed<Array<{ label: string; value: number }>>(() => {
const retVal: Array<{ label: string; value: number }> = [];
volumes.value.forEach((volume: DrinkPriceVolume) => {
retVal.push({ label: `${<number>volume.volume}L`, value: volume.id });
});
return retVal;
});
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);
}
emit('update:modelValue', unref(volumes));
2021-04-09 21:49:49 +00:00
}
return { volumes, volume, options, updateVolume };
},
});
</script>
<style scoped></style>