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

96 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2019-09-25 18:06:42 +00:00
import ngModule from '../module';
2019-11-14 13:37:18 +00:00
import Section from 'salix/components/section';
2019-09-25 18:06:42 +00:00
import './style.scss';
2019-11-14 13:37:18 +00:00
class Controller extends Section {
$onInit() {
this.setParams();
2019-09-25 18:06:42 +00:00
}
2020-03-26 16:41:40 +00:00
$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
};
2020-01-08 12:27:43 +00:00
this.$.data = null;
this.$http.get(`Zones/getEvents`, {params})
2020-01-08 12:27:43 +00:00
.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);
2020-01-08 12:27:43 +00:00
});
2019-09-25 18:06:42 +00:00
}
2020-02-26 06:02:03 +00:00
2020-03-24 16:32:30 +00:00
get deliveryMethodFk() {
2020-03-26 16:41:40 +00:00
return this._deliveryMethodFk;
2020-03-24 16:32:30 +00:00
}
set deliveryMethodFk(value) {
2020-03-26 16:41:40 +00:00
this._deliveryMethodFk = value;
2020-03-24 16:32:30 +00:00
let filter;
if (value === 'pickUp')
2020-03-24 16:32:30 +00:00
filter = {where: {code: 'PICKUP'}};
else
2020-03-26 16:41:40 +00:00
filter = {where: {code: {inq: ['DELIVERY', 'AGENCY']}}};
this.$http.get(`DeliveryMethods`, {filter}).then(res => {
const deliveryMethods = res.data.map(deliveryMethod => deliveryMethod.id);
2020-03-24 16:32:30 +00:00
this.agencyFilter = {deliveryMethodFk: {inq: deliveryMethods}};
});
}
2021-08-30 12:14:21 +00:00
onSelection($event, $events, $days) {
2020-02-26 06:02:03 +00:00
if (!$events.length) return;
2021-08-30 12:14:21 +00:00
const day = $days[0];
2022-03-15 08:13:35 +00:00
const zoneIds = [];
2020-02-26 06:02:03 +00:00
for (let event of $events)
2022-03-15 08:13:35 +00:00
zoneIds.push(event.zoneFk);
2020-02-26 06:02:03 +00:00
const params = {
2022-03-15 08:13:35 +00:00
zoneIds: zoneIds,
date: day
};
this.$http.post(`Zones/getZoneClosing`, params)
.then(res => this.zoneClosing = res.data)
.then(() => this.$.zoneEvents.show($event.target));
2020-02-26 06:02:03 +00:00
}
2020-03-26 08:07:17 +00:00
2020-04-25 09:50:04 +00:00
preview(zone) {
2020-03-26 08:07:17 +00:00
this.selectedZone = zone;
this.$.summary.show();
}
2019-09-25 18:06:42 +00:00
}
ngModule.vnComponent('vnZoneDeliveryDays', {
2019-09-25 18:06:42 +00:00
template: require('./index.html'),
controller: Controller
});