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';
|
2023-03-02 10:33:55 +00:00
|
|
|
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-02 12:55:47 +00:00
|
|
|
}
|
|
|
|
|
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') {
|
2023-07-12 11:08:46 +00:00
|
|
|
const today = Date.vnNew();
|
|
|
|
const shippedFrom = new Date(today.getTime());
|
|
|
|
shippedFrom.setDate(today.getDate() - 30);
|
2023-06-26 08:49:09 +00:00
|
|
|
shippedFrom.setHours(0, 0, 0, 0);
|
|
|
|
|
2023-07-12 11:08:46 +00:00
|
|
|
const shippedTo = new Date(today.getTime());
|
2023-06-26 08:49:09 +00:00
|
|
|
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)
|
2023-03-02 14:10:17 +00:00
|
|
|
.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'});
|
2023-03-02 14:10:17 +00:00
|
|
|
});
|
2021-01-29 10:45:35 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 10:33:55 +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
|
|
|
}
|
2023-03-02 12:55:47 +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');
|
2023-03-02 12:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-29 10:45:35 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnTravelSearchPanel', {
|
2018-11-13 06:44:03 +00:00
|
|
|
template: require('./index.html'),
|
2023-03-02 10:33:55 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
model: '<'
|
|
|
|
}
|
2018-11-13 06:44:03 +00:00
|
|
|
});
|