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

97 lines
2.4 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 {
2020-11-27 12:10:39 +00:00
constructor($element, $, $rootScope) {
super($element, $);
this.$rootScope = $rootScope;
}
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 = {
2020-05-26 08:37:52 +00:00
warehouseFk: this.item.itemType.warehouseFk,
dated: this.dated
};
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;
}
onCloneAccept() {
this.$http.post(`Items/${this.item.id}/clone`)
.then(res => this.$state.go('item.card.tags', {id: res.data.id}));
}
2020-11-27 12:10:39 +00:00
onUploadResponse() {
const timestamp = new Date().getTime();
const src = this.$rootScope.imagePath('catalog', '200x200', this.item.id);
const zoomSrc = this.$rootScope.imagePath('catalog', '1600x900', this.item.id);
const newSrc = `${src}&t=${timestamp}`;
const newZoomSrc = `${zoomSrc}&t=${timestamp}`;
this.$.photo.setAttribute('src', newSrc);
this.$.photo.setAttribute('zoom-image', newZoomSrc);
}
}
2020-11-27 12:10:39 +00:00
Controller.$inject = ['$element', '$scope', '$rootScope'];
2020-04-25 09:50:04 +00:00
ngModule.vnComponent('vnItemDescriptor', {
template: require('./index.html'),
controller: Controller,
bindings: {
2020-05-26 08:37:52 +00:00
item: '<',
2020-11-27 12:10:39 +00:00
dated: '<',
cardReload: '&'
}
});