salix/client/ticket/src/sale/sale.js

79 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-03-22 17:02:48 +00:00
import ngModule from '../module';
import FilterTicketList from '../filter-ticket-list';
2018-03-22 17:02:48 +00:00
class Controller extends FilterTicketList {
constructor($scope, $timeout, $stateParams, $http) {
super($scope, $timeout, $stateParams);
this.$ = $scope;
this.$timeout = $timeout;
this.onOrder('itemFk', 'ASC');
this.$http = $http;
}
get isChecked() {
let data = this.$.index.model.instances;
if (data)
for (let instance of data)
if (instance.checked)
return true;
return false;
}
onStateOkClick() {
let filter = {where: {code: "OK"}, fields: ["id"]};
let json = encodeURIComponent(JSON.stringify(filter));
this.$http.get(`/ticket/api/States?filter=${json}`).then(res => {
this.onStateChange(res.data[0].id);
});
}
onStateChange(value) {
let params = {ticketFk: this.$state.params.id, stateFk: value};
this.$http.post(`/ticket/api/TicketTrackings`, params).then(() => {
this.card.reload();
});
}
2018-03-26 12:55:10 +00:00
onRemoveLinesClick() {
let lines = {
delete: []
};
let data = this.$.index.model.instances;
if (data)
for (let i = 0; i < data.length;) {
if (data[i].checked) {
lines.delete.push(data[i].id);
data.splice(i, 1);
} else {
i++;
}
}
let query = `/ticket/api/Sales/crudSale`;
this.$http.post(query, lines);
}
showDescriptor(event, itemFk) {
this.$.descriptor.itemFk = itemFk;
this.$.descriptor.parent = event.target;
this.$.descriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
2018-03-26 12:55:10 +00:00
}
}
Controller.$inject = ['$scope', '$timeout', '$state', '$http'];
2018-03-26 12:55:10 +00:00
2018-03-22 17:02:48 +00:00
ngModule.component('vnTicketSale', {
template: require('./sale.html'),
controller: Controller,
bindings: {
ticket: '<'
},
require: {
card: '^vnTicketCard'
}
2018-03-22 17:02:48 +00:00
});