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

80 lines
2.4 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: 'invoiceOut', scope: {fields: ['id']}},
{relation: 'address'},
{relation: 'ship'},
{relation: 'agencyMode', scope: {fields: ['name']}},
{relation: 'stowaway'},
{
relation: 'client',
scope: {
fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked', 'credit'],
include: {
relation: 'salesPerson',
scope: {
fields: ['userFk'],
include: {
relation: 'user',
scope: {
fields: ['nickname']
}
}
}
},
},
},
{
relation: 'state',
scope: {
fields: ['stateFk'],
include: {
relation: 'state',
fields: ['id', 'name'],
}
},
},
],
};
}
$onInit() {
this.getCard();
}
getCard() {
const json = encodeURIComponent(JSON.stringify(this.filter));
const query = `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 = `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
});