salix/modules/ticket/front/component/index.js

83 lines
2.2 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
2020-03-18 07:35:59 +00:00
import Section from 'salix/components/section';
import './style.scss';
2020-03-18 07:35:59 +00:00
class Controller extends Section {
constructor($element, $) {
super($element, $);
this.filter = {
order: 'concept ASC',
include: [{
relation: 'item',
}, {
relation: 'components',
scope: {
fields: ['componentFk', 'value'],
include: {
relation: 'component',
scope: {
fields: ['typeFk', 'name'],
include: {
relation: 'componentType',
scope: {
fields: ['type', 'isBase']
}
}
}
}
}
}]
};
}
get ticket() {
return this._ticket;
}
set ticket(value) {
this._ticket = value;
if (!value) return;
this.getTheoricalPorts();
}
base() {
2020-03-18 07:35:59 +00:00
let sales = this.$.model.data;
let sum = 0;
if (!sales) return;
2018-11-06 09:49:38 +00:00
for (let sale of sales) {
for (let saleComponent of sale.components) {
if (saleComponent.component.componentType.isBase)
sum += sale.quantity * saleComponent.value;
2018-11-06 09:49:38 +00:00
}
}
return sum;
}
getTotal() {
let sales = this.$.model.data;
let total = 0;
if (!sales) return;
for (let sale of sales) {
for (let saleComponent of sale.components)
total += sale.quantity * saleComponent.value;
}
return total;
}
getTheoricalPorts() {
this.$http.get(`Tickets/${this.ticket.id}/freightPorts`)
.then(res => this.theoricalPorts = res.data);
console.log('this.THasdasdasdeoricalPorts', this.theoricalPorts);
}
}
ngModule.component('vnTicketComponents', {
template: require('./index.html'),
controller: Controller,
bindings: {
ticket: '<'
}
});