@@ -79,6 +90,8 @@
import { defineComponent, onBeforeMount, computed, ref } from 'vue';
import { usePricelistStore } from '../store';
import { useMainStore } from 'src/stores';
+import SearchInput from './SearchInput.vue';
+import { filter } from '../utils/filter';
function sort(a: string | number, b: string | number) {
if (a > b) return 1;
if (b > a) return -1;
@@ -86,6 +99,7 @@ function sort(a: string | number, b: string | number) {
}
export default defineComponent({
name: 'Pricelist',
+ components: { SearchInput },
filters: {
setVolume(volume: number) {
if (volume * 10 > 1) {
@@ -105,12 +119,6 @@ export default defineComponent({
},
setup() {
let user: string | null;
- onBeforeMount(() => {
- if (user) {
- store.getPriceCalcColumn(user);
- }
- });
- const store = usePricelistStore();
onBeforeMount(() => {
void store.getDrinks();
try {
@@ -118,7 +126,12 @@ export default defineComponent({
} catch {
user = null;
}
+
+ if (user) {
+ store.getPriceCalcColumn(user);
+ }
});
+ const store = usePricelistStore();
const drinks = computed(() => store.drinks);
const columns_drinks = [
{
@@ -210,7 +223,17 @@ export default defineComponent({
});
return retVal;
}
- return { columns_drinks, columns_volumes, columns_prices, drinks, visibleColumn };
+ const search = ref({ label: '', value: '', key: '' });
+
+ return {
+ columns_drinks,
+ columns_volumes,
+ columns_prices,
+ drinks,
+ visibleColumn,
+ search,
+ filter,
+ };
},
});
diff --git a/src/plugins/pricelist/components/SearchInput.vue b/src/plugins/pricelist/components/SearchInput.vue
new file mode 100644
index 0000000..44b9da3
--- /dev/null
+++ b/src/plugins/pricelist/components/SearchInput.vue
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
diff --git a/src/plugins/pricelist/utils/filter.ts b/src/plugins/pricelist/utils/filter.ts
new file mode 100644
index 0000000..af4329e
--- /dev/null
+++ b/src/plugins/pricelist/utils/filter.ts
@@ -0,0 +1,27 @@
+import { Drink } from '../store';
+
+function filter(
+ rows: Array,
+ terms: { value: string; key: string },
+ cols: Array<{ name: string; label: string; field: string }>,
+ cellValue: { (col: { name: string; label: string; field: string }, row: Drink): string }
+) {
+ if (terms.value) {
+ return rows.filter((row) => {
+ if (!terms.key || terms.key === '') {
+ return cols.some((col) => {
+ const val = cellValue(col, row) + '';
+ const haystack = val === 'undefined' || val === 'null' ? '' : val.toLowerCase();
+ return haystack.indexOf(terms.value) !== -1;
+ });
+ }
+ const index = cols.findIndex((col) => col.name === terms.key);
+ const val = cellValue(cols[index], row) + '';
+ const haystack = val === 'undefined' || val === 'null' ? '' : val.toLowerCase();
+ return haystack.indexOf(terms.value) !== -1;
+ });
+ }
+ return rows;
+}
+
+export { filter };