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

75 lines
2.0 KiB
JavaScript
Raw 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.$.params = {};
2019-09-25 18:06:42 +00:00
}
2020-03-26 16:41:40 +00:00
$postLink() {
this.deliveryMethodFk = 'delivery';
}
2019-09-25 18:06:42 +00:00
onSubmit() {
2020-01-08 12:27:43 +00:00
this.$.data = null;
2019-11-14 13:37:18 +00:00
this.$http.get(`Zones/getEvents`, {params: this.$.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'));
});
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;
this.$.params.agencyModeFk = null;
2020-03-24 16:32:30 +00:00
let filter;
2020-03-26 16:41:40 +00:00
if (value === 'pickUp') {
2020-03-24 16:32:30 +00:00
filter = {where: {code: 'PICKUP'}};
2020-03-26 16:41:40 +00:00
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);
2020-03-24 16:32:30 +00:00
this.agencyFilter = {deliveryMethodFk: {inq: deliveryMethods}};
});
}
2020-02-26 06:02:03 +00:00
onSelection($event, $events) {
if (!$events.length) return;
const zones = [];
for (let event of $events)
zones.push(event.zoneFk);
this.$.zoneEvents.show($event.target);
2020-03-26 08:07:17 +00:00
const zoneModel = this.$.zoneModel;
2020-02-26 06:02:03 +00:00
zoneModel.applyFilter({
include: {
relation: 'agencyMode',
scope: {fields: ['name']}
},
where: {
id: {inq: zones}
}
});
}
2020-03-26 08:07:17 +00:00
preview(event, zone) {
this.stopEvent(event);
this.selectedZone = zone;
this.$.summary.show();
}
2019-09-25 18:06:42 +00:00
}
ngModule.component('vnZoneDeliveryDays', {
template: require('./index.html'),
controller: Controller
});