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

70 lines
2.0 KiB
JavaScript

import ngModule from '../module';
class Controller {
constructor($http, $state) {
this.$http = $http;
this.$state = $state;
this.filter = {
include: [
{relation: 'warehouse', scope: {fields: ['name']}},
{relation: 'ship'},
{relation: 'agencyMode', scope: {fields: ['name']}},
{relation: 'stowaway'},
{
relation: 'client',
scope: {
fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked', 'credit'],
include: {
relation: 'salesPerson',
fields: ['firstName', 'name'],
},
},
},
{
relation: 'state',
scope: {
fields: ['stateFk'],
include: {
relation: 'state',
fields: ['id', 'name'],
}
},
},
],
};
}
$onInit() {
this.getCard();
}
getCard() {
const json = encodeURIComponent(JSON.stringify(this.filter));
const query = `/ticket/api/Tickets/${this.$state.params.id}?filter=${json}`;
this.$http.get(query).then(res => {
if (res.data) {
this.ticket = res.data;
this.getDebt(res.data.client.id);
}
});
}
getDebt(id) {
const query = `/ticket/api/Clients/${id}/getDebt`;
this.$http.get(query).then(res => {
if (res.data)
this.ticket.client.debt = res.data.debt;
});
}
reload() {
this.getCard();
}
}
Controller.$inject = ['$http', '$state'];
ngModule.component('vnTicketCard', {
template: require('./index.html'),
controller: Controller
});