[pricelist] add useroption for pricelist_view

This commit is contained in:
Tim Gröger 2021-04-15 22:54:40 +02:00
parent 8ee5c891a5
commit f7a6f3fbe1
4 changed files with 37 additions and 11 deletions

View File

@ -7,6 +7,7 @@
:filter="search" :filter="search"
:filter-method="filter" :filter-method="filter"
dense dense
:pagination="pagination"
> >
<template #top-right> <template #top-right>
<div class="row justify-end q-gutter-sm"> <div class="row justify-end q-gutter-sm">
@ -75,6 +76,7 @@ export default defineComponent({
onBeforeMount(() => { onBeforeMount(() => {
if (!props.public) { if (!props.public) {
user.value = useMainStore().currentUser.userid; user.value = useMainStore().currentUser.userid;
void store.getDrinks();
void store.getPriceCalcColumn(user.value); void store.getPriceCalcColumn(user.value);
} else { } else {
user.value = ''; user.value = '';
@ -191,6 +193,11 @@ export default defineComponent({
label: '', label: '',
}); });
const pagination = ref({
sortBy: 'name',
rowsPerPage: 10,
});
return { return {
drinks: computed(() => store.pricelist), drinks: computed(() => store.pricelist),
columns, columns,
@ -198,6 +205,7 @@ export default defineComponent({
options: _options, options: _options,
search, search,
filter, filter,
pagination,
}; };
}, },
}); });

View File

@ -11,21 +11,27 @@
</pricelist> </pricelist>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, onBeforeMount, ref } from 'vue'; import { defineComponent, onBeforeMount, computed } from 'vue';
import CalculationTable from '../components/CalculationTable.vue'; import CalculationTable from '../components/CalculationTable.vue';
import Pricelist from 'src/plugins/pricelist/components/Pricelist.vue'; import Pricelist from 'src/plugins/pricelist/components/Pricelist.vue';
import { usePricelistStore } from 'src/plugins/pricelist/store'; import { usePricelistStore } from 'src/plugins/pricelist/store';
import { useMainStore } from 'src/stores';
export default defineComponent({ export default defineComponent({
name: 'InnerPricelist', name: 'InnerPricelist',
components: { Pricelist, CalculationTable }, components: { Pricelist, CalculationTable },
setup() { setup() {
const store = usePricelistStore(); const store = usePricelistStore();
const mainStore = useMainStore();
onBeforeMount(() => { onBeforeMount(() => {
void store.getDrinks(); void store.getDrinks();
void store.getPriceListView(mainStore.currentUser.userid);
}); });
const list = ref(false); const list = computed({
get: () => store.pricelist_view,
set: (val: boolean) => store.updatePriceListView(mainStore.currentUser.userid, val),
});
return { list }; return { list };
}, },
}); });

View File

@ -78,6 +78,7 @@ export const usePricelistStore = defineStore({
min_prices: [] as Array<number>, min_prices: [] as Array<number>,
tags: [] as Array<FG.Tag>, tags: [] as Array<FG.Tag>,
pricecalc_columns: [] as Array<string>, pricecalc_columns: [] as Array<string>,
pricelist_view: false as boolean,
}), }),
actions: { actions: {
@ -263,6 +264,14 @@ export const usePricelistStore = defineStore({
await api.put<Array<string>>(`pricelist/users/${userid}/pricecalc_columns`, data); await api.put<Array<string>>(`pricelist/users/${userid}/pricecalc_columns`, data);
this.pricecalc_columns = data; this.pricecalc_columns = data;
}, },
async getPriceListView(userid: string) {
const { data } = await api.get<{ value: boolean }>(`pricelist/users/${userid}/pricelist`);
this.pricelist_view = data.value;
},
async updatePriceListView(userid: string, data: boolean) {
await api.put<Array<string>>(`pricelist/users/${userid}/pricelist`, { value: data });
this.pricelist_view = data;
},
}, },
getters: { getters: {
pricelist() { pricelist() {
@ -282,6 +291,7 @@ export const usePricelistStore = defineStore({
}); });
}); });
}); });
console.log(retVal);
return retVal; return retVal;
}, },
}, },

View File

@ -56,6 +56,7 @@ function calc_min_prices(
) { ) {
const retVal: Array<FG.MinPrices> = []; const retVal: Array<FG.MinPrices> = [];
volume.min_prices = []; volume.min_prices = [];
if (min_prices) {
min_prices.forEach((min_price) => { min_prices.forEach((min_price) => {
let computedMinPrice: number; let computedMinPrice: number;
if (cost_per_volume) { if (cost_per_volume) {
@ -65,6 +66,7 @@ function calc_min_prices(
} }
retVal.push({ percentage: min_price, price: computedMinPrice }); retVal.push({ percentage: min_price, price: computedMinPrice });
}); });
}
return retVal; return retVal;
} }