Joywork/js/vue_scripts/union_req_vue.js

340 lines
11 KiB
JavaScript
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
var union_reqs_form = new Vue({
el: '#union_reqs_form',
components: {
Multiselect: window.VueMultiselect.default,
vuejsDatepicker: window.vuejsDatepicker
},
data() {
return {
req: [],
//isPreloader: true,
agency_id: $('#session_agency_id').val(),
user_id: $("#session_user_id").val(),
//funnel_id: $('#funnelIdClients').val(),
reqs_id: [],
isReqClient: 0,
isShow: false,
page: 1,
all_pages: 1,
prevPage: 0,
ot: 0,
do: 0,
pagePagin: [],
main_id: 0,
union_req: [],
is_union: 0,
is_list_joint: false,
}
},
methods: {
//Список
getList() {
this.req = [];
this.isReqClient = 0;
this.pagePagin = [];
this.ot = 0;
this.do = 0;
//console.log(this.objectId);
//requisitions_client.isPreloader=true;
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_all',
is_cancel: this.is_list_joint,
reqs_id: this.reqs_id,
page: this.page,
per_page: 10,
//funnel_id: this.funnel_id,
//user_id: this.user_id, //без учета юзера
}, )
.then((response) => {
//console.log(response.data);
this.req = response.data.req;
//requisitions_client.isPreloader=false;
if (!this.isEmpty(this.req)) {
this.isReqClient = 1;
this.all_pages = parseInt(response.data.allPages);
if (this.all_pages > 1) {
if (this.page > 1)
this.prevPage = this.page - 1;
}
if (this.all_pages > 8) {
if (this.page > 4) {
this.ot = this.page - 3;
} else {
this.ot = 2;
}
if (this.page < this.all_pages - 4) {
this.do = this.page + 3;
} else {
this.do = this.all_pages;
}
} else {
this.ot = 2;
this.do = this.all_pages;
}
for (var i = this.ot; i < this.do; i++) {
this.pagePagin.push(i);
}
//$("#requisitions_list_client .clients").show();
} else {
this.isReqClient = 2;
}
})
.catch(function(error) {
console.log(error);
});
},
//Пагинация
pagin(page) {
this.page = page;
this.getList();
},
//Пагинация
goToRequisitionsPage(event) {
if (event.keyCode === 13) {
var pageNum = $('#union_reqs_formPageNumberInputForManualGoToPage').val();
if (pageNum) {
this.page = Number.parseInt(pageNum);
this.getList();
$('#runion_reqs_formPageNumberInputForManualGoToPage').val('');
}
}
},
//Выбор главной
check_main(req_id){
this.main_id = req_id;
this.delete_union(req_id);
},
//Выбор присоединяемых
check_unions($event, req_id){
if($($event.target).prop('checked'))
this.union_req.push(req_id);
else
this.delete_union(req_id);
},
//Удаление из объединения
delete_union(req_id){
var temp_union_reqs = [];
for(var i=0; i<this.union_req.length; i++ ){
if(this.union_req[i] != req_id){
temp_union_reqs.push(this.union_req[i]);
}
}
this.union_req = temp_union_reqs;
// console.log(this.union_req);
},
//Получение бара воронки
getBarFunnel(reqId) {
if (this.req['req' + reqId]) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_bar_funnel',
funnel_id: this.req['req' + reqId].funnel_id,
req_id: reqId
}, )
.then((response) => {
this.req['req' + reqId].steps = response.data;
this.isPreloader = 0;
})
.catch(function(error) {
console.log(error);
});
}
},
//Сохранить объединение
save_union(){
if(this.isEmpty(this.union_req)){
alert("Не выбраны заявки для объединения");
} else {
this.isReqClient = 0;
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'save_union_req',
main_id: this.main_id,
reqs: this.union_req,
user_id: this.user_id,
agency_id: this.agency_id,
}, )
.then((response) => {
console.log(response.data);
this.is_union = 1;
this.getList();
this.union_req = [];
})
.catch(function(error) {
console.log(error);
});
}
},
//открыть/закрыть подробности
toggleClient(id) {
if (this.req[id].isMainInfo) {
this.req[id].isMainInfo = false;
} else {
if (this.req[id].object_id > 0 && this.isEmpty(this.req[id].object)) {
this.getObject(this.req[id].object_id, id);
}
if (this.req[id].client_id > 0 && this.isEmpty(this.req[id].client)) {
this.getClient(this.req[id].client_id, id);
}
this.req[id].isMainInfo = true;
}
},
//Получение объекта
getObject(object_id, reqId, forma) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_object',
object_id: object_id
}, )
.then((response) => {
//console.log(response.data);
this.req[reqId].object = response.data;
if (forma) {
req_form.setReq(requisitions_object.req[reqId]);
}
})
.catch(function(error) {
console.log(error);
});
},
//Получение клиента
getClient(client_id, reqId, forma) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_client',
client_id: client_id
}, )
.then((response) => {
// console.log(response.data);
this.req[reqId].client = response.data;
if (forma) {
req_form.setReq(requisitions_object.req[reqId]);
}
})
.catch(function(error) {
console.log(error);
});
},
//показать объект
showObject(id) {
$('#liObject').click();
},
//показать клиента
showClient() {
$('#liGlobal').click();
},
//Открыть форму
openForm(reqs_id) {
this.isReqClient = 0;
this.is_list_joint = false;
this.page = 1;
this.isShow = true;
this.reqs_id = reqs_id;
this.union_req = [];
this.getList();
$("body").addClass("lock");
},
//открыть список уже объединенных
openFormJoint(req_id){
this.isReqClient = 0;
this.main_id = req_id;
this.page = 1;
this.isShow = true;
this.is_list_joint = true;
this.union_req = [];
this.req = [];
$("body").addClass("lock");
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_reqs_joint',
req_id: this.main_id,
}, )
.then((response) => {
if(this.isEmpty(response.data)){
this.req = [];
this.isReqClient = 1;
} else {
this.reqs_id = response.data;
this.getList();
}
})
.catch(function(error) {
console.log(error);
});
},
//закрыть форму
closeForm() {
this.isShow = false;
$("body").removeClass("lock");
if(this.is_union == 1) {
if(requisitions.view == 'kanban'){
requisitions.page = 1;
}
requisitions.getList();
}
this.union_req = [];
},
openCardClient(client_id, ignoreFunnelsUpdate = false) {
openClientEventsWindowNew(client_id, $('#session_to_send').val(), 0, undefined, undefined, ignoreFunnelsUpdate);
},
//Проверка на пустоту
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() {
//this.getList();
},
created: function() {
$("#union_reqs_form").removeClass("hidden");
}
})