Joywork/js/callevents.js

287 lines
10 KiB
JavaScript
Raw Normal View History

2026-05-22 20:21:54 +02:00
var callEvents = new Vue({
el: '#callEventWidget',
data: {
userId: $('#session_user_id').val(),
header: '',
call_type: '',
line1: false,
line2: false,
clock: false,
header_hide: true,
active_call: [0],
client_id: false,
call_uuid: '',
operator: '',
requisitions: [],
body_hide: true,
body_show: true,
callEventWidget_hide: true,
user_id: '',
user_list: [],
total_user_list: [],
consult: true,
list_class: 'consult',
list_hide: true,
method_transfer: 'transfer',
show: true,
history_show: false,
history_calls: [],
temp_body: false,
totalHistoryCalls: 0,
openUser: false,
searchTransfer: '',
source: null,
source_id: 0,
call_id: 0,
cannot_create_req_manually: 0,
},
methods: {
closelist: function() {
callEvents.list_hide = true;
callEvents.searchTransfer = '';
},
hide: function() {
if (this.history_show === true) {
this.history_show = false;
return;
}
if (this.callEventWidget_hide === false) {
this.callEventWidget_hide = true;
this.openUser = false;
} else {
this.callEventWidget_hide = false;
this.openUser = true;
}
},
callTransfer: function(e) {
var number = e.target.getAttribute("data-phone");
axios.post('/ajax/call_events.php', {
'request': 'callTransfer',
'phone': number,
'callid': callEvents.call_uuid,
'operator': callEvents.operator,
'method': callEvents.method_transfer,
}).then(function(response) {
console.log(response.data);
callEvents.list_hide = true;
});
},
getListTransfer: function(type) {
if (callEvents.list_hide) {
axios.post('/ajax/call_events.php', {
request: 'getListTransfer',
}).then(function(response) {
var data = response.data;
if (data.userlist) {
callEvents.user_list = data.userlist;
callEvents.total_user_list = data.userlist;
}
if (type == 'consult') {
callEvents.consult = true;
callEvents.method_transfer = 'consult';
callEvents.list_class = 'consult';
} else {
callEvents.consult = false;
callEvents.method_transfer = 'transfer';
callEvents.list_class = '';
}
callEvents.list_hide = false;
});
} else {
callEvents.list_hide = true;
}
},
openRequisitionsForm: function(e) {
var id = e.target.getAttribute("data-id");
if (id == 0) {
agency_id = $('#session_agency_id').val();
if (agency_id == 8826) {
req_form.funnel_id = 216;
req_form.getFunnel(req_form.funnel_id);
}
req_form.openReqForm();
req_form.clientId = callEvents.client_id
req_form.getClients();
req_form.selectedType = 1;
if(this.source_id > 0){
req_form.getSources(this.source_id);
}
// req_form.getClient(callEvents.client_id);
req_form.getWhowork(callEvents.user_id);
req_form.getActivities();
req_form.user_id = callEvents.user_id;
$("#req_form .tabs__content").removeAttr("style");
// $('#req_form .form-block.klient').hide();
req_form.isReqForm = true;
// $('#req-new-client').val(callEvents.client_id);
$("body").addClass("lock");
}
},
getCallHistory: function() {
if (this.history_show == false) {
axios.post('/ajax/call_events.php', {
request: 'getCallHistory',
}).then(function(response) {
var data = response.data;
console.log(data);
if (data.calls) {
callEvents.history_calls = data.calls;
callEvents.totalHistoryCalls = data.totalCalls;
}
callEvents.history_show = true;
callEvents.temp_body = callEvents.callEventWidget_hide;
callEvents.callEventWidget_hide = true;
});
} else {
this.history_show = false;
callEvents.callEventWidget_hide = callEvents.temp_body;
}
},
endCall() {
// console.log(this.call_id);
if (this.call_id > 0) {
axios.post('/ajax/call_events.php', {
request: 'endCall',
call_id: this.call_id,
}).then((response) => {
var data = response.data;
// console.log(data);
if (data.call_id) {
this.call_id = 0;
this.getCallsEvent();
}
});
}
},
getCallsEvent: function() {
// this.call_id = 0;
axios.post('/ajax/call_events.php', {
request: 'getCallEvents',
}).then((response) => {
var data = response.data;
// console.log(data);
if (data.call_id) {
this.call_id = data.call_id;
if (callEvents.active_call.some(element => element === data.call_id)) {
return;
} else {
for (let key in data) {
if (key == 'call_id') {
callEvents.active_call.push(data.call_id);
} else {
callEvents[key] = data[key];
}
}
callEvents.history_show = false;
callEvents.getRequisition();
callEvents.reqInterval = setInterval(() => callEvents.getRequisition(), 5000);
callEvents.callEventWidget_hide = false;
callEvents.openUser = false;
}
} else {
this.call_id = 0;
for (let key in data) {
if (key == 'call_id') {
callEvents.active_call = [0];
} else {
callEvents[key] = data[key];
}
callEvents.body_hide = true;
if (!callEvents.openUser) {
callEvents.callEventWidget_hide = true;
}
clearInterval(callEvents.reqInterval);
}
}
if (typeof data.cannot_create_req_manually !== 'undefined') {
this.cannot_create_req_manually = data.cannot_create_req_manually;
}
});
},
getRequisition: function() {
axios.post('/ajax/call_events.php', {
request: 'getRequisition',
client_id: callEvents.client_id,
}).then(function(response) {
var data = response.data;
var requisitions = [];
if (data.header) {
callEvents.header = data.header;
}
if (data.requisitions) {
requisitions = data.requisitions;
}
//var newRequisitions = {'id':"0", 'name':'+ Новая заявка'};
//requisitions.push(newRequisitions);
callEvents.requisitions = requisitions;
callEvents.body_hide = false;
});
},
filterTransfer: function() {
var arrSearch = callEvents.total_user_list;
callEvents.user_list = [];
if (this.isEmpty(this.searchTransfer)) {
callEvents.user_list = callEvents.total_user_list;
} else {
for (var i = 0; i < arrSearch.length; i++) {
if (arrSearch[i].name.toLowerCase().indexOf(this.searchTransfer.toLowerCase()) > -1 || arrSearch[i].phone.toLowerCase().indexOf(this.searchTransfer.toLowerCase()) > -1) {
callEvents.user_list.push(arrSearch[i]);
}
}
}
},
isEmpty: function(data) {
if (typeof(data) === 'object') {
if (JSON.stringify(data) === '{}' || JSON.stringify(data) === '[]') {
return true;
} else if (!data) {
return true;
}
return false;
} else if (typeof(data) === 'string') {
if (!data.trim()) {
return true;
}
return false;
} else if (typeof(data) === 'undefined') {
return true;
} else {
return false;
}
},
},
created: function() {
this.interval = setInterval(() => this.getCallsEvent(), 2000);
document.onclick = function(e) {
if (e.target.className != 'i-list-transfer' && e.target.className != 'i-filter-transfer') {
callEvents.list_hide = true;
};
};
}
});