58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
import ngModule from '../module';
|
|
import Summary from 'salix/components/summary';
|
|
import './style.scss';
|
|
|
|
class Controller extends Summary {
|
|
set route(value) {
|
|
this._route = value;
|
|
if (value && value.id)
|
|
this.getSummary();
|
|
}
|
|
|
|
sumPackages() {
|
|
this.packagesTotal = 0;
|
|
this.summary.tickets.forEach(ticket => {
|
|
this.packagesTotal += ticket.packages;
|
|
});
|
|
}
|
|
|
|
get isDelivery() {
|
|
return this.aclService.hasAny(['delivery']);
|
|
}
|
|
|
|
get route() {
|
|
return this._route;
|
|
}
|
|
|
|
getSummary() {
|
|
this.$http.get(`Routes/${this.route.id}/summary`).then(response => {
|
|
this.summary = response.data;
|
|
if (response.data && response.data.tickets)
|
|
this.sumPackages();
|
|
});
|
|
}
|
|
|
|
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');
|
|
});
|
|
}
|
|
}
|
|
|
|
ngModule.vnComponent('vnRouteSummary', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
route: '<'
|
|
}
|
|
});
|