136 lines
3.3 KiB
JavaScript
136 lines
3.3 KiB
JavaScript
import ngModule from '../module';
|
|
import Component from 'core/lib/component';
|
|
|
|
class Controller extends Component {
|
|
constructor($element, $) {
|
|
super($element, $);
|
|
this.ticket = {};
|
|
this.clientFk = this.$params.clientFk;
|
|
}
|
|
|
|
$onInit() {
|
|
if (this.$params && this.$params.clientFk)
|
|
this.clientId = parseInt(this.$params.clientFk);
|
|
|
|
this.warehouseId = this.vnConfig.warehouseFk;
|
|
}
|
|
|
|
get ticket() {
|
|
return this._ticket;
|
|
}
|
|
|
|
set ticket(value) {
|
|
if (value)
|
|
this._ticket = value;
|
|
}
|
|
|
|
get clientId() {
|
|
return this.ticket.clientFk;
|
|
}
|
|
|
|
set clientId(value) {
|
|
this.ticket.clientFk = value;
|
|
|
|
if (value) {
|
|
let filter = {
|
|
include: {
|
|
relation: 'defaultAddress',
|
|
scope: {
|
|
fields: ['id', 'agencyModeFk']
|
|
}
|
|
},
|
|
where: {id: value}
|
|
};
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
let query = `Clients?filter=${filter}`;
|
|
this.$http.get(query).then(res => {
|
|
const [client] = res.data;
|
|
this.defaultAddress = client.defaultAddress;
|
|
this.addressId = this.defaultAddress.id;
|
|
});
|
|
} else
|
|
this.addressId = null;
|
|
this.getAvailableAgencies();
|
|
}
|
|
|
|
get addressId() {
|
|
return this.ticket.addressFk;
|
|
}
|
|
|
|
set addressId(value) {
|
|
this.ticket.addressFk = value;
|
|
this.getAvailableAgencies();
|
|
}
|
|
|
|
get landed() {
|
|
return this.ticket.landed;
|
|
}
|
|
|
|
set landed(value) {
|
|
this.ticket.landed = value;
|
|
this.getAvailableAgencies();
|
|
}
|
|
|
|
get warehouseId() {
|
|
return this.ticket.warehouseFk;
|
|
}
|
|
|
|
set warehouseId(value) {
|
|
this.ticket.warehouseFk = value;
|
|
this.getAvailableAgencies();
|
|
}
|
|
|
|
get agencyModeId() {
|
|
return this.ticket.agencyModeFk;
|
|
}
|
|
|
|
set agencyModeId(value) {
|
|
this.ticket.agencyModeFk = value;
|
|
}
|
|
|
|
getAvailableAgencies() {
|
|
let ticket = this.ticket;
|
|
let params = {
|
|
warehouseFk: ticket.warehouseFk,
|
|
addressFk: ticket.addressFk,
|
|
landed: ticket.landed
|
|
};
|
|
|
|
if (params.warehouseFk && params.addressFk && params.landed) {
|
|
ticket.agencyModeFk = null;
|
|
|
|
this.$http.get(`Agencies/getAgenciesWithWarehouse`, {params}).then(res => {
|
|
this._availableAgencies = res.data;
|
|
|
|
this.agencyModeId = this.defaultAddress.agencyModeFk;
|
|
});
|
|
}
|
|
}
|
|
|
|
onSubmit() {
|
|
this.createTicket();
|
|
}
|
|
|
|
createTicket() {
|
|
let params = {
|
|
clientId: this.ticket.clientFk,
|
|
landed: this.ticket.landed,
|
|
addressId: this.ticket.addressFk,
|
|
agencyModeId: this.ticket.agencyModeFk,
|
|
warehouseId: this.ticket.warehouseFk,
|
|
};
|
|
this.$http.post(`Tickets/new`, params).then(res => {
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
this.$state.go('ticket.card.summary', {id: res.data.id});
|
|
});
|
|
}
|
|
}
|
|
|
|
ngModule.component('vnTicketCreateCard', {
|
|
template: require('./card.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
ticket: '<?'
|
|
}
|
|
});
|