Joywork/js/vue_scripts/union_clients_vue.js
2026-05-22 21:21:54 +03:00

342 lines
13 KiB
JavaScript

if ($('#union_clients').length > 0) {
var union_clients = new Vue({
el: '#union_clients',
components: {
vuejsDatepicker: window.vuejsDatepicker,
draggable: window.vuedraggable
},
data() {
return {
is_show: false,
agency_id: $('#session_agency_id').val(),
user_id: $('#session_user_id').val(),
prealoaderSearch: false,
prealoaderDop: false,
clients_search: [],
clients_dop: [],
client_dop_id: null,
fio_search: '',
phone_search: '',
id_search: null,
isError: false,
text_error: "",
is_show_error: false,
client_main: null,
prealoaderMain: false,
is_union_req: false,
is_union: false,
}
},
methods: {
//Открытие
open() {
$('.ui-tooltip').remove();
//this.clear();
this.is_show = true;
this.search_dop();
},
close() {
this.is_show = false;
if(this.is_union){
var page = window.location.pathname;
console.log(page);
if (page == '/clients.php') {
let sort_order = $('select[name=sort_order]').val();
console.log(sort_order);
get_list(page, sort_order);
}
$('#send_bg_new').fadeOut(500);
$("#send_bg_new .edit-modal").toggle(10);
$("body").removeClass("lock");
}
this.clear();
},
clear() {
this.prealoaderSearch = false;
this.clients_search = [];
this.clients_dop = [];
this.client_dop_id = null;
this.prealoaderDop = false;
this.fio_search = '';
this.phone_search = '';
this.id_search = null;
this.isError = false;
this.text_error = "";
this.is_show_error = false;
this.client_main = null;
this.prealoaderMain = false;
this.is_union_req = false;
this.is_union = false;
},
async search_dop(){
console.log(this.client_dop_id);
if(!this.isEmpty(this.client_dop_id)){
this.prealoaderDop = true;
axios.post('/ajax/vue_ajax/ajax_union_clients.php', {
request: 'search_client',
id: this.client_dop_id,
agency_id: this.agency_id,
user_id: this.user_id,
}, )
.then((response) => {
this.prealoaderDop = false;
this.clients_dop = [];
console.log(response.data);
var res = response.data;
if(res.total > 0){
this.clients_dop = res.clients;
}
})
.catch(function(error) {
console.log(error);
});
}
},
async search(){
if(this.isEmpty(this.id_search) && this.isEmpty(this.fio_search) && this.isEmpty(this.phone_search)){
this.text_error = "Введите хотя бы один параметр поиска";
this.is_show_error = true;
} else {
this.prealoaderSearch = true;
axios.post('/ajax/vue_ajax/ajax_union_clients.php', {
request: 'search_client',
id: this.id_search,
phone: this.phone_search,
fio: this.fio_search,
agency_id: this.agency_id,
user_id: this.user_id,
}, )
.then((response) => {
this.prealoaderSearch = false;
this.clients_search = [];
console.log(response.data);
var res = response.data;
if(res.total > 0){
this.clients_search = res.clients;
}
})
.catch(function(error) {
console.log(error);
});
}
},
async start_union(){
this.prealoaderDop = true;
this.prealoaderMain = true;
var main_id = this.client_main.id;
var dop_ids = [];
var is_union_req = 0;
if(this.is_union_req) is_union_req = 1;
for(var i = 0; i<this.clients_dop.length; i++){
dop_ids.push(this.clients_dop[i].id);
}
console.log(main_id);
console.log(dop_ids);
axios.post('/ajax/vue_ajax/ajax_union_clients.php', {
request: 'union_client',
id: main_id,
dop_ids: dop_ids,
agency_id: this.agency_id,
user_id: this.user_id,
is_union_req: is_union_req
}, )
.then((response) => {
console.log(response.data);
this.prealoaderDop = false;
this.prealoaderMain = false;
this.clients_dop = [];
this.is_union = true;
if(this.isEmpty(this.id_search) && this.isEmpty(this.fio_search) && this.isEmpty(this.phone_search)){
/******/
} else {
this.search();
}
})
.catch(function(error) {
console.log(error);
});
},
send_dop(client){
$('.ui-tooltip').remove();
var is_send = true;
var index = 0;
var index1 = 0
for(var i=0; i<union_clients.clients_dop.length; i++){
if(union_clients.clients_dop[i].id == client.id){
index = i;
union_clients.clients_dop[i].is_show_dop = true;
is_send = false;
for(var j=0; j<union_clients.clients_search.length; j++){
if(union_clients.clients_search[j].id == client.id){
index1 = j;
union_clients.clients_search.splice(index1, 1);
}
}
setTimeout(function(){
union_clients.clients_dop[index].is_show_dop = false;
}, 2000)
}
}
if(!this.isEmpty(union_clients.client_main)){
if(client.id == union_clients.client_main.id){
is_send = false;
union_clients.client_main.is_show_dop = true;
for(var i1=0; i1<union_clients.clients_search.length; i1++){
if(union_clients.clients_search[i1].id == client.id){
index1 = i1;
union_clients.clients_search.splice(index1, 1);
}
}
setTimeout(function(){
union_clients.client_main.is_show_dop = false;
}, 2000)
}
}
if(is_send){
this.clients_dop.push(client);
for(var i1=0; i1<union_clients.clients_search.length; i1++){
if(union_clients.clients_search[i1].id == client.id){
index1 = i1;
union_clients.clients_search.splice(index1, 1);
}
}
}
},
send_search(client){
$('.ui-tooltip').remove();
var is_send = true;
var index = 0;
var index1 = 0;
for(var i=0; i<union_clients.clients_search.length; i++){
if(union_clients.clients_search[i].id == client.id){
index = i;
is_send = false;
for(var j=0; j<union_clients.clients_dop.length; j++){
if(union_clients.clients_dop[j].id == client.id){
index = j;
union_clients.clients_dop.splice(index, 1);
}
}
}
}
if(is_send){
this.clients_search.push(client);
for(var i1=0; i1<union_clients.clients_dop.length; i1++){
if(union_clients.clients_dop[i1].id == client.id){
index1 = i1;
union_clients.clients_dop.splice(index1, 1);
}
}
}
},
send_main(client){
$('.ui-tooltip').remove();
var index = 0;
var index1 = 0;
if(!this.isEmpty(this.client_main) ){
var temp_client = this.client_main;
temp_client.is_show_dop = true;
this.clients_dop.push(temp_client);
setTimeout(function(){
var index_dop = union_clients.clients_dop.length-1;
union_clients.clients_dop[index_dop].is_show_dop = false;
}, 2000)
}
union_clients.client_main = client;
for(var i1=0; i1<union_clients.clients_dop.length; i1++){
if(union_clients.clients_dop[i1].id == client.id){
index1 = i1;
union_clients.clients_dop.splice(index1, 1);
}
}
for(var i=0; i<union_clients.clients_search.length; i++){
if(union_clients.clients_search[i].id == client.id){
index = i;
union_clients.clients_search.splice(index, 1);
}
}
},
delete_main(){
$('.ui-tooltip').remove();
if(!this.isEmpty(this.client_main)){
var temp_client = this.client_main;
temp_client.is_show_dop = true;
this.clients_dop.push(temp_client);
setTimeout(function(){
var index_dop = union_clients.clients_dop.length-1;
union_clients.clients_dop[index_dop].is_show_dop = false;
}, 2000)
}
this.client_main = null;
},
//Проверка на пустоту
isEmpty(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;
}
},
},
mounted() {
},
created: function() {
$("#union_clients").removeClass("hidden");
}
})
}