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

94 lines
2.3 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, $state) {
2018-07-09 11:54:43 +00:00
this.$scope = $scope;
this.$http = $http;
this.translate = $translate;
this.vnApp = vnApp;
this.order = {};
this.$state = $state;
2018-07-09 11:54:43 +00:00
}
set order(value) {
2018-07-09 11:54:43 +00:00
if (value) {
this._order = value;
2018-07-09 11:54:43 +00:00
}
}
get order() {
return this._order;
2018-07-09 11:54:43 +00:00
}
set clientFk(value) {
this.order.clientFk = value;
2018-07-09 11:54:43 +00:00
this.addressFk = null;
}
get clientFk() {
return this.order.clientFk;
2018-07-09 11:54:43 +00:00
}
set addressFk(value) {
this.order.addressFk = value;
2018-07-17 11:04:24 +00:00
this.getAvailableAgencies();
2018-07-09 11:54:43 +00:00
}
get addressFk() {
return this.order.addressFk;
2018-07-09 11:54:43 +00:00
}
set landed(value) {
this.order.landed = value;
2018-07-17 11:04:24 +00:00
this.getAvailableAgencies();
2018-07-09 11:54:43 +00:00
}
get landed() {
return this.order.landed;
2018-07-09 11:54:43 +00:00
}
get warehouseFk() {
return this.order.warehouseFk;
2018-07-09 11:54:43 +00:00
}
2018-07-17 11:04:24 +00:00
getAvailableAgencies() {
this.order.agencyModeFk = null;
if (this.order.landed && this.order.addressFk) {
let filter = {addressFk: this.order.addressFk, landed: this.order.landed};
2018-07-09 11:54:43 +00:00
filter = encodeURIComponent(JSON.stringify(filter));
let query = `/api/Agencies/landsThatDay?filter=${filter}`;
this.$http.get(query).then(res => {
2018-07-17 11:04:24 +00:00
this._availableAgencies = res.data[0];
2018-07-09 11:54:43 +00:00
});
}
}
onSubmit() {
this.createOrder();
}
createOrder() {
let params = {
landed: this.order.landed,
addressFk: this.order.addressFk,
agencyModeFk: this.order.agencyModeFk
2018-07-09 11:54:43 +00:00
};
this.$http.post(`order/api/Orders/new`, params).then(res => {
this.vnApp.showSuccess(this.translate.instant('Data saved!'));
this.$state.go("order.card.catalogue", {id: res.data});
2018-07-09 11:54:43 +00:00
}).catch(e => {
this.vnApp.showError(this.translate.instant(e.data.error.message));
});
}
}
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate', '$state'];
2018-07-09 11:54:43 +00:00
ngModule.component('vnOrderCreateCard', {
2018-07-09 11:54:43 +00:00
template: require('./card.html'),
controller: Controller,
bindings: {
order: '<?'
2018-07-09 11:54:43 +00:00
}
});