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

136 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-11-27 12:28:15 +00:00
import ngModule from '../module';
2020-03-18 07:35:59 +00:00
import Component from 'core/lib/component';
2018-11-27 12:28:15 +00:00
2020-03-18 07:35:59 +00:00
class Controller extends Component {
constructor($element, $) {
super($element, $);
2018-11-27 12:28:15 +00:00
this.ticket = {};
2020-03-18 07:35:59 +00:00
this.clientFk = this.$params.clientFk;
2018-11-27 12:28:15 +00:00
}
$onInit() {
2020-03-18 07:35:59 +00:00
if (this.$params && this.$params.clientFk)
this.clientId = parseInt(this.$params.clientFk);
2019-01-25 10:58:50 +00:00
2019-12-26 12:29:50 +00:00
this.warehouseId = this.vnConfig.warehouseFk;
2018-11-27 12:28:15 +00:00
}
get ticket() {
return this._ticket;
}
2018-11-27 12:28:15 +00:00
set ticket(value) {
if (value)
this._ticket = value;
}
get clientId() {
return this.ticket.clientFk;
2018-11-27 12:28:15 +00:00
}
set clientId(value) {
2018-11-27 12:28:15 +00:00
this.ticket.clientFk = value;
if (value) {
let filter = {
include: {
relation: 'defaultAddress',
scope: {
fields: ['id', 'agencyModeFk']
}
},
where: {id: value}
};
2018-11-27 12:28:15 +00:00
filter = encodeURIComponent(JSON.stringify(filter));
let query = `Clients?filter=${filter}`;
2018-11-27 12:28:15 +00:00
this.$http.get(query).then(res => {
const [client] = res.data;
this.defaultAddress = client.defaultAddress;
this.addressId = this.defaultAddress.id;
2018-11-27 12:28:15 +00:00
});
} else
this.addressId = null;
2019-01-25 10:58:50 +00:00
this.getAvailableAgencies();
2018-11-27 12:28:15 +00:00
}
get addressId() {
return this.ticket.addressFk;
2018-11-27 12:28:15 +00:00
}
set addressId(value) {
2018-11-27 12:28:15 +00:00
this.ticket.addressFk = value;
2019-01-25 10:58:50 +00:00
this.getAvailableAgencies();
2018-11-27 12:28:15 +00:00
}
get landed() {
return this.ticket.landed;
2018-11-27 12:28:15 +00:00
}
set landed(value) {
this.ticket.landed = value;
2019-01-25 10:58:50 +00:00
this.getAvailableAgencies();
2018-11-27 12:28:15 +00:00
}
get warehouseId() {
return this.ticket.warehouseFk;
2018-11-27 12:28:15 +00:00
}
set warehouseId(value) {
2018-11-27 12:28:15 +00:00
this.ticket.warehouseFk = value;
this.getAvailableAgencies();
}
get agencyModeId() {
return this.ticket.agencyModeFk;
}
set agencyModeId(value) {
this.ticket.agencyModeFk = value;
2018-11-27 12:28:15 +00:00
}
getAvailableAgencies() {
2019-11-11 15:32:03 +00:00
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;
});
2018-11-27 12:28:15 +00:00
}
}
onSubmit() {
this.createTicket();
}
createTicket() {
let params = {
clientId: this.ticket.clientFk,
2018-11-27 12:28:15 +00:00
landed: this.ticket.landed,
addressId: this.ticket.addressFk,
agencyModeId: this.ticket.agencyModeFk,
warehouseId: this.ticket.warehouseFk,
2018-11-27 12:28:15 +00:00
};
this.$http.post(`Tickets/new`, params).then(res => {
2020-03-18 13:08:04 +00:00
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
2018-11-27 12:28:15 +00:00
this.$state.go('ticket.card.summary', {id: res.data.id});
});
}
}
ngModule.component('vnTicketCreateCard', {
template: require('./card.html'),
controller: Controller,
bindings: {
ticket: '<?'
}
});