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

125 lines
3.1 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
2020-04-25 09:50:04 +00:00
import Descriptor from 'salix/components/descriptor';
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;
if (this.warehouseFk) this.updateStock();
}
get warehouseFk() {
return this._warehouseFk;
}
set warehouseFk(value) {
this._warehouseFk = value;
if (value) {
this.updateStock();
this.getWarehouseName(value);
}
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.warehouseFk,
2020-05-26 08:37:52 +00:00
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() {
2023-01-16 14:18:24 +00:00
const timestamp = Date.vnNew().getTime();
2020-11-27 12:10:39 +00:00
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);
}
getWarehouseName(warehouseFk) {
this.showIcon = false;
const filter = {
where: {id: warehouseFk}
};
this.$http.get('Warehouses/findOne', {filter})
.then(res => {
this.warehouseText = this.$t('WarehouseFk', {
warehouseName: res.data.name
});
this.showIcon = true;
});
}
}
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: '&',
2023-02-06 11:24:26 +00:00
warehouseFk: '<'
}
});