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

View File

@ -11,21 +11,27 @@
</pricelist>
</template>
<script lang="ts">
import { defineComponent, onBeforeMount, ref } from 'vue';
import { defineComponent, onBeforeMount, computed } from 'vue';
import CalculationTable from '../components/CalculationTable.vue';
import Pricelist from 'src/plugins/pricelist/components/Pricelist.vue';
import { usePricelistStore } from 'src/plugins/pricelist/store';
import { useMainStore } from 'src/stores';
export default defineComponent({
name: 'InnerPricelist',
components: { Pricelist, CalculationTable },
setup() {
const store = usePricelistStore();
const mainStore = useMainStore();
onBeforeMount(() => {
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 };
},
});

View File

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

View File

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