salix/modules/client/front/notification/index.js

124 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

import ngModule from '../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.$checkAll = false;
this.smartTableOptions = {
activeButtons: {
search: true
},
columns: [
{
field: 'socialName',
autocomplete: {
url: 'Clients',
showField: 'socialName',
valueField: 'socialName'
}
},
{
field: 'city',
autocomplete: {
url: 'Towns',
valueField: 'name',
showField: 'name'
}
}
]
};
this.campaign = {
id: null,
from: null,
to: null
};
this.getUpcomingCampaing();
}
get checked() {
const clients = this.$.model.data || [];
const checkedClients = [];
for (const buy of clients) {
if (buy.$checked)
checkedClients.push(buy);
}
return checkedClients;
}
onChangeDate(value) {
if (value)
this.campaign.id = null;
}
getUpcomingCampaing() {
2022-02-14 07:44:22 +00:00
this.$http.get('Campaigns/upcoming')
.then(res => this.campaign.id = res.data.id);
}
get campaignSelection() {
return this._campaignSelection;
}
set campaignSelection(value) {
this._campaignSelection = value;
if (value) {
const from = new Date(value.dated);
from.setDate(from.getDate() - value.scopeDays);
this.campaign.to = value.dated;
this.campaign.from = from;
}
}
onSendClientConsumption() {
const clientIds = this.checked.map(client => client.id);
2022-10-07 10:00:06 +00:00
const data = {
2022-09-29 12:43:27 +00:00
clients: clientIds,
from: this.campaign.from,
to: this.campaign.to
};
2022-10-07 10:00:06 +00:00
const params = JSON.stringify(data);
2022-09-29 12:43:27 +00:00
this.$http.post('ClientConsumptionQueues', {params})
.then(() => this.$.filters.hide())
2022-10-10 05:28:10 +00:00
.then(() => this.vnApp.showSuccess(this.$t('Notification sent!')));
}
exprBuilder(param, value) {
switch (param) {
case 'search':
return /^\d+$/.test(value)
? {id: value}
: {or: [{name: {like: `%${value}%`}}, {socialName: {like: `%${value}%`}}]};
case 'phone':
return {
or: [
{phone: value},
{mobile: value}
]
};
case 'name':
case 'socialName':
case 'city':
case 'email':
return {[param]: {like: `%${value}%`}};
case 'id':
case 'fi':
case 'postcode':
case 'salesPersonFk':
2022-08-12 13:31:59 +00:00
case 'provinceFk':
return {[param]: value};
}
}
}
ngModule.vnComponent('vnClientNotification', {
template: require('./index.html'),
controller: Controller
});