2020-07-20 09:31:47 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import SearchPanel from 'core/components/searchbar/search-panel';
|
2023-02-03 14:21:27 +00:00
|
|
|
import './style.scss';
|
2020-07-20 09:31:47 +00:00
|
|
|
|
|
|
|
class Controller extends SearchPanel {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2023-02-03 14:21:27 +00:00
|
|
|
}
|
2020-07-20 09:31:47 +00:00
|
|
|
|
2023-02-03 14:21:27 +00:00
|
|
|
$onInit() {
|
|
|
|
this.filter = {
|
|
|
|
isActive: true,
|
|
|
|
tags: []
|
|
|
|
};
|
|
|
|
}
|
2020-07-20 09:31:47 +00:00
|
|
|
|
2023-02-03 14:21:27 +00:00
|
|
|
changeCategory(id) {
|
|
|
|
if (this.filter.categoryFk != id) {
|
|
|
|
this.filter.categoryFk = id;
|
|
|
|
this.applyFilters();
|
2020-07-20 09:31:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-03 14:21:27 +00:00
|
|
|
removeItemFilter(param) {
|
|
|
|
this.filter[param] = null;
|
|
|
|
if (param == 'categoryFk') this.filter['typeFk'] = null;
|
|
|
|
this.applyFilters();
|
|
|
|
}
|
2020-07-20 09:31:47 +00:00
|
|
|
|
2023-02-03 14:21:27 +00:00
|
|
|
removeTag(tag) {
|
|
|
|
const index = this.filter.tags.indexOf(tag);
|
|
|
|
if (index > -1) this.filter.tags.splice(index, 1);
|
|
|
|
this.applyFilters();
|
2020-07-20 09:31:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 14:21:27 +00:00
|
|
|
onKeyPress($event) {
|
|
|
|
if ($event.key === 'Enter')
|
|
|
|
this.applyFilters();
|
|
|
|
}
|
2020-07-20 09:31:47 +00:00
|
|
|
|
2023-02-03 14:21:27 +00:00
|
|
|
applyFilters() {
|
|
|
|
for (let i = 0; i < this.filter.tags.length; i++) {
|
|
|
|
if (!this.filter.tags[i].value)
|
|
|
|
this.filter.tags.splice(i, 1);
|
2020-07-20 09:31:47 +00:00
|
|
|
}
|
2023-02-03 14:21:27 +00:00
|
|
|
return this.model.applyFilter({}, this.filter);
|
2020-07-20 09:31:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 14:21:27 +00:00
|
|
|
showTagInfo(itemTag) {
|
|
|
|
if (!itemTag.tagFk) return itemTag.value;
|
|
|
|
return `${this.tags.find(tag => tag.id == itemTag.tagFk).name}: ${itemTag.value}`;
|
2020-07-20 09:31:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.component('vnLatestBuysSearchPanel', {
|
|
|
|
template: require('./index.html'),
|
2023-02-03 14:21:27 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
model: '<'
|
|
|
|
}
|
2020-07-20 09:31:47 +00:00
|
|
|
});
|