salix/client/ticket/src/create/card.js

94 lines
2.2 KiB
JavaScript
Raw Normal View History

2018-07-09 11:54:43 +00:00
import ngModule from '../module';
class Controller {
constructor($scope, $http, vnApp, $translate) {
this.$scope = $scope;
this.$http = $http;
this.translate = $translate;
this.vnApp = vnApp;
this.ticket = {};
}
set ticket(value) {
if (value) {
this._ticket = value;
}
}
get ticket() {
return this._ticket;
}
set clientFk(value) {
this.ticket.clientFk = value;
this.addressFk = null;
}
get clientFk() {
return this.ticket.clientFk;
}
set addressFk(value) {
this.ticket.addressFk = value;
this.getAvaibleAgencies();
}
get addressFk() {
return this.ticket.addressFk;
}
set landed(value) {
this.ticket.landed = value;
this.getAvaibleAgencies();
}
get landed() {
return this.ticket.landed;
}
get warehouseFk() {
return this.ticket.warehouseFk;
}
getAvaibleAgencies() {
this.ticket.agencyModeFk = null;
if (this.ticket.landed && this.ticket.addressFk) {
let filter = {addressFk: this.ticket.addressFk, landed: this.ticket.landed};
filter = encodeURIComponent(JSON.stringify(filter));
let query = `/api/Agencies/landsThatDay?filter=${filter}`;
this.$http.get(query).then(res => {
this._avaibleAgencies = res.data[0];
});
}
}
onSubmit() {
this.createOrder();
}
createOrder() {
let params = {
landed: this.ticket.landed,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk
};
this.$http.post(`order/api/Orders/new`, params).then(res => {
this.vnApp.showSuccess(this.translate.instant('Data saved!'));
return res.data.id;
}).catch(e => {
this.vnApp.showError(this.translate.instant(e.data.error.message));
});
}
}
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate'];
ngModule.component('vnTicketCreateCard', {
template: require('./card.html'),
controller: Controller,
bindings: {
ticket: '<?'
}
});