salix/modules/item/front/descriptor/index.js

71 lines
1.6 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
2020-04-25 09:50:04 +00:00
import Descriptor from 'salix/components/descriptor';
import './style.scss';
2020-04-25 09:50:04 +00:00
class Controller extends Descriptor {
get item() {
return this.entity;
2018-11-12 12:12:25 +00:00
}
set item(value) {
this.entity = value;
2018-11-12 12:12:25 +00:00
}
get entity() {
return super.entity;
2018-11-12 12:12:25 +00:00
}
set entity(value) {
super.entity = value;
this.updateStock();
2019-02-18 12:31:57 +00:00
}
loadData() {
return this.getData(`Items/${this.id}/getCard`)
.then(res => this.entity = res.data);
2019-02-18 12:31:57 +00:00
}
updateStock() {
2019-02-18 06:57:15 +00:00
this.available = null;
this.visible = null;
if (!this.item) return;
2019-02-15 15:04:24 +00:00
const params = {
warehouseFk: this.item.itemType.warehouseFk
};
2018-11-12 12:12:25 +00:00
return this.$http.get(`Items/${this.id}/getVisibleAvailable`, {params})
.then(res => {
this.available = res.data.available;
this.visible = res.data.visible;
});
}
saveRegularize() {
const params = {
itemFk: this.id,
quantity: parseInt(this.quantity),
warehouseFk: this.warehouseFk
};
2018-11-12 12:12:25 +00:00
return this.$http.post(`Items/regularize`, params)
.then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.updateStock();
2018-11-12 12:12:25 +00:00
});
}
clearRegularizeDialog() {
this.warehouseFk = null;
this.quantity = null;
}
}
2020-04-25 09:50:04 +00:00
ngModule.vnComponent('vnItemDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
2020-04-25 09:50:04 +00:00
item: '<'
}
});