salix/modules/route/front/summary/index.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-03-22 10:10:23 +00:00
import ngModule from '../module';
2020-11-23 12:41:51 +00:00
import Summary from 'salix/components/summary';
2019-03-22 10:10:23 +00:00
import './style.scss';
2020-11-23 12:41:51 +00:00
class Controller extends Summary {
2019-03-22 10:10:23 +00:00
set route(value) {
this._route = value;
if (value && value.id)
this.getSummary();
}
sumPackages() {
this.packagesTotal = 0;
2019-03-25 12:16:34 +00:00
this.summary.tickets.forEach(ticket => {
2019-03-22 10:10:23 +00:00
this.packagesTotal += ticket.packages;
});
}
get isDelivery() {
return this.aclService.hasAny(['delivery']);
}
2019-03-22 10:10:23 +00:00
get route() {
return this._route;
}
getSummary() {
this.$http.get(`Routes/${this.route.id}/summary`).then(response => {
2019-03-22 10:10:23 +00:00
this.summary = response.data;
2019-03-25 12:16:34 +00:00
if (response.data && response.data.tickets)
2019-03-22 10:10:23 +00:00
this.sumPackages();
});
}
2023-03-01 13:22:25 +00:00
goToBuscaman(ticket) {
if (!this.route.vehicleFk)
throw new UserError(`The route doesn't have a vehicle`);
let query = `Routes/${this.route.vehicleFk}/getDeliveryPoint`;
this.$http.get(query).then(response => {
if (!response.data)
throw new UserError(`The route's vehicle doesn't have a delivery point`);
const address = response.data + '+to:' + ticket.postalCode + ' ' + ticket.city + ' ' + ticket.street;
const url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
window.open(url + encodeURI(address), '_blank');
});
}
2019-03-22 10:10:23 +00:00
}
ngModule.vnComponent('vnRouteSummary', {
2019-03-22 10:10:23 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
route: '<'
}
});