salix/modules/entry/front/latest-buys-search-panel/index.js

62 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-07-20 09:31:47 +00:00
import ngModule from '../module';
import SearchPanel from 'core/components/searchbar/search-panel';
import './style.scss';
2020-07-20 09:31:47 +00:00
class Controller extends SearchPanel {
constructor($element, $) {
super($element, $);
}
2020-07-20 09:31:47 +00:00
$onInit() {
this.filter = {
isActive: true,
tags: []
};
}
2020-07-20 09:31:47 +00:00
changeCategory(id) {
if (this.filter.categoryFk != id) {
this.filter.categoryFk = id;
2023-02-07 11:30:30 +00:00
this.addFilters();
2020-07-20 09:31:47 +00:00
}
}
removeItemFilter(param) {
this.filter[param] = null;
if (param == 'categoryFk') this.filter['typeFk'] = null;
2023-02-07 11:30:30 +00:00
this.addFilters();
}
2020-07-20 09:31:47 +00:00
removeTag(tag) {
const index = this.filter.tags.indexOf(tag);
if (index > -1) this.filter.tags.splice(index, 1);
2023-02-07 11:30:30 +00:00
this.addFilters();
2020-07-20 09:31:47 +00:00
}
onKeyPress($event) {
if ($event.key === 'Enter')
2023-02-07 11:30:30 +00:00
this.addFilters();
}
2020-07-20 09:31:47 +00:00
2023-02-07 11:30:30 +00:00
addFilters() {
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-07 11:30:30 +00:00
return this.model.addFilter({}, this.filter);
2020-07-20 09:31:47 +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'),
controller: Controller,
bindings: {
model: '<'
}
2020-07-20 09:31:47 +00:00
});