salix/client/order/src/prices-popover/index.js

63 lines
1.6 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
import './style.scss';
class Controller {
constructor($scope, $http) {
this.$ = $scope;
this.$http = $http;
this.totalBasquet = 0;
}
getTags() {
let filter = {
where: {itemFk: this.item.id,
priority: {gte: 4}},
order: 'priority ASC',
include: {relation: 'tag'}
};
this.$http.get(`/item/api/ItemTags?filter=${JSON.stringify(filter)}`).then(response => {
this.tags = response.data;
});
}
show(event, item) {
this.item = JSON.parse(JSON.stringify(item));
this.prices = this.item.prices;
this.getTags();
this.$.popover.parent = event.target;
this.$.popover.relocate();
this.$.popover.show();
}
clear() {
this.item = {};
this.tags = {};
this.prices = {};
this.totalBasquet = 0;
}
addQuantity(price) {
if (this.totalBasquet + price.grouping <= this.item.disponible) {
price.quantity += price.grouping;
this.totalBasquet = this.totalBasquet + price.grouping;
}
}
save() {
let params = {
warehouseFk: warehouseFk,
itemFk: itemFk,
quantity: quantity
};
this.$http.post(`/order/api/OrderRows/new`, params).then(response => {
this.tags = response.data;
});
}
}
Controller.$inject = ['$scope', '$http'];
ngModule.component('vnOrderPricesPopover', {
template: require('./index.html'),
controller: Controller
});