[CLEAR-39] Add searching products

This commit is contained in:
Gabriela Pałka 2020-01-19 18:02:45 +01:00
parent 95a9f9c664
commit b5af362a1d
2 changed files with 23 additions and 2 deletions

View File

@ -1,5 +1,9 @@
<template> <template>
<div> <div>
<Row type="flex" justify="center" style="margin-bottom: 20px">
<Input v-model="search" @on-change="debounce" search enter-button="Wyszukaj"
placeholder="Szukaj produktu..."/>
</Row>
<Table :columns="columns" :border="true" :data="data" :loading="loading"/> <Table :columns="columns" :border="true" :data="data" :loading="loading"/>
<Page @on-change="retrieveProducts" :total="pagination.total" style="margin-top:10px;"/> <Page @on-change="retrieveProducts" :total="pagination.total" style="margin-top:10px;"/>
</div> </div>
@ -40,14 +44,31 @@
total: 0 total: 0
}, },
loading: true, loading: true,
search: '',
debounceTimer: 0,
}; };
}, },
methods: { methods: {
resetData() {
this.data = [];
this.pagination = {total: 0};
this.retrieveProducts();
},
debounce(event) {
if (this.debounceTimer !== null) {
clearTimeout(this.debounceTimer);
}
this.debounceTimer = setTimeout(() => {
this.search = event.target.value;
this.resetData();
}, 800);
},
retrieveProducts(page = 1) { retrieveProducts(page = 1) {
this.loading = true; this.loading = true;
this.$axios.get('/product', { this.$axios.get('/product', {
params: { params: {
page: page page: page,
search: this.search
} }
}) })
.then((res) => { .then((res) => {

View File

@ -20,7 +20,7 @@
return { return {
productsListData: null productsListData: null
}; };
}, }
}; };
</script> </script>