salix/modules/order/front/create/card.js

115 lines
2.7 KiB
JavaScript
Raw Normal View History

2018-07-09 11:54:43 +00:00
import ngModule from '../module';
2020-03-17 14:18:02 +00:00
import Component from 'core/lib/component';
2018-07-09 11:54:43 +00:00
2020-03-17 14:18:02 +00:00
class Controller extends Component {
constructor($element, $) {
super($element, $);
this.order = {};
2020-03-17 14:18:02 +00:00
this.clientFk = this.$params.clientFk;
}
$onInit() {
2020-03-17 14:18:02 +00:00
if (this.$params && this.$params.clientFk)
this.clientFk = this.$params.clientFk;
2018-07-09 11:54:43 +00:00
}
set order(value) {
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;
if (value) {
let filter = {
include: {
relation: 'defaultAddress',
scope: {
fields: 'id'
}
},
where: {id: value}
};
filter = encodeURIComponent(JSON.stringify(filter));
let query = `Clients?filter=${filter}`;
this.$http.get(query).then(res => {
if (res.data) {
let client = res.data[0];
let defaultAddress = client.defaultAddress;
this.addressFk = defaultAddress.id;
}
});
} else
this.addressFk = null;
2018-07-09 11:54:43 +00:00
}
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() {
2019-11-11 15:32:03 +00:00
let order = this.order;
order.agencyModeFk = null;
let params = {
addressFk: order.addressFk,
landed: order.landed
};
if (params.landed && params.addressFk) {
this.$http.get(`Agencies/landsThatDay`, {params})
.then(res => this._availableAgencies = res.data);
2018-07-09 11:54:43 +00:00
}
}
onSubmit() {
this.createOrder();
}
createOrder() {
let params = {
landed: this.order.landed,
2019-06-03 08:05:22 +00:00
addressId: this.order.addressFk,
agencyModeId: this.order.agencyModeFk
2018-07-09 11:54:43 +00:00
};
this.$http.post(`Orders/new`, params).then(res => {
2020-03-17 14:18:02 +00:00
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.$state.go('order.card.catalog', {id: res.data});
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
}
});