salix/modules/ticket/front/basic-data/step-two/index.js

70 lines
1.5 KiB
JavaScript
Raw Normal View History

import ngModule from '../../module';
class Controller {
constructor($http) {
this.$http = $http;
}
$onInit() {
this.data.registerChild(this);
}
get ticket() {
return this._ticket;
}
set ticket(value) {
this._ticket = value;
if (!value) return;
2019-01-25 11:52:12 +00:00
this.getTotalPrice();
this.getTotalNewPrice();
this.getTotalDifferenceOfPrice();
}
onStepChange(state) {
return true;
}
2019-01-25 11:52:12 +00:00
getTotalPrice() {
let totalPrice = 0;
this.ticket.sale.items.forEach(item => {
let itemTotalPrice = item.quantity * item.price;
totalPrice += itemTotalPrice;
});
this.totalPrice = totalPrice;
}
getTotalNewPrice() {
let totalNewPrice = 0;
this.ticket.sale.items.forEach(item => {
if (item.component)
totalNewPrice += item.quantity * item.component.newPrice;
2019-01-25 11:52:12 +00:00
});
this.totalNewPrice = totalNewPrice;
}
getTotalDifferenceOfPrice() {
let totalPriceDifference = 0;
this.ticket.sale.items.forEach(item => {
if (item.component)
totalPriceDifference += item.component.difference;
2019-01-25 11:52:12 +00:00
});
this.totalPriceDifference = totalPriceDifference;
}
}
Controller.$inject = ['$http'];
ngModule.component('vnTicketBasicDataStepTwo', {
template: require('./index.html'),
controller: Controller,
bindings: {
ticket: '<'
},
require: {
data: '^vnTicketBasicData'
}
});