salix/modules/zone/front/delivery-days/index.js

74 lines
2.0 KiB
JavaScript

import ngModule from '../module';
import Section from 'salix/components/section';
import './style.scss';
class Controller extends Section {
$onInit() {
this.$.params = {};
}
$postLink() {
this.deliveryMethodFk = 'delivery';
}
onSubmit() {
this.$.data = null;
this.$http.get(`Zones/getEvents`, {params: this.$.params})
.then(res => {
let data = res.data;
this.$.data = data;
if (!data.events.length)
this.vnApp.showMessage(this.$t('No service for the specified zone'));
});
}
get deliveryMethodFk() {
return this._deliveryMethodFk;
}
set deliveryMethodFk(value) {
this._deliveryMethodFk = value;
this.$.params.agencyModeFk = null;
let filter;
if (value === 'pickUp') {
filter = {where: {code: 'PICKUP'}};
this.$.agencymode.focus();
} else
filter = {where: {code: {inq: ['DELIVERY', 'AGENCY']}}};
this.$http.get(`DeliveryMethods`, {filter}).then(res => {
let deliveryMethods = res.data.map(deliveryMethod => deliveryMethod.id);
this.agencyFilter = {deliveryMethodFk: {inq: deliveryMethods}};
});
}
onSelection($event, $events) {
if (!$events.length) return;
const zones = [];
for (let event of $events)
zones.push(event.zoneFk);
this.$.zoneEvents.show($event.target);
const zoneModel = this.$.zoneModel;
zoneModel.applyFilter({
include: {
relation: 'agencyMode',
scope: {fields: ['name']}
},
where: {
id: {inq: zones}
}
});
}
preview(zone) {
this.selectedZone = zone;
this.$.summary.show();
}
}
ngModule.component('vnZoneDeliveryDays', {
template: require('./index.html'),
controller: Controller
});