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

97 lines
2.6 KiB
JavaScript

import ngModule from '../module';
import Section from 'salix/components/section';
import './style.scss';
class Controller extends Section {
$onInit() {
this.setParams();
}
$postLink() {
this.deliveryMethodFk = 'delivery';
}
setParams() {
const hasParams = this.$params.deliveryMethodFk || this.$params.geoFk || this.$params.agencyModeFk;
if (hasParams) {
if (this.$params.deliveryMethodFk)
this.deliveryMethodFk = this.$params.deliveryMethodFk;
if (this.$params.geoFk)
this.geoFk = this.$params.geoFk;
if (this.$params.agencyModeFk)
this.agencyModeFk = this.$params.agencyModeFk;
this.fetchData();
}
}
fetchData() {
const params = {
deliveryMethodFk: this.deliveryMethodFk,
geoFk: this.geoFk,
agencyModeFk: this.agencyModeFk
};
this.$.data = null;
this.$http.get(`Zones/getEvents`, {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'));
this.$state.go(this.$state.current.name, params);
});
}
get deliveryMethodFk() {
return this._deliveryMethodFk;
}
set deliveryMethodFk(value) {
this._deliveryMethodFk = value;
let filter;
if (value === 'pickUp')
filter = {where: {code: 'PICKUP'}};
else
filter = {where: {code: {inq: ['DELIVERY', 'AGENCY']}}};
this.$http.get(`DeliveryMethods`, {filter}).then(res => {
const deliveryMethods = res.data.map(deliveryMethod => deliveryMethod.id);
this.agencyFilter = {deliveryMethodFk: {inq: deliveryMethods}};
});
}
onSelection($event, $events, $days) {
if (!$events.length) return;
const day = $days[0];
const zonesIds = [];
for (let event of $events)
zonesIds.push(event.zoneFk);
this.$.zoneEvents.show($event.target);
const params = {
zonesId: zonesIds,
date: day
};
this.$http.post(`Zones/getZoneClosing`, params)
.then(res => this.zoneClosing = res.data);
}
preview(zone) {
this.selectedZone = zone;
this.$.summary.show();
}
}
ngModule.vnComponent('vnZoneDeliveryDays', {
template: require('./index.html'),
controller: Controller
});