salix/modules/travel/front/search-panel/index.js

80 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-11-13 06:44:03 +00:00
import ngModule from '../module';
2018-12-27 11:54:16 +00:00
import SearchPanel from 'core/components/searchbar/search-panel';
import './style.scss';
2018-11-13 06:44:03 +00:00
2021-01-29 10:45:35 +00:00
class Controller extends SearchPanel {
constructor($, $element) {
super($, $element);
2023-03-10 09:05:16 +00:00
this.initFilter();
this.fetchData();
}
2023-03-10 09:05:16 +00:00
$onChanges() {
if (this.model)
this.applyFilters();
2021-01-29 10:45:35 +00:00
}
2023-03-10 09:05:16 +00:00
fetchData() {
this.$http.get('AgencyModes').then(res => {
this.agencyModes = res.data;
});
this.$http.get('Warehouses').then(res => {
this.warehouses = res.data;
});
this.$http.get('Continents').then(res => {
this.continents = res.data;
});
2021-01-29 10:45:35 +00:00
}
2023-03-10 09:05:16 +00:00
initFilter() {
this.filter = {};
if (this.$params.q) {
this.filter = JSON.parse(this.$params.q);
this.search = this.filter.search;
this.totalEntries = this.filter.totalEntries;
}
if (!this.filter.scopeDays) this.filter.scopeDays = 7;
}
applyFilters(param) {
2023-06-26 08:49:09 +00:00
if (typeof this.filter.scopeDays === 'number') {
const shippedFrom = Date.vnNew();
shippedFrom.setHours(0, 0, 0, 0);
const shippedTo = new Date(shippedFrom.getTime());
shippedTo.setDate(shippedTo.getDate() + this.filter.scopeDays);
shippedTo.setHours(23, 59, 59, 999);
Object.assign(this.filter, {shippedFrom, shippedTo});
}
2023-03-10 09:05:16 +00:00
this.model.applyFilter({}, this.filter)
.then(() => {
2023-03-10 09:05:16 +00:00
if (param && this.model._orgData.length === 1)
this.$state.go('travel.card.summary', {id: this.model._orgData[0].id});
else
this.$state.go(this.$state.current.name, {q: JSON.stringify(this.filter)}, {location: 'replace'});
});
2021-01-29 10:45:35 +00:00
}
removeParamFilter(param) {
2023-03-10 09:05:16 +00:00
if (this[param]) delete this[param];
delete this.filter[param];
this.applyFilters();
2021-01-29 10:45:35 +00:00
}
onKeyPress($event, param) {
if ($event.key === 'Enter') {
this.filter[param] = this[param];
2023-03-10 09:05:16 +00:00
this.applyFilters(param === 'search');
}
}
2021-01-29 10:45:35 +00:00
}
ngModule.vnComponent('vnTravelSearchPanel', {
2018-11-13 06:44:03 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
model: '<'
}
2018-11-13 06:44:03 +00:00
});