salix/modules/item/front/fixed-price-search-panel/index.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-01-18 13:16:39 +00:00
import ngModule from '../module';
import SearchPanel from 'core/components/searchbar/search-panel';
import './style.scss';
2021-01-18 13:16:39 +00:00
class Controller extends SearchPanel {
constructor($element, $) {
super($element, $);
2021-01-18 13:16:39 +00:00
}
$onInit() {
this.filter = {
tags: []
};
}
changeCategory(id) {
if (this.filter.categoryFk != id) {
this.filter.categoryFk = id;
this.addFilters();
}
}
removeItemFilter(param) {
this.filter[param] = null;
if (param == 'categoryFk') this.filter['typeFk'] = null;
this.addFilters();
}
removeTag(tag) {
const index = this.filter.tags.indexOf(tag);
if (index > -1) this.filter.tags.splice(index, 1);
this.addFilters();
}
onKeyPress($event) {
if ($event.key === 'Enter')
this.addFilters();
}
2021-01-18 13:16:39 +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);
}
return this.model.addFilter({}, this.filter);
}
showTagInfo(itemTag) {
if (!itemTag.tagFk) return itemTag.value;
return `${this.tags.find(tag => tag.id == itemTag.tagFk).name}: ${itemTag.value}`;
2021-01-18 13:16:39 +00:00
}
}
ngModule.vnComponent('vnFixedPriceSearchPanel', {
template: require('./index.html'),
controller: Controller,
bindings: {
model: '<'
}
2021-01-18 13:16:39 +00:00
});