Joywork/js/requisitions_vue.js

3941 lines
159 KiB
JavaScript
Raw Normal View History

2026-05-22 20:21:54 +02:00
Vue.config.devtools = true;
Vue.component('v-select', VueSelect.VueSelect)
Vue.directive('mask', VueMask.VueMaskDirective);
if ($('#requisitions_list').length > 0) {
var requisitions = new Vue({
el: '#requisitions_list',
components: {
Multiselect: window.VueMultiselect.default,
vuejsDatepicker: window.vuejsDatepicker
},
name: 'requisitions_list',
data() {
return {
req: [],
isPreloader: 1,
agencyId: $('#session_agency_id').val(),
user_id: $('#userIdReq').val(),
userId: $('#session_user_id').val(),
funnel_id: $('#funnelIdClients').val(),
autosearch: [],
autosearch_id: 0,
autosearch_info: '',
autosearch_comment: '',
isList: true,
isKanban: false,
isTable: false,
view: 'list',
steps: [],
filtr: [],
page: 1,
isLoading: false,
all_pages: 1,
prevPage: 0,
ot: 0,
do: 0,
pagePagin: [],
activities: [],
activities_name: [],
totalReqs: 0,
OpenIndicator: {
render: createElement => createElement('span', { class: { 'vueToggleSpan': true } }),
},
option_contract_tag: [{ 'code': 1, 'name': 'Добавить тег' }, { 'code': 2, 'name': 'Добавить договор' }],
add_tag_contract: null,
req_id_contract_tag: 0,
prev_selectors: { 'li': null, 'ul': null },
}
},
watch: {
totalReqs(newVal) {
if (!newVal) {
newVal = localStorage.getItem('totalReqs')
}
this.$nextTick(() => {
const totalCount = newVal
let countValues = $('.task-count-holder .task-count:not(.task-count-percent)')
.map(function () {
return parseInt($(this).text(), 10);
})
.get()
$('.task-count-holder').each(function (index) {
const rawCount = countValues[index] || 0;
let rawPercent = (rawCount / totalCount) * 100 || 0;
const percent = Number.isInteger(rawPercent) ? rawPercent.toString() : rawPercent.toFixed(2) || 0;
const color = $(this).find('.task-count-percent').css('color') || '#00aaff';
const bg = `conic-gradient(${color} 0% ${percent}%, #dfdfdf ${percent}% 100%)`;
$(this).find('.circle-progress').css('background', bg);
$(this).find('.task-count-percent').text(percent + '%');
});
})
},
view(newVal) {
if (newVal === 'kanban') {
const totalFromSt = localStorage.getItem('totalReqs')
this.totalReqs = totalFromSt
}
}
},
methods: {
setAutosearch(reqs) {
if (!this.isEmpty(reqs)) {
setTimeout(function() { check_req_all_filter() }, 1000)
let as_req_ids = [];
Object.entries(reqs).forEach((item, index) => {
if (
(item[1].type_id == 1 || item[1].heir_type == 1) ||
(item[1].type_id == 4 || item[1].heir_type == 4)) {
as_req_ids.push(item[1].id.toString());
}
});
if (!this.isEmpty(as_req_ids)) {
axios.post('/ajax/ajax_vue_autosearch.php', {
request: 'get_filter_by_req',
user_id: this.user_id,
req_ids: as_req_ids,
}).then((response) => {
if (response.data.success) {
Object.entries(response.data.results).forEach((item, index) => {
if (!this.isEmpty(this.req['req' + item[0]])) {
this.req['req' + item[0]]['autosearch'] = item[1]['autosearch'];
this.req['req' + item[0]]['autosearch_id'] = item[1]['autosearch_id'];
this.req['req' + item[0]]['autosearch_info'] = item[1]['autosearch_info'];
this.req['req' + item[0]]['autosearch_comment'] = item[1]['autosearch_comment'];
}
});
}
}).catch(function(error) {
console.error(error);
});
}
}
},
//Для объединения
setUnionReq(reqs){
//console.log(reqs);
if (!this.isEmpty(reqs, this.agencyId)) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_union_reqs',
reqs: reqs,
agency_id: this.agencyId,
user_id: this.userId
}, )
.then((response) => {
// console.log(response.data);
const union_req = response.data;
Object.entries(union_req).forEach(([reqKey, unionIds]) => {
// console.log(unionIds);
let found = false;
// Перебираем все шаги (кроме 'count' и других не-шагов)
for (const step in this.req) {
if (step === 'count' || step === 'union_req' || !this.req.hasOwnProperty(step)) continue;
if (this.req[step] && step == reqKey) {
this.$set(this.req[step], 'union_req', unionIds);
found = true;
console.log(`[setUnionReq] Updated ${reqKey} in step ${step}`);
}
if(this.req[step][reqKey])
this.$set(this.req[step][reqKey], 'union_req', unionIds);
}
if (!found) {
console.warn(`[setUnionReq] req "${reqKey}" not found in any step`);
}
});
/* Object.entries(union_req).forEach((item, index) => {
this.req[item[0]].union_req = item[1];
if(this.req.count !== undefined){
for(var step in this.req.count){
if(this.req[step][item[0]] !== undefined){
this.req[step][item[0]].union_req = item[1];
}
}
}
});*/
// console.log(this.req);
// this.steps = response.data;
})
.catch(function(error) {
console.error(error);
})
}
},
open_union_req_form(reqs_id, req_id){
reqs_id.push(req_id);
if(typeof union_reqs_form == 'object'){
union_reqs_form.main_id = req_id;
union_reqs_form.is_union = 0;
union_reqs_form.openForm(reqs_id);
}
},
open_joint_req(req_id){
if(typeof union_reqs_form == 'object'){
// union_reqs_form.main_id = req_id;
union_reqs_form.is_union = 0;
}
union_reqs_form.openFormJoint(req_id);
},
//Список
getList() {
if (this.funnel_id == "all") {
this.view = "list";
}
console.log(this.view);
// console.log(this.page);
let funnel_id = $('#funnelIdClients').val();
let use_custom_funnel = $('#useCustomFunnel').val();
// get_funnels(funnel_id, 'requisitions', use_custom_funnel);
if (this.page > 1 && this.view == 'kanban') {
////////
} else {
this.req = [];
this.isPreloader = 1;
}
this.pagePagin = [];
this.ot = 0;
this.do = 0;
if (this.view == "list") {
this.isList = true;
this.isKanban = false;
this.isTable = false;
//this.view = 'list';
$('#groupClients').show();
} else if (this.view == 'kanban') {
this.isList = false;
this.isKanban = true;
this.isTable = false;
this.view = 'kanban';
this.getStepsFunnel();
this.funnel_id = $('#funnelIdClients').val();
$('#groupClients').hide();
} else if (this.view == 'table') {
this.isList = false;
this.isKanban = false;
this.isTable = true;
this.view = 'table';
$('#groupClients').hide();
}
console.log(this.isKanban);
console.log(this.filtr.order);
if(this.isKanban){
if(this.filtr.order === false || this.filtr.order == 0){
$('#sort_order_req').val(2);
}
}
//удаление вспомогательной таблицы
$("#req_table2").bootgrid("destroy");
$("#req_table2").remove();
// console.log(this.filtr);
return get_funnels(funnel_id, 'requisitions', use_custom_funnel).then(() => {
return axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_all',
user_id: this.user_id,
funnel_id: this.funnel_id,
view: this.view,
filtr: this.filtr,
page: this.page,
}, )
.then((response) => {
const totalReqsSt = localStorage.getItem('totalReqs')
if (!totalReqsSt) {
localStorage.setItem('totalReqs', this.totalReqs);
this.totalReqs = response.data.total_req
}
console.log(response.data);
if (this.view == 'kanban' && this.page > 1) {
this.req.count = response.data.req.count;
const totalFromSt = localStorage.getItem('totalReqs')
this.totalReqs = totalFromSt
//console.log(response.data);
setTimeout(() => {
for (var i in response.data.req) {
if (!isNaN(parseInt(i))) {
for (var ii in response.data.req[i]) {
if (ii.indexOf("req") > -1) {
if (!requisitions.req[i]) {
console.log('r.q is undefined');
continue
}
requisitions.$set(requisitions.req[i], ii, response.data.req[i][ii]);
}
}
} else if (i.indexOf("req") > -1) {
add_knban = true;
requisitions.$set(requisitions.req, i, response.data.req[i]);
}
}
//requisitions.totalReqs = response.data.total_req
requisitions.setAutosearch(response.data.req);
//if(this.agencyId == 5238 || this.agencyId == 4)
requisitions.setUnionReq(response.data.req);
let countValues = $('.task-count-holder .task-count:not(.task-count-percent)').map(function () {
return parseInt($(this).text(), 10);
})
.get()
$('.task-count-holder').each(function (index) {
const rawCount = countValues[index] || 0;
let rawPercent = (rawCount / parseInt(totalFromSt)) * 100 || 0;
const percent = Number.isInteger(rawPercent) ? rawPercent.toString() : rawPercent.toFixed(2) || 0;
const color = $(this).find('.task-count-percent').css('color') || '#00aaff';
const bg = `conic-gradient(${color} 0% ${percent}%, #dfdfdf ${percent}% 100%)`;
$(this).find('.circle-progress').css('background', bg);
$(this).find('.task-count-percent').text(percent + '%');
});
}, 500);
//this.totalReqs = response.data.total_req
if (this.totalReqs) {
localStorage.setItem('totalReqs', this.totalReqs);
}
} else {
this.req = response.data.req;
this.setAutosearch(response.data.req);
//if(this.agencyId == 5238 || this.agencyId == 4)
this.totalReqs = response.data.total_req
if (this.totalReqs) {
localStorage.setItem('totalReqs', this.totalReqs);
}
// if(this.agencyId == 5238 || this.agencyId == 4)
this.setUnionReq(response.data.req);
}
$('#req_filter_etap_input').html(response.data.step_filter);
this.getSelect('req_filter_etap_input', 'req_filter_etap', 'Этап', this.filtr.step);
$('#totalCountReq .text').text(response.data.total_req);
$('#totalCountReqComission .text').text(response.data.total_comission);
console.log(this.filtr);
if(this.filtr.stages.hit == 1){
$('#totalCountReqComission').hide();
} else {
$('#totalCountReqComission').show();
}
this.activities = response.data.activities;
this.activities_name = response.data.activities_name;
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.isPreloader = 0;
if (this.view == 'kanban') {
setTimeout(function() {
kanbanOverscroll();
}, 500);
} else if (this.view == 'table') {
setTimeout(function() {
reqBootgrid();
}, 500);
}
autosearch_objs.$on('change_autosearch_counters', function(filter_id, counter) {
console.log({ filter_id, counter });
if (counter.total > 0) {
$('.fltr-objects-list[data-id="' + filter_id + '"] .counter').fadeIn();
$('.fltr-objects-list[data-id="' + filter_id + '"] .counter').text('+' + counter.match);
$('.fltr-objects-list[data-id="' + filter_id + '"] .error').addClass('with-counter');
} else {
$('.fltr-objects-list[data-id="' + filter_id + '"] .counter').fadeOut();
$('.fltr-objects-list[data-id="' + filter_id + '"] .counter').text('0');
$('.fltr-objects-list[data-id="' + filter_id + '"] .error').removeClass('with-counter');
}
});
})
.catch(function(error) {
console.error(error);
});
});
},
get_req_id(id, is_kanban = 0){
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_req_id',
req_id: id,
user_id: this.user_id,
is_kanban: is_kanban
}, ).then((response) => {
var new_req = response.data;
for(var index in this.req){
if(this.req[index] && (index.indexOf('req') == -1 && index.indexOf('count') == -1)){
for(var index1 in this.req[index]){
if(index1 == 'req'+id){
var temp_req = this.req[index][index1];
this.req[index][index1] = new_req['req'+id];
requisitions.setUnionReq(this.req);
if(is_kanban){
let is_update = false;
if(index != new_req['req'+id].step_id) {
if(this.req[index][index1].funnel_id !=0){
delete this.req[index][index1];
is_update = true;
}
}
if(this.filtr.stages.close == 0 && temp_req.deleted == 0 && new_req['req'+id].deleted == 1){
// console.log($(`#kanban_item_li_${id}`));
$(`#kanban_item_li_${id}`).hide();
is_update = true;
}
if(temp_req.funnel_id != new_req['req'+id].funnel_id){
$(`#kanban_item_li_${id}`).hide();
is_update = true;
}
if(is_update){
requisitions.page = requisitions.page+1;
requisitions.getList();
}
}
}
}
} else if (index == 'req'+id){
this.req[index] = new_req['req'+id];
}
};
if(new_req.is_kanban){
for(var indexCount in this.req.count){
console.log(indexCount)
if(indexCount == new_req['req'+id].step_id){
if(this.req[indexCount]){
/** */
} else {
this.$set(this.req, indexCount, {});
}
this.$set(this.req[indexCount], 'req'+id, new_req['req'+id]);
}
}
}
}).catch(function(error) {
console.debug(error);
});
},
getSelect(id, idf, name, value) {
if ($('#' + idf).length > 0) {
$('#' + idf).fastselect().data('fastselect').destroy();
if (!this.isEmpty(value)) {
$('#' + idf).val(value);
} else {
$('#' + idf).val(null);
}
$('#' + idf).fastselect({
placeholder: name,
onItemCreate: function(item, model) {
if ($('#' + idf).find('option[value=' + model.value + ']').hasClass('bolt')) {
$(item).addClass('bolt');
}
},
onItemSelect: function(item, val) {
filtr.checkFiltr();
},
onItemDelete: function() {
filtr.checkFiltr();
}
});
}
},
//Пагинация
pagin(page) {
this.page = page;
this.getList();
},
//Пагинация
goToRequisitionsPage(event) {
if (event.keyCode === 13) {
var pageNum = $('#requisitionPageNumberInputForManualGoToPage').val();
if (pageNum) {
this.page = Number.parseInt(pageNum);
this.getList();
$('#requisitionPageNumberInputForManualGoToPage').val('');
}
}
},
//Пагинация
goToRequisitionsPageTable(event) {
if (event.keyCode === 13) {
var pageNum = $('#requisitionPageNumberInputForManualTableGoToPage').val();
if (pageNum) {
this.page = Number.parseInt(pageNum);
this.getList();
$('#requisitionPageNumberInputForManualGoToPage').val('');
}
}
},
//Для канбана этапы воронки
getStepsFunnel() {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_step_funnel',
funnel_id: this.funnel_id,
}, )
.then((response) => {
// console.log(response.data);
this.steps = response.data;
})
.catch(function(error) {
console.error(error);
});
},
//Получение бара воронки
getBarFunnel(reqId, adjacent_id = 0) {
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,
adjacent_id: adjacent_id,
}, )
.then((response) => {
ac.closesStep = false;
ac.is_looad = false;
ac.is_load_open = false;
ac.isOpenPrevStep = false;
var bar = response.data;
this.req['req' + reqId].steps = response.data;
if(response.data.steps){
this.req['req' + reqId].steps = response.data.steps;
}
if(response.data.funnels_adjacent){
this.req['req' + reqId].funnels_adjacent = response.data.funnels_adjacent;
this.req['req' + reqId].funnels_adjacent_text = response.data.funnels_adjacent_text;
}
if(response.data.req_deleted !== undefined){
requisitions.req['req' + reqId].deleted = response.data.req_deleted;
}
requisitions.isPreloader = 0;
console.log($('#client-history__bg').css('display'));
if ($('#client-history__bg').css('display') != 'none') {
$('#client-history__bg .crm__small-stagebar .stage').removeClass('nextStep');
$('#client-history__bg .crm__small-stagebar .stage').removeClass('active');
for (var i in bar.bar) {
$('#client-history__bg .crm__small-stagebar .stageFunnel__' + bar.bar[i].id).addClass(bar.bar[i].classF);
}
$('#client-history__bg .stagebar-title').text(bar.stage);
}
})
.catch(function(error) {
console.error(error);
});
}
},
//Для редактирования
getReq(id) {
req_form.openReqForm();
this.getComplexRoom(id);
if (this.req[id].object_id > 0 && this.isEmpty(this.req[id].object)) {
this.getObject(this.req[id].object_id, id, 1);
} else {
req_form.setReq(requisitions.req[id]);
}
if (this.req[id].client_id > 0) {
this.getClient(this.req[id].client_id, id, 1);
//req_form.setReq(requisitions.req[id]);
} else {
req_form.setReq(requisitions.req[id]);
}
},
getComplexRoom(reqId) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_complex_room',
req_id: reqId
}, )
.then((response) => {
this.req[reqId].complex_status_id = response.data.complex_status_id;
this.req[reqId].complex_room_id = response.data.complex_room_id;
req_form.setReq(requisitions.req[reqId]);
})
.catch(function(error) {
console.error(error);
});
},
//Получение объекта
getObject(object_id, reqId, forma, obj) {
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.req[reqId]);
if (obj) {
req_form.liGlobal = 4;
}
}
})
.catch(function(error) {
console.error(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.req[reqId]);
}
})
.catch(function(error) {
console.error(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;
}
},
//показать объект
showObject(id) {
console.log(id);
req_form.openReqForm();
if (this.req['req' + id].object_id > 0 && this.isEmpty(this.req['req' + id].object)) {
this.getObject(this.req['req' + id].object_id, 'req' + id, 1, 1);
} else {
req_form.setReq(requisitions.req['req' + id]);
req_form.liGlobal = 4;
}
},
//Удаление заявки
cancelReq(id) {
if (confirm('Вы точно хотите безвозвратно удалить эту заявку?')) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'cancel_req',
req_id: id
}, )
.then((response) => {
this.getList();
})
.catch(function(error) {
console.error(error);
});
}
},
//Возврат заявки
renewReq(id) {
if (confirm('Вы точно хотите восстановить эту заявку?')) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'renew_req',
req_id: id,
user_id: this.user_id
}, )
.then((response) => {
this.getList();
})
.catch(function(error) {
console.error(error);
});
}
},
//возврат нескольких заявок
//Возврат заявки
renewReqs(reqs) {
var ids = [];
var all = 0;
if ($('#changeReqAllFilter').prop('checked')) {
all = 1;
if (localStorage['ids_exception_req']) {
var ids_exception_req = localStorage.getItem('ids_exception_req');
ids = JSON.parse(ids_exception_req);
}
}
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'renew_reqs',
reqs_id: reqs,
user_id: this.user_id,
all: all,
ids_exception: ids,
}, )
.then((response) => {
console.log(response.data);
this.getList();
})
.catch(function(error) {
console.error(error);
});
},
takeFromClosedReqs(reqs) {
let ids = [];
let all = 0;
if ($('#changeReqAllFilter').prop('checked')) {
all = 1;
if (localStorage['ids_exception_req']) {
let ids_exception_req = localStorage.getItem('ids_exception_req');
ids = JSON.parse(ids_exception_req);
}
}
console.log('reqs_ids', reqs);
console.log('user_id', this.user_id);
console.log('ids_exception', ids);
console.log('all', all);
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'take_from_closed_reqs',
reqs_id: reqs,
user_id: this.user_id,
all: all,
ids_exception: ids,
}, )
.then((response) => {
console.log(response.data);
this.getList();
})
.catch(function(error) {
console.error(error);
});
},
//Общее выделение
to_check_req_new(id) {
console.log(id);
if ($('#changeReq' + id).prop('checked')) {
$('#changeReq' + id).prop('checked', false);
$('#checked-clt' + id).removeClass('active');
if($('#changeReqAllFilter').prop('checked')){
allOnCheckId(id, 'req');
}
} else {
$('#changeReq' + id).prop('checked', true);
$('#checked-clt' + id).addClass('active');
if($('#changeReqAllFilter').prop('checked')){
allOffCheckId(id, 'req');
}
}
},
//Общая передача заявок
confirm__User_req() {
var ids = [];
var user_id = $('#confirm__user_id_req').val();
var who_work = $('#confirm__who_work_req').val();
var reqs_id = $('#confirm_reqs_id').val();
var all = 0;
if ($('#changeReqAllFilter').prop('checked')) {
all = 1;
if (localStorage['ids_exception_req']) {
var ids_exception_req = localStorage.getItem('ids_exception_req');
ids = JSON.parse(ids_exception_req);
}
}
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'confirm_reqs',
reqs_id: reqs_id,
user_id: user_id,
who_work: who_work,
all: all,
ids_exception: ids,
}, )
.then((response) => {
console.log(response.data);
closeConfirmReq();
this.getList();
})
.catch(function(error) {
console.error(error);
});
},
//Общая смена воронок
funnelReqsConfirm() {
var ids = [];
var reqs_id = $('#funnel_reqs_id').val();
var funnel_check = $('#funnel__check_req').val();
var all = 0;
if ($('#changeReqAllFilter').prop('checked')) {
all = 1;
if (localStorage['ids_exception_req']) {
var ids_exception_req = localStorage.getItem('ids_exception_req');
ids = JSON.parse(ids_exception_req);
}
}
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'funnel_check',
reqs_id: reqs_id,
funnel_check: funnel_check,
all: all,
ids_exception: ids,
}, )
.then((response) => {
//console.log(response.data);
closeFunnelReqs();
this.getList();
})
.catch(function(error) {
console.error(error);
});
},
//Открыть чек лист
openCheckList(funnel_id, id, type) {
funnelchecklist.open(funnel_id, id, type);
},
//Открыть добавление тегов
open_add_tag(id) {
for (var i in this.req) {
if (i != id) {
this.req[i].add_tag = false;
}
}
(this.req[id].add_tag) ? this.req[id].add_tag = false: this.req[id].add_tag = true;
this.req[id].activities_temp = this.req[id].activities;
},
//Открыть добавление тегов или договоров
open_add_tag_contract(id) {
this.req_id_contract_tag = id;
this.add_tag_contract = null;
for (var i in this.req) {
this.req[i].add_tag = false;
this.req[i].popup_tag = false;
if (i != id) {
this.req[i].add_tag_contract = false;
this.req[i].add_tag = false;
}
}
(this.req[id].add_tag_contract) ? this.req[id].add_tag_contract = false: this.req[id].add_tag_contract = true;
},
//Открыть добавление тегов или договоров
open_popup_tag(id) {
for (var i in this.req) {
this.req[i].add_tag_contract = false;
this.req[i].add_tag = false;
if (i != id) {
// this.req[i].poup_tag_contract = false;
this.req[i].popup_tag = false;
} else {
this.req[i].popup_tag = !this.req[i].popup_tag;
}
}
//(this.req[id].add_tag_contract) ? this.req[id].add_tag_contract = false: this.req[id].add_tag_contract = true;
},
//выбор договор/тег
change_contract_tag(val) {
if (val == 1) {
this.req[this.req_id_contract_tag].add_tag = true;
} else if (val == 2) {
if (typeof contract_form != "undefined") {
contract_form.parent_type = 'req';
contract_form.parent_id = this.req_id_contract_tag;
contract_form.open();
}
}
this.req[this.req_id_contract_tag].add_tag_contract = false;
},
open_form_contract(id, contract_id) {
if (typeof contract_form != "undefined") {
contract_form.parent_type = 'req';
contract_form.parent_id = id;
contract_form.id = contract_id;
contract_form.open();
}
},
//Вазврат данных из form_contract
return_contract_form(req_id) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_contracts',
parent_id: req_id,
type: 'req',
}, )
.then((response) => {
var res = response.data;
console.log(this.req);
console.log(req_id);
this.req[req_id].contracts = res.contracts;
this.req[req_id].contracts_name = res.contracts_name;
if (req_form.isReqForm) {
req_form.contracts = res.contracts;
}
})
.catch(function(error) {
console.error(error);
});
},
//Сохранить теги
save_activites(id) {
var name_tag = '';
var activities_temp = [];
console.log(this.req[id].activities);
console.log(this.req[id].activities_temp);
//this.req[id].activities = this.req[id].activities_temp;
for (var i = 0; i < this.req[id].activities_temp.length; i++) {
activities_temp.push(this.activities.find(a => a.id === this.req[id].activities_temp[i]));
}
this.req[id].activities = activities_temp;
//this.req[id].activities_name = name_tag;
this.req[id].add_tag = false;
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'save_activites',
req_id: this.req[id].id,
activities: this.req[id].activities_temp,
}, )
.then((response) => {
console.log(response.data);
})
.catch(function(error) {
console.error(error);
});
},
openCardClient(client_id) {
openClientEventsWindowNew(client_id, $('#session_to_send').val(), 0, 0, false, true);
},
//Проверка на пустоту
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;
}
},
//Открыть панель со смежными воронками
open_stagebars_funnels(req_id){
if(this.req['req'+req_id].is_active_funnels_adjacent){
this.req['req'+req_id].is_active_funnels_adjacent = false;
} else {
this.req['req'+req_id].is_active_funnels_adjacent = true;
this.get_adjacent_funnels_req(req_id);
}
},
get_adjacent_funnels_req(req_id){
axios.post('/ajax/vue_ajax/funnel_axios_vue.php', {
request: 'get_adjacent_funnels_req',
agency_id: this.agencyId,
req_id: req_id,
})
.then((response) => {
if(typeof ac == 'object'){
ac.closesStep = false;
ac.is_looad = false;
ac.is_load_open = false;
ac.isOpenPrevStep = false;
}
console.log(response.data);
if(response.data.html){
$('#funnels_adjacent_req_'+req_id).html(response.data.html);
}
})
.catch(function(error) {
console.log(error);
});
},
//Открыть карточку объекту
openObject(object_id) {
object_card.open(object_id);
},
//Открыть редактирование параметров автопоиска
openAutoSearchFiltr(req_id, filter_id) {
autosearch_filtr.openAutoSearchFiltr(req_id, filter_id);
},
//Открыть список объектов автопоиска
showAutoSearchObjects(filter_id, event) {
autosearch_objs.openAutoSearchResults(filter_id);
},
async kanbanListScroll(event) {
const container = this.$refs.kanbanList;
const scrollTop = container.scrollTop;
const scrollHeight = container.scrollHeight;
const clientHeight = container.clientHeight;
const divUl = $(container).find('.kanban__items-list');
if(divUl){
for(let i=0; i<divUl.length; i++){
if(i < 2){
// let divLi = $(divUl[i]).find('.block_li_kanban');
$(divUl[i]).addClass('no-heigth');
let heigthLi = $(divUl[i]).find('ul').height();
$(divUl[i]).removeClass('no-heigth');
/*console.log(clientHeight+scrollTop);
console.log(heigthLi);*/
//const isScrollingDown = scrollTop > this.lastScrollTop;
//this.lastScrollTop = scrollTop;
//console.log(this.isLoading, heigthLi >=clientHeight+scrollTop-250);
if (heigthLi >=clientHeight+scrollTop-250 && !this.isLoading) {
this.isLoading = true; // Устанавливаем флаг загрузки
console.log('loading reqs li');
this.page = this.page + 1;
await this.getList();
this.isLoading = false;
}
}
}
}
const isScrollingDown = scrollTop > this.lastScrollTop;
this.lastScrollTop = scrollTop; // Обновляем позицию скролла
// Проверка с учетом зазора в 50 пикселей
//if(this.userId != 5238){
if (isScrollingDown && scrollTop + clientHeight >= scrollHeight - 50 && !this.isLoading) {
this.isLoading = true; // Устанавливаем флаг загрузки
console.log('loading reqs');
this.page = this.page + 1;
await this.getList();
this.isLoading = false;
}
// }
},
},
mounted() {
if (document.location.pathname == '/requisitions.php') {
}
},
created: function() {
//this.getList();
$(".clients").removeClass("hidden");
$(".kanban__rails").removeClass("hidden");
$(".crm__table").removeClass("hidden");
}
})
}
//Форма
var req_form = new Vue({
el: '#req_form',
components: {
Multiselect: window.VueMultiselect.default,
vuejsDatepicker: window.vuejsDatepicker
},
data() {
return {
user_id: $("#session_user_id").val(),
userId: $("#session_user_id").val(),
funnel_id: $('#funnelIdClients').val(),
agency_id: $('#session_agency_id').val() || null,
isReqForm: false,
isError: false,
isFilterError: false,
is_looad: false,
errorText: '',
errorFilterText: '',
liGlobal: 1,
name: '',
autosearch_filter: [],
autosearch_filter_id: null,
fio: '',
email: '',
phone: '',
opis: '',
types_req: [{
"code": 0,
"name": "",
"order": -1,
"heir": 0,
"archive": 0,
"type": "label",
}],
selectedType: 0,
steps: [],
selectedObject: 0,
isObject: false,
isClient: false,
isNew: true,
req_id: 0,
object: [],
client: [],
nums: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
isClear: true,
clientId: 0,
funnel_type: 'main',
clientName: '',
newClientName: '',
newClientPhone: '',
dopPhonesClient: '',
inputClientName: false,
inputClientPhone: false,
is_national_phone: false,
is_error_dop_phone: false,
axios_processed: false,
prep_price: '',
start_price: '',
fact_price: '',
objectId: 0,
priority: 0,
isClientForm: false,
confirm: 1,
who_work: 0,
hot: 0,
autoSearch: false,
findObject: false,
findObj: [],
OpenIndicator: {
render: createElement => createElement('span', { class: { 'vueToggleSpan': true } }),
},
noEmptyClientId: 0,
reqFields: [],
reqFieldsLinking: [],
fieldModels: [],
contracts: [],
heir: 0,
clients: [],
client_id: 0,
spinner: true,
clientSelect: null,
debounceTimer: null,
wazzap_chat_type: null,
wazzap_chat_id: null,
wazzap_channel_id: null,
wazzap_user_id: null,
wazzap_integration_id: null,
complex_room_id: null,
confirm_recommendation: null,
recommendations: [{ 'code': 1, 'name': 'Да' }, { 'code': 2, 'name': 'Нет' }],
friend_client_id: 0,
source_see: 1,
no_can_edit_hot: 0,
}
},
methods: {
//Открыть форму
openReqForm(no_clear) {
this.is_looad = false;
this.isClear = false;
if (no_clear) {
this.getClients();
} else {
this.clearReq();
}
if ( $('input[name=complex_room_id]').length) {
this.selectedType = +this.selectedType ? this.selectedType : 1;
$('#status').show()
} else {
$('#status').hide()
}
console.log(this.isNew, no_clear);
if (this.isNew && no_clear != 1) {
this.getClients();
this.getWhowork(this.user_id);
this.getActivities();
this.getObject();
this.getTypes();
this.getSources(0);
this.getPartner(0);
if ($('input[name=complex_room_id]').length) {
this.getStatuses(4);
}
if (document.location.pathname == '/requisitions.php' && $('#funnelIdClients').length > 0) {
this.funnel_id = $('#funnelIdClients').val();
this.getFunnel(this.funnel_id);
} else
if (this.funnel_id === undefined || this.funnel_id == 0 || isNaN(this.funnel_id)) {
$.post("/ajax/getFunnelFirst.php", {is_req: 1}, function(dataf) {
//console.log(dataf);
var res_funnels = JSON.parse(dataf);
req_form.funnel_id = parseInt(res_funnels.funnel_id);
req_form.getFunnel(req_form.funnel_id);
req_form.getReqFields();
})
} else {
this.getFunnel(this.funnel_id);
}
this.getReqFields();
}
$("#req_form .tabs__content").removeAttr("style");
this.isReqForm = true;
// console.log(this);
$("body").addClass("lock");
$('.jw__add-popup').removeClass('is__show');
},
setReq(req) {
this.user_id = req.who_work;
this.funnel_id = req.funnel_id;
this.getFunnel(this.funnel_id);
this.name = req.name;
this.autosearch_filter = req.autosearch.filter;
if (req.autosearch_id > 0)
this.autosearch_filter_id = req.autosearch_id;
else if (req.asfilter_id > 0)
this.autosearch_filter_id = req.asfilter_id;
else
this.autosearch_filter_id = null;
this.opis = req.description.replace(/<br>/g, "\n");
this.selectedType = req.type_id;
this.steps = req.steps;
this.isNew = false;
this.autoSearch = false;
this.autoSearchEnabled = 0;
this.req_id = req.id;
this.getReqFields();
this.liGlobal = 1;
this.who_work = req.who_work;
this.confirm = req.confirm;
this.funnel_type = req.funnel_type;
this.prep_price = '';
this.start_price = '';
this.fact_price = '';
this.heir = req.heir_type;
if (req.type_id == 4 || req.heir_type == 4) {
this.autoSearch = true;
this.findObject = true;
this.autoSearchEnabled = (this.autosearch_filter_id && req.autosearch.is_reverse == "1") ? 1 : 0;
this.objectId = req.object_id;
this.getObjectFind(this.who_work);
} else if (req.type_id == 5 || req.heir_type == 4) {
this.autoSearch = false;
this.findObject = false;
this.objectId = req.object_id;
this.getObjectFind(this.who_work);
} else if (req.type_id == 1 || req.heir_type == 1) {
this.isObject = false;
this.autoSearch = true;
this.getObject();
this.object = [];
} else {
this.autoSearch = false;
this.findObject = false;
this.isObject = true;
this.getObject(req.object_id);
this.object = req.object;
if (req.type_id == 2 || req.heir_type == 2) {
/*this.price = req.object.stoim;
this.prep_price = req.object.prep_price;
this.start_price = req.object.start_price;
this.fact_price = req.object.fact_price;*/
this.getObjPrices(req.object_id);
}
setTimeout(function() {
$('.fotorama').fotorama();
//koala_loader();
}, 500);
}
/* if(req.type_id == 1){
this.isObject = false;
}*/
this.priority = req.priority;
this.client = req.client;
this.complex_room_id = req.complex_room_id
this.confirm_recommendation = req.confirm_recommendation;
this.friend_client_id = req.friend_client_id;
this.source_see = req.source_see;
this.no_can_edit_hot = req.no_can_edit_hot;
this.getClients(req.client_id);
this.getWhowork(req.who_work);
this.getSources(req.source);
this.getPartner(req.employee_id);
if ( !$('input[name=complex_room_id]').length) {
if (!this.isEmpty(req.complex_room_id)) {
const reqForm = document.querySelector('#req_form')
if (reqForm) {
const input = document.createElement('input')
input.type = 'hidden';
input.name = 'complex_room_id';
input.value = req.complex_room_id;
reqForm.appendChild(input)
}
}
}
if ( !$('input[name=complex_room_id]').length) {
$('#status').hide()
} else {
$('#status').show()
this.getStatuses(req.complex_status_id)
}
this.hot = req.hot;
if (req.activities) {
this.getActivities(req.activities_temp);
}
this.contracts = req.contracts;
},
//Получение дополнительных полей
getReqFields() {
console.log(this.funnel_id);
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_req_fields',
agency_id: this.agency_id,
req_id: this.req_id,
funnel_id: this.funnel_id,
user_id: this.userId,
}).then((response) => {
console.log(response.data);
this.reqFields = response.data.fields;
//console.log(this.reqFields);
this.reqFieldsLinking = response.data.linking_fields;
var values = response.data.values;
for (var i = 0; i < this.reqFields.length; i++) {
this.$set(this.fieldModels, 'model_' + this.reqFields[i].id, null);
if (this.reqFields[i].is_podgroup > 0) {
for (var j = 0; j < this.reqFields[i].podgroups.length; j++) {
this.$set(this.fieldModels, 'modelp_' + this.reqFields[i].podgroups[j].id, null);
}
}
}
for (var index in this.fieldModels) {
if (index.indexOf('model') != -1) {
if (!this.isEmpty(values[index])) {
this.fieldModels[index] = JSON.parse(values[index]);
}
}
}
// console.log(this.fieldModels);
}).catch(function(error) {
console.log(error);
});
},
//Получение предварительной оценки объекта
getObjPrices(objectId) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_object_prices',
user_id: this.user_id,
object_id: objectId
}).then((response) => {
console.log(response.data);
if (!req_form.isEmpty(response.data.prep_price) && response.data.prep_price > 0)
req_form.prep_price = response.data.prep_price;
else
req_form.prep_price = '';
if (!req_form.isEmpty(response.data.start_price) && response.data.start_price > 0)
req_form.start_price = response.data.start_price;
else
req_form.start_price = '';
if (!req_form.isEmpty(response.data.fact_price) && response.data.fact_price > 0)
req_form.fact_price = response.data.fact_price;
else
req_form.fact_price = '';
}).catch(function(error) {
console.log(error);
});
},
//Получение списка объектов
getObject(objectId) {
//console.log(this.user_id);
$("#req-new-object-input").html('');
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_objects',
user_id: this.user_id,
}, )
.then((response) => {
$("#req-new-object-input").html(response.data);
if (objectId) {
$("#req-new-object").val(objectId);
}
$("#req-new-object").fastselect({
placeholder: 'Объекты',
onItemSelect: function(item, val) {
//console.debug(val.value);
req_form.getObjPrices(val.value);
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_client',
client_id: 0,
object_id: val.value
}, )
.then((response) => {
// console.log(response.data);
if (!req_form.isEmpty(response.data)) {
$("#req-new-client-input").html('');
req_form.client = response.data;
req_form.clientId = response.data.value;
req_form.getClients(response.data.value);
}
})
.catch(function(error) {
console.log(error);
});
/*if(!req_form.isEmpty(val.objects)){
$("#req-new-object-input").html('');
req_form.getObject(val.objects[0]);
}*/
},
});
})
.catch(function(error) {
console.log(error);
});
},
getObjectFind(who_work, obj) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_objects_find',
object_id: this.objectId,
}, )
.then((response) => {
console.log(response.data);
this.findObj = response.data;
if (obj) {
this.opis = "Звонок по объекту " + this.findObj['nazv'] + " " + this.findObj['adres'];
}
//this.who_work = who_work;
this.getWhowork(who_work);
})
.catch(function(error) {
console.log(error);
});
},
//Автозаполнение названия заявки на основе типа заявки и имени клиента
fillReqName(client_name) {
console.log(client_name);
let ref = this;
let reg_type = 'Заявка';
if (!this.isEmpty(client_name)) {
if (this.types_req.length > 0) {
this.types_req.forEach(function(type, index) {
if (type['code'] == ref.selectedType && ref.selectedType !== 0) {
reg_type = type['name'];
}
});
}
this.name = reg_type + ' для ' + client_name;
}
},
showClientNameInput() {
this.inputClientName = true;
this.newClientName = this.clientName;
$('.ui-tooltip.ui-widget').remove();
},
hideClientNameInput() {
this.inputClientName = false;
this.newClientName = '';
$('.ui-tooltip.ui-widget').remove();
},
changeClientName(client_id) {
let ref = this;
if (typeof client_id !== "undefined")
ref.clientId = client_id;
if (!ref.axios_processed && ref.newClientName.length > 0) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'change_client_name',
user_id: $("#session_user_id").val(),
new_client_name: ref.newClientName,
client_id: ref.clientId
}).then((response) => {
if (response.data.success) {
ref.clientName = ref.newClientName;
if (document.location.pathname == '/requisitions.php') {
if (requisitions.view == 'kanban') {
for (var index in requisitions.req) {
for (var index2 in requisitions.req[index]) {
if (index2 == 'req' + ref.req_id) {
requisitions.req[index][index2].fio = ref.clientName;
break;
}
}
}
}
}
ref.fillReqName(ref.clientName);
ref.client.fio = ref.clientName;
ref.inputClientName = false;
ref.newClientName = '';
req_form.getClients(ref.clientId);
req_form.getClient(ref.clientId, 1);
$('.ui-tooltip.ui-widget').remove();
}
}).catch(function(error) {
if (error)
console.debug(error);
});
}
},
showClientPhoneInput() {
this.inputClientPhone = true;
this.newClientPhone = '';
this.is_national_phone = false;
this.dopPhonesClient = this.clientSelect.phones_dop;
this.is_error_dop_phone = false;
$('.ui-tooltip.ui-widget').remove();
},
hideClientPhoneInput() {
this.inputClientPhone = false;
this.newClientPhone = '';
this.is_national_phone = false;
this.dopPhonesClient = this.clientSelect.phones_dop;
this.is_error_dop_phone = false;
$('.ui-tooltip.ui-widget').remove();
},
checkIsNationalPhone(){
this.newClientPhone = '';
},
changeClientPhone(client_id) {
this.is_error_dop_phone = false;
if (typeof client_id !== "undefined")
this.clientId = client_id;
if (!this.isEmpty(this.newClientPhone)) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'change_client_phone',
agency_id: this.agency_id,
new_client_phone: this.newClientPhone,
client_id: client_id
}).then((response) => {
console.log(response.data);
let dopPhones = this.newClientPhone;
$('.ui-tooltip.ui-widget').remove();
if(response.data.success == 'error'){
this.is_error_dop_phone = true;
}
if(response.data.success == 'done'){
if(this.dopPhonesClient != '') this.dopPhonesClient += ', ';
this.dopPhonesClient += dopPhones;
this.newClientPhone = '';
this.clientSelect.phones_dop = this.dopPhonesClient;
}
}).catch(function(error) {
if (error)
console.debug(error);
});
}
},
selectClientList() {
console.log(this.clientSelect);
if (!this.isEmpty(this.clientSelect)) {
req_form.clientName = this.clientSelect.fio;
req_form.inputClientName = false;
req_form.inputClientPhone = false;
req_form.clientId = this.clientSelect.id;
req_form.dopPhonesClient = this.clientSelect.phones_dop;
req_form.fillReqName(req_form.clientName);
if (!req_form.isEmpty(this.clientSelect.objects)) {
$("#req-new-object-input").html('');
req_form.getObject(this.clientSelect.objects[0]);
}
}
},
//Получение списка клиентов
getClients(clientId) {
$("#req-new-client-input").html('');
$("#req-new-client-input").html('<input type="text" id="req-new-client" data-url="/ajax/list_clients.php?req=1" data-load-once="true">');
if (clientId) {
console.log(this.client);
req_form.clientId = clientId;
req_form.clientName = this.client.fio;
// this.getClientsList(this.client.fio);
this.clientSelect = { id: clientId, color: '#000', name: this.client.text, fio: this.client.fio, phones_dop: this.client.phones_dop };
$("#req-new-client").val(clientId);
$("#req-new-client").attr('data-initial-value', JSON.stringify(this.client));
$("#req-new-client").fastselect({
placeholder: 'Клиент',
onItemSelect: function(item, val) {
//console.debug({val, item});
req_form.clientName = val.fio;
req_form.inputClientName = false;
req_form.inputClientPhone = false;
req_form.clientId = val.value;
req_form.fillReqName(req_form.clientName);
if (!req_form.isEmpty(val.objects)) {
$("#req-new-object-input").html('');
req_form.getObject(val.objects[0]);
}
},
});
} else if (this.clientId > 0) {
console.log(this.clientId);
this.getClient(this.clientId, 1);
} else {
$("#req-new-client").fastselect({
placeholder: 'Клиент',
onItemSelect: function(item, val) {
//console.debug({val, item});
req_form.clientName = val.fio;
req_form.inputClientName = false;
req_form.inputClientPhone = false;
req_form.clientId = val.value;
req_form.fillReqName(req_form.clientName);
if (!req_form.isEmpty(val.objects)) {
$("#req-new-object-input").html('');
req_form.getObject(val.objects[0]);
}
},
});
}
},
//Получение списка ответственных
getWhowork(who_work) {
if(this.funnel_type == 'adjacent'){
axios.post('/ajax/select_form_client-work-adjacent.php', {
request: 'get_who_work',
funnel_id: this.funnel_id,
user_id: this.user_id,
})
.then((response) => {
//console.log(response.data);
$('#req-new-client-work-input-div').html(response.data);
$("#req-new-client-work").val(who_work);
$('#req-new-client-work').fastselect({
placeholder: 'Ответственный',
onItemCreate: function() { $(this).find('.fstQueryInput').hide() },
});
})
.catch(function(error) {
console.error(error);
});
} else {
if ($('#req-new-client-work').length < 1) {
axios.post('/ajax/select_form_client-work.php')
.then((response) => {
$('#req-new-client-work-input-div').html(response.data);
$("#req-new-client-work").val(who_work);
$('#req-new-client-work').fastselect({
placeholder: 'Ответственный',
onItemCreate: function() { $(this).find('.fstQueryInput').hide() },
});
})
.catch(function(error) {
console.error(error);
});
} else {
$('#req-new-client-work').fastselect().data('fastselect').destroy();
//$('#req-new-client-work-input').html(html);
$("#req-new-client-work").val(who_work);
$('#req-new-client-work').fastselect({
placeholder: 'Ответственный',
onItemCreate: function() { $(this).find('.fstQueryInput').hide() },
});
}
}
},
//Получение списка источников
getSources(source) {
if ($('#ms-req-source').length < 1) {
axios.post('/ajax/select_form_source.php')
.then((response) => {
$('#ms-req-source-input').html(response.data);
$("#ms-req-source").val(source);
$('#ms-req-source').fastselect({
placeholder: 'Источник',
onItemCreate: function() { $(this).find('.fstQueryInput').hide() },
});
})
.catch(function(error) {
console.error(error);
});
} else {
$('#ms-req-source').fastselect().data('fastselect').destroy();
$("#ms-req-source").val(source);
$('#ms-req-source').fastselect({
placeholder: 'Источник',
onItemCreate: function() { $(this).find('.fstQueryInput').hide() },
});
}
},
getStatuses(selectedStatus) {
if ($('#status').length) {
if ($('#ms-req-status').length < 1) {
axios.post('/ajax/select_form_status.php')
.then(response => {
$('#ms-req-status-input').html(response.data);
$("#ms-req-status").val(selectedStatus);
$('#ms-req-status').fastselect({
placeholder: 'Выберите статус',
onItemCreate: function() { $(this).find('.fstQueryInput').hide() },
});
})
} else {
$('#ms-req-status').fastselect().data('fastselect').destroy();
$("#ms-req-status").val(selectedStatus);
$('#ms-req-status').fastselect({
placeholder: 'Выберите статус',
onItemCreate: function() { $(this).find('.fstQueryInput').hide() },
});
}
}
},
//Получение партнеров
getPartner(employee_id) {
if ($('#ms-req-partner').length < 1) {
axios.post('/ajax/select_form_partner.php')
.then((response) => {
$('#ms-req-partner-input').html(response.data);
$("#ms-req-partner").val(employee_id);
$('#ms-req-partner').fastselect({
placeholder: 'Партнер',
onItemCreate: function() { $(this).find('.fstQueryInput').hide() },
});
})
.catch(function(error) {
console.error(error);
});
} else {
$('#ms-req-partner').fastselect().data('fastselect').destroy();
$("#ms-req-partner").val(employee_id);
$('#ms-req-partner').fastselect({
placeholder: 'Партнер',
onItemCreate: function($item, itemModel) {
let partner_name = $("#ms-req-partner-input select option[value=" + itemModel.value + "]").data('partner');
itemModel.text = itemModel.text + ' <!-- ' + partner_name + ' -->';
$(this).find(".fstControls input.hidenClass").attr('type', "text");
$(this).find(".fstControls input.hidenClass").removeClass('hidenClass');
},
onItemSelect: function($item, itemModel) {
let partner_label = $("#ms-req-partner-input select option:selected").data("label");
if (partner_label)
$("#ms-req-partner-input select").closest(".inputs").find(".fstToggleBtn").text(partner_label);
$(this).find(".fstControls input.hidenClass").attr('type', "text");
$(this).find(".fstControls input.hidenClass").removeClass('hidenClass');
}
});
}
},
//Получение тегов
getActivities(tag) {
console.log(tag);
if ($('#req-new-client-activities').length < 1) {
axios.post('/ajax/select_form_activities.php')
.then((response) => {
$('#req-new-client-activities-input').html(response.data);
if (tag) {
$("#req-new-client-activities").val(tag);
} else {
$("#req-new-client-activities").val(null);
}
$('#req-new-client-activities').fastselect({
placeholder: 'Теги',
onItemCreate: function() { $(this).find('.fstQueryInput').hide() },
});
})
.catch(function(error) {
console.error(error);
});
} else {
if (tag) {
$("#req-new-client-activities").val(tag);
} else {
$("#req-new-client-activities").val(null);
}
$('#req-new-client-activities').fastselect().data('fastselect').destroy();
$('#req-new-client-activities').fastselect({
placeholder: 'Теги',
onItemCreate: function() { $(this).find('.fstQueryInput').hide() },
});
}
},
//Получение клиента
getClient(client_id, forma) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_client',
client_id: client_id
}, )
.then((response) => {
console.log(response.data);
this.client = response.data;
if (forma) {
req_form.clientName = this.client.fio;
//req_form.getClientsList(req_form.client.fio);
req_form.clientSelect = { id: client_id, color: '#000', name: req_form.client.text, fio: req_form.client.fio };
$("#req-new-client-input").html('');
$("#req-new-client-input").html('<input type="text" id="req-new-client" data-url="/ajax/list_clients.php?req=1" data-load-once="true">');
$("#req-new-client").val(this.clientId);
$("#req-new-client").attr('data-initial-value', JSON.stringify(this.client));
$("#req-new-client").fastselect({
placeholder: 'Клиент',
onItemSelect: function(item, val) {
req_form.clientName = val.fio;
req_form.fillReqName(req_form.clientName);
if (!req_form.isEmpty(val.objects)) {
$("#req-new-object-input").html('');
req_form.getObject(val.objects[0]);
}
},
});
}
})
.catch(function(error) {
console.log(error);
});
},
//Получение типов заявок
getTypes() {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_type',
agency_id: this.agency_id,
active: 1,
no_archive: 1
},
)
.then((response) => {
// console.log(response.data);
this.types_req = response.data.type;
})
.catch(function(error) {
console.log(error);
});
},
//Получение ворнки
getFunnel(funnelId) {
console.log(funnelId);
var params = {};
params.selector = 'req-new-funnel';
params.section = 'req';
$('#req-new-funnel-input').html('');
if ($('#req-new-funnel').length < 1) {
axios.post('/ajax/select_form_funnel.php', params)
.then((response) => {
$('#req-new-funnel-input').html(response.data);
$("#req-new-funnel option[value='" + funnelId + "']").prop("selected", true);
$('#req-new-funnel').fastselect({
placeholder: 'Воронка',
});
})
.catch(function(error) {
console.error(error);
});
} else {
$('#req-new-funnel').fastselect().data('fastselect').destroy();
$("#req-new-funnel").val(funnelId);
$("#req-new-funnel option[value='" + funnelId + "']").prop("selected", true);
$('#req-new-funnel').fastselect({
placeholder: 'Воронка',
});
}
},
//Закрыть форму
closeReqform() {
this.isReqForm = false;
this.clientSelect = null;
$("body").removeClass("lock");
if ($('#client-history__bg').css('display') == 'block' && $('#send_bg_new').css('display') == 'none') {
$('#client-history__bg').css('zIndex', '99998');
}
if($('#object_card .f__modal-bg').css('display') == 'none'){
$(".chat-cian").css("zIndex", "99999");
}
$('input[name=complex_room_id]').remove()
$('#status').hide()
},
//Переключение табов
changeLiGlobal(num) {
this.liGlobal = num;
if ($('#req_form .fotorama').data('fotorama')) {
$('#req_form .fotorama').data('fotorama').destroy();
//$('#object_card .fotorama').html('');
}
if (num == 4) {
setTimeout(function() {
$('#req_form .fotorama').fotorama();
//koala_loader();
}, 500);
}
},
//Переключение priority
changePriority(num) {
if (this.priority == num) {
this.priority = 0;
} else {
this.priority = num;
}
},
getClientsList(search, loading) {
// console.log(typeof loading);
if (typeof loading == 'function') {
loading(true);
}
var search_val = '';
if (!this.isEmpty(search)) {
search_val = search;
}
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_clients_list',
search: search_val,
})
.then((response) => {
//console.log(response.data);
this.clients = response.data;
if (typeof loading == 'function') {
loading(false);
}
})
.catch(function(error) {
console.log(error);
});
},
getClientsListNew(search, loading) {
clearTimeout(this.debounceTimer);
this.debounceTimer = setTimeout(() => this.getClientsList(search, loading), 500);
},
open_form_contract(id, contract_id, index) {
//console.log(contract_id);
if (typeof contract_form != "undefined") {
contract_form.parent_type = 'req';
contract_form.parent_id = id;
contract_form.id = contract_id;
contract_form.open();
if (id == 'req0' && index >= 0) {
contract_form.number = this.contracts[index].number;
contract_form.type_contract = this.contracts[index].type;
contract_form.date_start = this.contracts[index].date_start;
contract_form.date_end = this.contracts[index].date_end;
contract_form.days_mes_end = this.contracts[index].days_mes_end;
contract_form.no_mes_end = this.contracts[index].no_mes_end;
contract_form.parent_index = index;
}
}
},
//Открыть карточку объекту
openObject(object_id) {
object_card.open(object_id);
},
//Добавить/изменить заявку
addEditReq() {
this.is_looad = true;
var agencyID = $('#agencyIdClients').val();
this.errorText = '';
this.isError = false;
if ($('#status').length && $('input[name=complex_room_id]').length) {
if (this.isEmpty($("#ms-req-status").val())) {
this.isError = true;
this.errorText += "<p>Выберите статус</p>";
$('#ms-req-status').addClass('invalid');
$('#ms-req-status').closest('.fstElement').addClass('invalid');
} else {
$('#ms-req-status').removeClass('invalid');
$('#ms-req-status').closest('.fstElement').removeClass('invalid');
}
}
if (this.isEmpty(this.name)) {
this.isError = true;
this.errorText += "<p>Введите название</p>";
$('#req_name_form').addClass('invalid');
$('#req_name_form').closest('.fstElement').addClass('invalid');
} else {
$('#req_name_form').removeClass('invalid');
$('#req_name_form').closest('.fstElement').removeClass('invalid');
}
var object_id = 0;
if (this.findObject) {
if (this.isEmpty(this.findObj) || this.isEmpty(this.findObj.id)) {
this.isError = true;
this.errorText += "<p>Выберите объект</p>";
} else {
object_id = this.findObj.id;
}
} else
if ($("#req-new-object").val() && $("#req-new-object").val() > 0) {
object_id = $("#req-new-object").val();
}
var client_id = 0;
if ($("#req-new-client").val() && $("#req-new-client").val() > 0) {
client_id = $("#req-new-client").val();
}
// console.log(this.clientSelect);
if (!this.isEmpty(this.clientSelect) && !this.isEmpty(this.clientSelect.id)) {
client_id = this.clientSelect.id;
}
//console.log(client_id);
if (client_id == 0) {
this.isError = true;
this.errorText += "<p>Выберите клиента</p>";
$('#req-new-client').addClass('invalid');
$('#req-new-client').closest('.fstElement').addClass('invalid');
} else {
$('#req-new-client').removeClass('invalid');
$('#req-new-client').closest('.fstElement').removeClass('invalid');
}
var who_work = 0;
if($("#req-new-client-work").val() > 0){
who_work = $("#req-new-client-work").val();
}
var tags = 0;
tags = $("#req-new-client-activities").val();
var confirm = this.confirm;
if (this.isNew || this.who_work == 0) {
this.who_work = this.user_id;
}
if (this.who_work != who_work) {
confirm = 0;
}
if (this.selectedType != 1 && this.heir != 1 && this.selectedType != 4 && this.heir != 4) {
this.autosearch_filter_id = 0;
}
autosearch_filtr.$once('add_edit_autosearch_filter', function(filter_id, filter) {
if (typeof filter_id !== "undefined")
this.autosearch_filter_id = filter_id;
if (typeof filter !== "undefined")
this.autosearch_filter = filter;
console.debug(filter_id);
console.debug(this.autosearch_filter_id);
console.debug(filter);
console.debug(this.autosearch_filter);
});
var id_funnel = $('#req-new-funnel').val();
var source_id = $("#ms-req-source").val();
if (agencyID == 4135 || agencyID == 7384 || agencyID == 7864 || agencyID == 13154 || agencyID == 19111 || agencyID == 22666) {
if (source_id == 0) {
this.isError = true;
this.errorText += "<p>Не выбран рекламный источник</p>";
$('#ms-req-source').addClass('invalid');
$('#ms-req-source').closest('.fstElement').addClass('invalid');
} else {
$('#ms-req-source').removeClass('invalid');
$('#ms-req-source').closest('.fstElement').removeClass('invalid');
}
}
var poles = {};
if (!this.isEmpty(this.reqFields)) {
for (var i = 0; i < this.reqFields.length; i++) {
if (!this.isEmpty(this.fieldModels['model_' + this.reqFields[i].id]) && this.fieldModels['model_' + this.reqFields[i].id]) {
if (this.reqFields[i].type == 4) {
poles['model_' + this.reqFields[i].id] = 1;
} else {
poles['model_' + this.reqFields[i].id] = this.fieldModels['model_' + this.reqFields[i].id];
}
}
if (this.reqFields[i].is_podgroup > 0) {
for (var j = 0; j < this.reqFields[i].podgroups.length; j++) {
//console.log(this.fieldModels['modelp_11']);
if (!this.isEmpty(this.fieldModels['modelp_' + this.reqFields[i].podgroups[j].id]) && this.fieldModels['modelp_' + this.reqFields[i].podgroups[j].id]) {
$('#custom_req_p' + this.reqFields[i].podgroups[j].id).removeClass('invalid');
if (this.reqFields[i].podgroups[j].type == 4) {
poles['modelp_' + this.reqFields[i].podgroups[j].id] = 1;
} else {
poles['modelp_' + this.reqFields[i].podgroups[j].id] = this.fieldModels['modelp_' + this.reqFields[i].podgroups[j].id];
}
} else {
if (this.reqFields[i].podgroups[j].is_required > 0 && this.reqFields[i].podgroups[j].id == this.fieldModels['model_' + this.reqFields[i].id]) {
this.isError = true;
this.errorText += "<p>Не заполнено поле: " + this.reqFields[i].podgroups[j].title + "</p>";
$('#custom_req_p' + this.reqFields[i].podgroups[j].id).addClass('invalid');
}
}
}
}
if (this.reqFields[i].is_required > 0 && this.reqFields[i].is_close_step == 0) {
//console.log(JSON.parse(this.reqFields[i].req_type));
if (this.reqFields[i].req_type==0 || JSON.parse(this.reqFields[i].req_type).indexOf(this.selectedType) != -1) {
if (this.isEmpty(this.fieldModels['model_' + this.reqFields[i].id])) {
this.isError = true;
this.errorText += "<p>Не заполнено поле: " + this.reqFields[i].title + "</p>";
$('#custom_req_' + this.reqFields[i].id).addClass('invalid');
} else {
$('#custom_req_' + this.reqFields[i].id).removeClass('invalid');
}
}
}
}
}
const apartmentId = $("input[name=complex_room_id]").val();
const statusId = $("#ms-req-status").val();
if(agencyID == 19895) {
if(id_funnel === undefined || isNaN(parseInt(id_funnel)) || parseInt(id_funnel) == 0){
this.isError = true;
this.errorText += "<p>Не выбрана воронка</p>";
}
}
if (!this.isError) {
var params = {
request: 'add_edit',
user_id: this.user_id,
req_id: this.req_id,
funnel_id: id_funnel,
name: this.name,
autosearch_filter: this.autosearch_filter,
autosearch_filter_id: this.autosearch_filter_id,
fio: this.fio,
email: this.email,
phone: this.phone,
opis: this.opis.replace(/\n/g, "<br>"),
type_id: this.selectedType,
object_id: object_id,
client_id: client_id,
priority: this.priority,
price: this.price,
prep_price: this.prep_price,
start_price: this.start_price,
fact_price: this.fact_price,
who_work: who_work,
confirm: confirm,
old_whowork: this.who_work,
hot: this.hot,
activities: tags,
// source: $("#ms-req-source").val(),
employee_id: $("#ms-req-partner").val(),
status: statusId,
complex_room_id: apartmentId,
field_models: poles,
contracts: this.contracts,
autosearch_enabled: (this.autoSearchEnabled) ? 1 : 0,
newClientName: this.newClientName,
wazzap_channel_id: this.wazzap_channel_id,
wazzap_chat_id: this.wazzap_chat_id,
wazzap_chat_type: this.wazzap_chat_type,
wazzap_integration_id: this.wazzap_integration_id,
wazzap_user_id: this.wazzap_user_id,
confirm_recommendation: this.confirm_recommendation,
friend_client_id: this.friend_client_id,
is_manual: 1
}
if(this.source_see == 1){
params.source = $("#ms-req-source").val();
}
axios.post('/ajax/ajax_vue_requisitions.php', params, )
.then((response) => {
console.log(response.data);
refreshCalendar();
var res = response.data;
if (res.error == 1001) {
this.isError = true;
this.errorText += "<p>" + res.mes + "</p>";
$('.full_modal-bg').stop().animate({ scrollTop: 0 }, '500');
} else {
let req_id = parseInt(res.req_id);
autosearch_filtr.setReqToFilter(req_id, this.autosearch_filter_id);
this.closeReqform();
if (document.location.pathname == '/requisitions.php') {
if(requisitions.view == 'kanban'){
requisitions.get_req_id(req_id, 1);
} else {
requisitions.getList();
}
}
if ($('#client-history__bg').css('display') == 'block') {
if (parseInt(this.req_id) > 0) {
openClientEventsWindowNew(0, $('#session_to_send').val(), 0, this.req_id);
}
}
if ($('#send_bg_new').css('display') == 'block') {
var data_req = $('#ms-new-client-req').val();
if (data_req != '') data_req += ",";
data_req += req_id;
req_fastselect('ms-new-client-req-input', 'ms-new-client-req', data_req);
}
requisitions_client.getList();
if (location.href.includes('complexes/#')) {
window.complexBus.$emit('apartment-status-changed', { complex_status_id: statusId, req_id: response.data.req_id })
window.complexBus.$emit('change-apartment-status', apartmentId, statusId)
window.complexBus.$emit("change-apartment-reservations", response.data.reservations);
window.complexBus.$emit("change-apartment-created-requisition", response.data.requisitions);
}
}
})
.catch(function(error) {
console.error(error);
});
} else {
this.is_looad = false;
$('.full_modal-bg').stop().animate({ scrollTop: 0 }, '500');
}
},
//Очистка формы
clearReq() {
this.isError = false;
this.isFilterError = false;
this.errorText = '';
this.errorFilterText = '';
this.name = '';
this.autosearch_filter = [];
this.autosearch_filter_id = null;
this.liGlobal = 1;
this.fio = '';
this.email = '';
this.phone = '';
this.opis = '';
this.getTypes();
this.selectedType = 0;
this.isObject = false;
this.isNew = true;
this.req_id = 0;
this.object = [];
this.client = [];
this.isClear = true;
this.hot = 0;
this.priority = 0;
this.objectId = 0;
if (this.noEmptyClientId == 0) {
this.clientId = 0;
} else {
this.noEmptyClientId = 0;
}
this.funnel_type = 'main';
this.clientName = '';
this.newClientName = '';
this.inputClientName = false;
this.inputClientPhone = false;
this.axios_processed = false;
this.prep_price = '';
this.start_price = '';
this.fact_price = '';
this.findObj = [];
this.autoSearch = false;
this.autoSearchEnabled = false;
this.findObject = false;
this.contracts = [];
this.heir = 0;
this.confirm_recommendation = null,
this.friend_client_id = 0
},
selectType(val) {
//console.log(val);
this.findObject = false;
this.autoSearch = false;
this.autoSearchEnabled = false;
this.findObj = [];
var heir = 0;
this.heir = 0;
var temp_type = this.types_req.find((el, idx) => el.code == val);
console.info(this.types_req);
if (temp_type) {
if (temp_type.heir > 0) {
heir = temp_type.heir;
this.heir = heir;
}
}
autosearch_filtr.req_type = val;
this.is_search = 1;
this.is_reverse = 1;
if (val == 2 || heir == 2) {
this.isObject = true;
this.getObject();
} else if (val == 1 || heir == 1) {
this.isObject = false;
this.autoSearch = true;
this.findObject = false;
} else if (val == 4 || heir == 4) {
this.isObject = false;
this.findObject = true;
this.autoSearch = true;
this.autoSearchEnabled = 1;
} else if (val == 5 || heir == 5) {
this.isObject = false;
this.findObject = false;
} else {
this.isObject = true;
this.autoSearch = false;
}
this.fillReqName(this.clientName);
},
//открыть форму из объекта
openFormObj(idObj, who_work) {
this.openReqForm();
this.selectedType = 4;
this.findObject = true;
this.autoSearch = true;
this.findObject = true;
this.autoSearchEnabled = 1
this.objectId = idObj;
this.getObjectFind(who_work, idObj);
},
//Переключение горячий
toggleHot() {
if (this.hot == 0) {
this.hot = 1;
} else {
this.hot = 0;
}
},
//Открыть поиск объект
openFindObj() {
var html = '<div class="f__modal" id="modalFindObj" style="display: none; padding-bottom: 0px;">' +
'<span class="pseudo-link closer">×</span>' +
'<h3>Объекты</h3><div style="text-align:center; margin-top: 25px;"><img src="../images/rocket-spinner.svg" width="96px"></div>' +
'</div>';
$('#modalFindObj_bg').html(html).fadeIn(500);
$('#modalFindObj').toggle(10);
$("body").addClass("lock");
axios.post('/ajax/modals/findObjectsWinContent.php', {agency_id: this.agency_id})
.then((response) => {
$('#modalFindObj').html(response.data);
// $('#modalFindObj').toggle(10);
findObject();
installationComponentFindObj();
})
.catch(function(error) {
console.log(error);
});
},
//Открыть редактирование параметров автопоиска
openAutoSearchFiltr(req_id, filter_id) {
if (typeof req_id == "undefined")
req_id = this.req_id;
if (typeof filter_id == "undefined")
filter_id = this.autosearch_filter_id;
let res = this;
autosearch_filtr.openAutoSearchFiltr(req_id, filter_id);
autosearch_filtr.$once('add_edit_autosearch_filter', function(filter_id, filter) {
if (typeof filter_id !== "undefined")
res.autosearch_filter_id = filter_id;
if (typeof filter !== "undefined")
res.autosearch_filter = filter;
console.debug(filter_id);
console.debug(res.autosearch_filter_id);
console.debug(filter);
console.debug(res.autosearch_filter);
});
},
//Мини-форма редактирования параметра автопоиска
editAutoSearchParam(filter_id, param_id, event) {
/*let element = event.target;
let row = $(event.target).closest('tr[data-key="'+param_id+'"]');*/
let row = $('body').find('tr[data-key="' + param_id + '"]');
row.find('a.edit_param_btn').fadeOut();
row.find('a.delete_param_btn').fadeOut();
row.find('a.save_param_btn').fadeIn();
row.find('a.close_param_btn').fadeIn();
autosearch_filtr.editShortField(filter_id, param_id);
autosearch_filtr.$once('edit_short_field_input', function(html) {
row.find('td[data-key="value"]').html(html);
if (row.find('td[data-key="value"] select').length > 0) {
row.find('td[data-key="value"] select').fastselect();
} else if (row.find('td[data-key="value"] input.datepicker-here2').length > 0) {
row.find('td[data-key="value"] input.datepicker-here2').datepicker({
autoClose: 'true'
});
}
});
},
deleteAutoSearchParam(filter_id, param_id, event) {
let element = event.target;
let row = $(event.target).closest('tr[data-key="' + param_id + '"]');
if (confirm("Вы действительно желаете удалить параметр автопоиска?")) {
autosearch_filtr.deleteShortField(filter_id, param_id);
autosearch_filtr.$once('removed_short_field_value', function(field_id) {
if (param_id == field_id) {
row.remove();
}
});
}
},
openAutoSearchMap(filter_id, event) {
autosearch_filtr.openAutoSearchMap(filter_id, this.req_id, this.user_id);
},
saveAutoSearchParam(filter_id, param_id, event) {
let fields = [];
let values = [];
let input_id = param_id.replace('_', '-');
let row = $(event.target).closest('tr[data-key="' + param_id + '"]');
let input = row.find('#asfiltr-' + input_id + ' input, select, textarea, checkbox');
if (input.length > 0) {
input.each(function() {
let input_name = $(this).attr('name');
let input_value = $(this).val();
if ($(this).is(':checkbox')) {
input_value = ($(this).prop('checked')) ? "1" : "0";
}
if (typeof input_name !== "undefined" && typeof input_value !== "undefined") {
fields.push(input_name);
values.push(input_value);
}
console.debug({ input_name, input_value });
});
} else {
let input = $(event.target).closest('tr[data-key="' + param_id + '"]').find('#asfiltr-' + input_id);
let input_name = input.attr('name');
let input_value = input.val();
if (input.is(':checkbox')) {
input_value = (input.prop('checked')) ? "1" : "0";
}
if (typeof input_name !== "undefined" && typeof input_value !== "undefined") {
fields.push(input_name);
values.push(input_value);
}
console.debug({ input_name, input_value });
}
autosearch_filtr.saveShortField(filter_id, param_id, array_combine(fields, values));
autosearch_filtr.$once('edit_short_field_value', function(value) {
if (value !== null) {
row.find('td[data-key="value"]').data('origin', value);
row.find('td[data-key="value"]').html(value);
}
});
autosearch_filtr.$once('edit_short_field_error', function(error) {
if (error !== null) {
this.isFilterError = true;
this.errorFilterText = error;
}
});
if (document.location.pathname == '/requisitions.php') {
requisitions.getList();
}
row.find('a.save_param_btn').fadeOut();
row.find('a.close_param_btn').fadeOut();
row.find('a.edit_param_btn').fadeIn();
row.find('a.delete_param_btn').fadeIn();
},
closeAutoSearchParam(filter_id, param_id, event) {
let element = event.target;
let row = $(event.target).closest('tr[data-key="' + param_id + '"]');
row.find('a.close_param_btn').fadeOut();
row.find('a.save_param_btn').fadeOut();
row.find('a.edit_param_btn').fadeIn();
row.find('a.delete_param_btn').fadeIn();
let html = row.find('td[data-key="value"]').data('origin');
row.find('td[data-key="value"]').html(html);
},
deleteContract(index) {
if (confirm('Вы действительно хотите удалить этот договор?')) {
$('.ui-tooltip.ui-widget').remove();
if (this.req_id != 'req0') {
if (typeof contract_form != "undefined") {
contract_form.delete(this.contracts[index].id, 'req');
}
}
this.contracts.splice(index, 1);
}
},
//Поиск и сравнение
isFindValue(val1, val2){
let res = false;
if(!this.isEmpty(val2)){
if(Array.isArray(val2)){
for(let i=0; i<val2.length; i++){
if(val2[i] == val1){
res = true;
break;
}
}
} else {
if(val1 == val2){
res = true;
}
}
}
return res;
},
//Проверка на пустоту
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() {
this.getClientsList();
$("#req_form").removeClass("hidden");
$("#req_form .tabs__content").removeAttr("style");
}
})
//Фильтр
if ($('#req_filtr').length > 0) {
var filtr = new Vue({
el: '#req_filtr',
components: {
Multiselect: window.VueMultiselect.default,
vuejsDatepicker: window.vuejsDatepicker
},
data() {
return {
view: null,
viewUser: null,
user_id: $('#userIdReq').val(),
funnel_id: $('#funnelIdClients').val(),
agency_id: $('#session_agency_id').val() || null,
options: 0,
textOptions: ' опций',
reqFields: [],
fieldModels: [],
tempModel: [],
types_contract: [{ 'code': 0, 'type': '' }],
property_types: [],
filtr: {
search: "",
stages: { 'work': 1, 'hot': 0, 'close': 0, 'hit': 0, 'ahency': 0, 'confirm': 0, 'send': 0 },
confirm: 0,
send: 0,
emp: [],
type: [],
step: [],
priority: { 1: 0, 2: 0, 3: 0, 4: 0 },
object_id: $('#objectIdForReq').val() || '',
is_tasks: false,
noTasks: false,
todayTasks: false,
overTasks: false,
period: "all",
onDate: '',
offDate: '',
denial: [],
activities: [],
order: $('#sort_order_req').val(),
isPartner: false,
2026-06-18 13:16:44 +02:00
is_deal: false,
2026-05-22 20:21:54 +02:00
source: -1,
fields: {},
is_contract: false,
numder_contract: null,
onDateContract: '',
offDateContract: '',
type_contract: [],
date_closer: 10,
priceFrom: 0,
priceTo: 0,
property_type: null,
is_date_step: false,
onDateStep: '',
offDateStep: '',
total_union: null
},
OpenIndicator: {
render: createElement => createElement('span', { class: { 'vueToggleSpan': true } }),
},
}
},
methods: {
//Список
getFilter(clear) {
this.filtr = {
search: "",
stages: { 'work': 1, 'hot': 0, 'close': 0, 'hit': 0, 'ahency': 0, 'confirm': 0, 'send': 0 },
confirm: 0,
send: 0,
emp: [],
type: [],
step: [],
priority: { 1: 0, 2: 0, 3: 0, 4: 0 },
object_id: '',
is_tasks: false,
noTasks: false,
todayTasks: false,
overTasks: false,
period: "all",
onDate: '',
offDate: '',
denial: [],
activities: [],
order: $('#sort_order_req').val(),
isPartner: false,
2026-06-18 13:16:44 +02:00
is_deal: false,
2026-05-22 20:21:54 +02:00
source: -1,
fields: {},
is_contract: false,
numder_contract: null,
onDateContract: '',
offDateContract: '',
type_contract: [],
date_closer: 10,
property_type: null,
tempModel: {},
fieldModels: {},
is_date_step: false,
onDateStep: '',
offDateStep: '',
currentFilterTypesParents: {},
}
if (clear == 1) {
filtr.$set(filtr.filtr.stages, 'work', 0);
}
},
//Получение дополнительных полей
getReqFields() {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_req_fields',
agency_id: this.agency_id,
req_id: this.req_id,
}).then((response) => {
//console.log(response.data);
this.reqFields = response.data.fields;
this.clearFields();
}).catch(function(error) {
console.log(error);
});
},
//Типы договоров
getTypesContract() {
axios.post('/ajax/ajax_vue_contract.php', {
request: 'get_types_contract',
agency_id: this.agency_id,
}, )
.then((response) => {
this.types_contract = response.data;
})
.catch(function(error) {
console.error(error);
});
},
//Типы недвижимости
getPropertyType() {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_property_types'
}).then((response) => {
//console.log(response.data);
this.property_types = response.data;
}).catch(function(error) {
console.log(error);
});
},
clearFields(clear) {
if (clear) {
this.tempModel = {};
}
if (this.reqFields) {
for (var i = 0; i < this.reqFields.length; i++) {
this.$set(this.fieldModels, 'model_' + this.reqFields[i].id, null);
if (this.tempModel['model_' + this.reqFields[i].id] && !this.isEmpty(this.tempModel['model_' + this.reqFields[i].id])) {
this.$set(this.fieldModels, 'model_' + this.reqFields[i].id, this.tempModel['model_' + this.reqFields[i].id]);
}
if (this.reqFields[i].is_podgroup > 0) {
for (var j = 0; j < this.reqFields[i].podgroups.length; j++) {
this.$set(this.fieldModels, 'modelp_' + this.reqFields[i].podgroups[j].id, null);
if (this.tempModel['modelp_' + this.reqFields[i].podgroups[j].id] &&
!this.isEmpty(this.tempModel['modelp_' + this.reqFields[i].podgroups[j].id])) {
this.$set(this.fieldModels, 'modelp_' + this.reqFields[i].podgroups[j].id, this.tempModel['modelp_' + this.reqFields[i].podgroups[j].id]);
}
}
}
}
}
setTimeout(function() { this.tempModel = {} }, 500);
},
//Для кастомных фильтров
checkFields() {
this.filtr.fields = {};
if (!this.isEmpty(this.reqFields)) {
for (var i = 0; i < this.reqFields.length; i++) {
if (!this.isEmpty(this.fieldModels['model_' + this.reqFields[i].id]) && this.fieldModels['model_' + this.reqFields[i].id]) {
if (this.reqFields[i].type == 4) {
this.filtr.fields['model_' + this.reqFields[i].id] = 1;
} else {
this.filtr.fields['model_' + this.reqFields[i].id] = this.fieldModels['model_' + this.reqFields[i].id];
}
}
if (this.reqFields[i].is_podgroup > 0) {
for (var j = 0; j < this.reqFields[i].podgroups.length; j++) {
//console.log(this.fieldModels['modelp_11']);
if (!this.isEmpty(this.fieldModels['modelp_' + this.reqFields[i].podgroups[j].id]) && this.fieldModels['modelp_' + this.reqFields[i].podgroups[j].id]) {
if (this.reqFields[i].podgroups[j].type == 4) {
this.filtr.fields['modelp_' + this.reqFields[i].podgroups[j].id] = 1;
} else {
this.filtr.fields['modelp_' + this.reqFields[i].podgroups[j].id] = this.fieldModels['modelp_' + this.reqFields[i].podgroups[j].id];
}
}
}
}
}
}
this.get_option();
//this.search();
},
//Количество фильтров
get_option() {
this.options = 0;
if (!this.isEmpty(this.filtr.search)) {
this.options++;
this.textOptions = " опции";
if (this.options == 1) this.textOptions = " опция";
if (this.options > 4) this.textOptions = " опций";
}
for (var st in this.filtr.stages) {
if (this.filtr.stages[st] == 1) {
this.options++;
}
}
for (var pr in this.filtr.priority) {
if (this.filtr.priority[pr] == 1) {
this.options++;
break;
}
}
if (!this.isEmpty(this.filtr.emp)) {
this.options++;
}
if (!this.isEmpty(this.filtr.type)) {
this.options++;
}
if (!this.isEmpty(this.filtr.property_type)) {
this.options++;
}
if (!this.isEmpty(this.filtr.activities)) {
this.options++;
}
if (!this.isEmpty(this.filtr.source) && this.filtr.source > 0) {
this.options++;
}
if (!this.isEmpty(this.filtr.employee_id)) {
this.options++;
}
if (!this.isEmpty(this.filtr.denial)) {
this.options++;
}
if (!this.isEmpty(this.filtr.step)) {
this.options++;
}
if (!this.isEmpty(this.filtr.object_id)) {
this.options++;
}
if (this.filtr.is_contract) {
this.options++;
}
if (this.filtr.is_tasks) {
this.options++;
}
if (this.filtr.noTasks) {
this.options++;
}
if (this.filtr.todayTasks) {
this.options++;
}
if (this.filtr.overTasks) {
this.options++;
}
if (this.filtr.isPartner) {
this.options++;
}
2026-06-18 13:16:44 +02:00
if (this.filtr.is_deal) {
this.options++;
}
2026-05-22 20:21:54 +02:00
if (this.filtr.fields && Object.keys(this.filtr.fields).length) {
this.options++;
}
if (this.filtr.is_date_step) {
this.options++;
}
},
searchButtonClick() {
this.checkFiltr();
this.search(0);
$('.crm__filter-popup').removeClass("is__show");
},
//Поиск
search(isLupa) {
//console.log(this.filtr.stages);
console.log(requisitions.isKanban);
console.log(this.filtr.order);
//console.log($('#sort_order_req').val(2));
if(requisitions.isKanban){
if(this.filtr.order === false || this.filtr.order == 0){
$('#sort_order_req').val(2);
}
}
if (isLupa && !requisitions.isKanban) {
requisitions.funnel_id = 'all';
} else {
requisitions.funnel_id = $('#funnelIdClients').val();
}
if (this.filtr.stages.close == 0) {
$('.closed_all').show();
$('.renew_all_reqs').hide();
$('.mass_take_from_closed').hide();
$('.confirm__reqs').show();
$('.transfer_reqs_closed').hide();
} else {
$('.closed_all').hide();
$('.renew_all_reqs').hide();
$('.mass_take_from_closed').show();
$('.confirm__reqs').hide();
$('.transfer_reqs_closed').show();
}
if (this.filtr.stages.ahency == 1 || this.filtr.stages.confirm == 1) {
$('.confirm_on_reqs').show();
$('#popup__reqs .closed_all').hide();
} else {
if (this.filtr.stages.close == 0){
$('#popup__reqs .closed_all').show();
}
$('.confirm_on_reqs').hide();
}
localStorage.removeItem('req_filter');
localStorage.setItem('req_filter', JSON.stringify(this.filtr));
requisitions.filtr = this.filtr;
requisitions.view = this.view;
requisitions.page = 1;
requisitions.getList();
},
clearFiltr() {
this.options = 0;
this.getFilter(1);
localStorage.removeItem('req_filter');
//this.filtr.stages.work = 0;
//console.log(this.filtr);
this.getSelect('req_filter_emp_input', 'req_filter_emp', 'Ответственный');
this.getSelect('filter-req-type-input', 'filter-req-type', 'Тип');
this.getSelect('req_filter_etap_input', 'req_filter_etap', 'Этап');
this.getSelect('req_filter_period_input', 'req_filter_period', 'Период', 'all');
this.getSelect('req_denial_work_input', 'req_denial_work', 'Причина закрытия');
this.getSelect('req_filter_activities_input', 'req_filter_activities', 'Теги');
this.getSelect('req_filter-source_input', 'req_filter-source', 'Источники');
this.getSelect('req_filter_partner_input', 'req_filter_partner', 'Партнеры');
$('#reqOnDate').val('');
$('#reqOffDate').val('');
$('#reqDates').addClass('hidden');
this.fieldModels = {};
this.clearFields(1);
this.get_option();
this.search();
},
clearSearch() {
this.filtr.search = '';
this.get_option();
this.search();
},
checkStage(stage) {
//console.log(stage);
for (var st in this.filtr.stages) {
if (st == stage) {
if (this.filtr.stages[st] == 1) {
this.filtr.stages[st] = 0;
} else {
this.filtr.stages[st] = 1;
}
} else {
this.filtr.stages[st] = 0;
}
}
this.get_option();
//this.search();
},
//Категории
checkPriority(pr) {
if (this.filtr.priority[pr] == 1) {
this.filtr.priority[pr] = 0;
} else {
this.filtr.priority[pr] = 1;
}
this.get_option();
//this.search();
},
//Выбор id объекта
checkObjectId() {
this.get_option();
//this.search();
},
//По задачам
checkTasks() {
this.get_option();
//this.search();
},
checkFiltr() {
var denial = $('#req_denial_work').val();
this.filtr.denial = denial;
console.log(decodeURI(window.location.search));
var queryParams = parseQueryString(decodeURI(window.location.search));
var activities = $('#req_filter_activities').val();
this.filtr.activities = activities;
var source = $('#req_filter-source').val();
this.filtr.source = source;
var employee_id = $('#req_filter_partner').val();
this.filtr.employee_id = employee_id;
this.getReqFields();
var period = $('#req_filter_period').val();
if (queryParams) {
console.log(queryParams);
if (queryParams.emp !== undefined) {
this.filtr.userId = queryParams.emp;
} else if(queryParams.responsible !== undefined){
this.filtr.userId = queryParams.responsible;
}
if(queryParams.filter_emp !== undefined){
console.log(queryParams.filter_emp.replace('[\'','').replace('\']',''));
this.filtr.userId = queryParams.filter_emp.replace('[\'','').replace('\']','');
this.filtr.is_stats = 1
}
if (queryParams.filter_stage !== undefined) {
this.filtr.filter_stage = queryParams.filter_stage;
this.filtr.stages = { 'work': 0, 'hot': 0, 'close': 0, 'hit': 0, 'ahency': 0, 'confirm': 0, 'send': 0 };
if (queryParams.filter_stage == 'filter_stage_work') {
this.filtr.stages.work = 1;
this.filtr.stages.send = 1;
this.filtr.stages.confirm = 1;
}
if (queryParams.filter_stage == 'filter_stage_close') {
this.filtr.stages.close = 1;
}
if (queryParams.filter_stage == 'filter_stage_hit') {
this.filtr.stages.hit = 1;
}
}
if (queryParams.isPartner !== undefined) {
this.filtr.isPartner = 1;
}
if (queryParams.denial !== undefined) {
this.filtr.denial = [queryParams.denial];
}
if (queryParams.date_closer !== undefined) {
this.filtr.date_closer = queryParams.date_closer;
}
if (queryParams.expired_stages !== undefined) {
this.filtr.expired_stages = queryParams.expired_stages;
}
if (queryParams.source !== undefined) {
this.filtr.source = queryParams.source.split(',');
}
if (queryParams.activities !== undefined) {
this.filtr.activities = queryParams.activities.split(',');
}
if (queryParams.partner !== undefined) {
this.filtr.employee_id = queryParams.partner.split(',');
}
if (queryParams.step !== undefined) {
this.filtr.step_id = queryParams.step;
}
if (queryParams.transmitted !== undefined) {
this.filtr.transmitted = queryParams.transmitted;
}
if (queryParams.accepted !== undefined) {
this.filtr.accepted = queryParams.accepted;
}
if(period == 'period'){
if(queryParams.date_start !== undefined) {
this.filtr.date_start = queryParams.date_start;
}
if(queryParams.date_end !== undefined) {
this.filtr.date_end = queryParams.date_end;
}
}
}
var tempemp = $("#req_filter_emp").val();
var emp = [];
if(!this.isEmpty(tempemp)){
for(var i=0; i < tempemp.length; i++){
emp.push(tempemp[i].replace('I_',''));
}
}
this.filtr.emp = emp;
var types = $('#filter-req-type').val();
this.filtr.type = types;
var step = $('#req_filter_etap').val();
this.filtr.step = step;
if (period == 'period') {
$('#reqDates').removeClass('hidden');
} else {
$('#reqOnDate').val('');
$('#reqOffDate').val('');
$('#reqDates').addClass('hidden');
}
this.filtr.period = period;
var onDate = $('#reqOnDate').val();
this.filtr.onDate = onDate;
var offDate = $('#reqOffDate').val();
this.filtr.offDate = offDate;
var onDateContract = $('#contractReqOnDate').val();
this.filtr.onDateContract = onDateContract;
var offDateContract = $('#contractReqOffDate').val();
this.filtr.offDateContract = offDateContract;
this.filtr.onDateStep = $('#dateStepReqOnDate').val();
this.filtr.offDateStep = $('#dateStepReqOffDate').val();
this.tempModel = {};
if (!this.isEmpty(this.filtr.fields)) {
for (var index in this.filtr.fields) {
if (index.indexOf('model') != -1) {
this.$set(this.tempModel, index, this.filtr.fields[index]);
}
}
}
console.log(this.filtr);
this.checkFields();
this.get_option();
// Установка связей с родительскими типами
this.currentFilterTypesParents = JSON.parse($('#filter-req-type-parents').val() || '{}')
if (Object.values(this.filtr.type ?? {}).map(v => parseInt(v)).filter(
// Включаем цену только по определённым типам + дочерним от них
// 1 - Подбор объекта
// 4 - Спрос по нашему объекту
v => [1, 4].includes(v) || [1, 4].includes(this.currentFilterTypesParents[v])
).length) {
this.filtr.priceFrom = parseInt($('#filter-popup-price-from').val())
this.filtr.priceTo = parseInt($('#filter-popup-price-to').val())
}
else {
this.filtr.priceFrom = undefined
this.filtr.priceTo = undefined
}
},
getSelect(id, idf, name, value) {
if ($('#' + idf).length > 0) {
$('#' + idf).fastselect().data('fastselect').destroy();
if (!this.isEmpty(value)) {
$('#' + idf).val(value);
} else {
$('#' + idf).val(null);
}
$('#' + idf).fastselect({
placeholder: name,
onItemCreate: function(item, model) {
if ($('#' + idf).find('option[value=' + model.value + ']').hasClass('bolt')) {
$(item).addClass('bolt');
}
},
onItemSelect: function(item, val) {
filtr.checkFiltr();
},
onItemDelete: function() {
filtr.checkFiltr();
}
});
}
},
setSelectReolad() {
this.getSelect('req_filter_emp_input', 'req_filter_emp', 'Ответственный', this.filtr.emp);
this.getSelect('filter-req-type-input', 'filter-req-type', 'Тип', this.filtr.type);
this.getSelect('req_filter_activities_input', 'req_filter_activities', 'Теги', this.filtr.activities);
this.getSelect('req_filter-source_input', 'req_filter-source', 'Источники', this.filtr.source);
this.getSelect('req_filter_partner_input', 'req_filter_partner', 'Партнеры', this.filtr.employee_id);
this.getSelect('req_denial_work_input', 'req_denial_work', 'Причина закрытия', this.filtr.denial);
this.getSelect('req_filter_period_input', 'req_filter_period', 'Период', this.filtr.period);
this.getSelect('req_filter_etap_input', 'req_filter_etap', 'Этап', this.filtr.step);
if (this.filtr.period == 'period') {
$('#reqOnDate').val(this.filtr.onDate);
$('#reqOffDate').val(this.filtr.offDate);
$('#reqDates').removeClass('hidden');
}
$('#contractReqOnDate').val(this.filtr.onDateContract);
$('#contractReqOffDate').val(this.filtr.offDateContract);
$('#dateStepReqOnDate').val(this.filtr.onDateStep);
$('#dateStepReqOffDate').val(this.filtr.offDateStep);
if (!this.isEmpty(this.filtr.fields)) {
for (var index in this.filtr.fields) {
if (index.indexOf('model') != -1) {
this.$set(this.tempModel, index, this.filtr.fields[index]);
}
}
}
},
getViews(){
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_view_page',
user_id: this.user_id,
}, ).then((response) => {
console.log(response.data);
this.viewUser = response.data.view;
this.view = response.data.view;
this.search();
}).catch(function(error) {
console.error(error);
})
},
setViews(view){
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'set_view_page',
user_id: this.user_id,
view: view
}, ).then((response) => {
console.log(response.data);
}).catch(function(error) {
console.error(error);
})
if(this.view != view) {
requisitions.view = view;
requisitions.getList();
}
this.viewUser = view;
this.view = view;
},
//Проверка на пустоту
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() {
if (document.location.pathname == '/requisitions.php') {
this.getTypesContract();
this.getPropertyType();
if (document.location.search && document.location.search.indexOf("resetFilter=1") < 0) {
if (localStorage['req_filter']) {
var req_filte = localStorage.getItem('req_filter');
//console.log(req_filte);
this.filtr = JSON.parse(req_filte);
this.setSelectReolad();
}
}
this.checkFiltr();
this.getViews();
/* if (localStorage['view_req']) {
this.view = localStorage['view_req'];
}*/
} else {
localStorage.removeItem('req_filter');
}
},
created: function() {
$(".crm_req").show();
}
})
}
if ($("#client_fields").length > 0) {
var client_fields = new Vue({
el: '#client_fields',
components: {
Multiselect: window.VueMultiselect.default,
vuejsDatepicker: window.vuejsDatepicker
},
data() {
return {
agency_id: $('#session_agency_id').val() || null,
user_id: $("#session_user_id").val(),
OpenIndicator: {
render: createElement => createElement('span', { class: { 'vueToggleSpan': true } }),
},
clientFields: [],
fieldModels: [],
client_id: 0,
}
},
methods: {
//Получение дополнительных полей
getClientFields() {
axios.post('/ajax/ajax_vue_fields.php', {
request: 'get_client_fields',
agency_id: this.agency_id,
client_id: this.client_id,
user_id: this.user_id
}).then((response) => {
//console.log(response.data);
this.clientFields = response.data.fields;
var values = response.data.values;
for (var i = 0; i < this.clientFields.length; i++) {
this.$set(this.fieldModels, 'model_' + this.clientFields[i].id, null);
if (this.clientFields[i].is_podgroup > 0) {
for (var j = 0; j < this.clientFields[i].podgroups.length; j++) {
this.$set(this.fieldModels, 'modelp_' + this.clientFields[i].podgroups[j].id, null);
}
}
}
for (var index in this.fieldModels) {
if (index.indexOf('model') != -1) {
if (!this.isEmpty(values[index])) {
this.fieldModels[index] = JSON.parse(values[index]);
}
}
}
//console.log(this.fieldModels);
}).catch(function(error) {
console.log(error);
});
},
//Добавить/изменить заявку
addEditFields(poles, client_id) {
var agencyID = $('#agencyIdClients').val();
axios.post('/ajax/ajax_vue_fields.php', {
request: 'add_edit',
client_id: client_id,
field_models: poles,
},
)
.then((response) => {
refreshCalendar();
console.log(response.data);
})
.catch(function(error) {
console.error(error);
});
},
//Очистка формы
clearField() {
this.getReqFields();
this.client_id = 0;
},
//Поиск и сравнение
isFindValue(val1, val2){
let res = false;
if(!this.isEmpty(val2)){
if(Array.isArray(val2)){
for(let i=0; i<val2.length; i++){
if(val2[i] == val1){
res = true;
break;
}
}
} else {
if(val1 == val2){
res = true;
}
}
}
return res;
},
//Проверка на пустоту
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() {
$("#client_fields").removeClass("hidden");
this.getClientFields();
}
})
}
if ($("#client_fields_filtr").length > 0) {
var client_fields_filtr = new Vue({
el: '#client_fields_filtr',
components: {
Multiselect: window.VueMultiselect.default,
vuejsDatepicker: window.vuejsDatepicker
},
data() {
return {
agency_id: $('#session_agency_id').val() || null,
OpenIndicator: {
render: createElement => createElement('span', { class: { 'vueToggleSpan': true } }),
},
clientFields: [],
fieldModels: [],
client_id: 0,
types_contract: [],
filtr: {
fields: {},
is_contract: false,
numder_contract: null,
onDateContract: '',
offDateContract: '',
type_contract: [],
},
}
},
methods: {
//Получение дополнительных полей
getClientFields() {
axios.post('/ajax/ajax_vue_fields.php', {
request: 'get_client_fields',
agency_id: this.agency_id,
client_id: this.client_id,
}).then((response) => {
//console.log(response.data);
this.clientFields = response.data.fields;
var values = response.data.values;
for (var i = 0; i < this.clientFields.length; i++) {
this.$set(this.fieldModels, 'model_' + this.clientFields[i].id, null);
if (this.clientFields[i].is_podgroup > 0) {
for (var j = 0; j < this.clientFields[i].podgroups.length; j++) {
this.$set(this.fieldModels, 'modelp_' + this.clientFields[i].podgroups[j].id, null);
}
}
}
}).catch(function(error) {
console.log(error);
});
},
//Для кастомных фильтров
checkFields() {
//console.log(this.fieldModels);
this.filtr.fields = {};
if (!this.isEmpty(this.clientFields)) {
for (var i = 0; i < this.clientFields.length; i++) {
if (!this.isEmpty(this.fieldModels['model_' + this.clientFields[i].id]) && this.fieldModels['model_' + this.clientFields[i].id]) {
if (this.clientFields[i].type == 4) {
this.filtr.fields['model_' + this.clientFields[i].id] = 1;
} else {
this.filtr.fields['model_' + this.clientFields[i].id] = this.fieldModels['model_' + this.clientFields[i].id];
}
}
if (this.clientFields[i].is_podgroup > 0) {
for (var j = 0; j < this.clientFields[i].podgroups.length; j++) {
//console.log(this.fieldModels['modelp_11']);
if (!this.isEmpty(this.fieldModels['modelp_' + this.clientFields[i].podgroups[j].id]) && this.fieldModels['modelp_' + this.clientFields[i].podgroups[j].id]) {
if (this.clientFields[i].podgroups[j].type == 4) {
this.filtr.fields['modelp_' + this.clientFields[i].podgroups[j].id] = 1;
} else {
this.filtr.fields['modelp_' + this.clientFields[i].podgroups[j].id] = this.fieldModels['modelp_' + this.clientFields[i].podgroups[j].id];
}
}
}
}
}
}
var onDateContract = $('#contractClientOnDate').val();
this.filtr.onDateContract = onDateContract;
var offDateContract = $('#contractClientOffDate').val();
this.filtr.offDateContract = offDateContract;
if (document.location.pathname == '/clients.php') {
show_options_search();
page_kanban = 1;
add_knban = true;
//get_list();
}
},
//Типы договоров
getTypesContract() {
axios.post('/ajax/ajax_vue_contract.php', {
request: 'get_types_contract',
agency_id: this.agency_id,
}, )
.then((response) => {
this.types_contract = response.data;
})
.catch(function(error) {
console.error(error);
});
},
//Очистка формы
clearField() {
this.getClientFields();
this.filtr.fields = {};
this.filtr.is_contract = false;
this.filtr.numder_contract = null;
this.filtr.onDateContract = '';
this.filtr.offDateContract = '';
this.filtr.onDateStep = '';
this.filtr.offDateStep = '';
this.filtr.type_contract = [];
$('#contractClientOnDate').val('');
$('#contractClientOffDate').val('');
$('#dateStepReqOnDate').val('');
$('#dateStepReqOffDate').val('');
},
//Проверка на пустоту
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() {
$("#client_fields_filtr").removeClass("hidden");
this.getClientFields();
this.getTypesContract();
}
})
}
//Для клиентов в add_object.php
if ($('#object-new-client-input-vue').length > 0) {
var object_new_client_input_vue = new Vue({
el: '#object-new-client-input-vue',
components: {
// Multiselect: window.VueMultiselect.default,
//vuejsDatepicker: window.vuejsDatepicker
},
data() {
return {
OpenIndicator: {
render: createElement => createElement('span', { class: { 'vueToggleSpan': true } }),
},
clients: [],
client_id: 0,
spinner: true,
clientSelect: [],
debounceTimer: null,
}
},
methods: {
selectClientList() {
//console.log(selectedOption);
this.client_id = 0;
//console.log(this.clientSelect);
//bindObjReq();
if (!isEmpty(this.clientSelect)) {
this.client_id = this.clientSelect[this.clientSelect.length - 1].id;
bindObjReq(this.client_id);
this.setValueInput();
} else {
this.client_id = 0;
this.setValueInput();
}
},
setValueInput() {
var values = [];
for (var i = 0; i < this.clientSelect.length; i++) {
values.push(this.clientSelect[i].id);
}
$("#object-new-client-vue").val(JSON.stringify(values));
},
getClientsList(search, loading) {
// console.log(typeof loading);
if (typeof loading == 'function') {
loading(true);
}
var search_val = '';
if (!isEmpty(search)) {
search_val = search;
}
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_clients_list',
search: search_val,
})
.then((response) => {
// console.log(response.data);
this.clients = response.data;
if (typeof loading == 'function') {
loading(false);
}
})
.catch(function(error) {
console.error(error);
});
},
getClientsListNew(search, loading) {
clearTimeout(this.debounceTimer);
this.debounceTimer = setTimeout(() => this.getClientsList(search, loading), 500);
},
search_client(client_id) {
// console.log(client_id);
if (parseInt(client_id) > 0) {
// $("#object-new-client-vue").val(client_id);
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_client',
client_id: client_id
}, )
.then((response) => {
console.log(response.data);
var this_client = response.data;
var index = this.clientSelect.length;
this.$set(this.clientSelect, index, { id: client_id, color: '#000', name: this_client.text, fio: this_client.fio });
this.setValueInput();
})
.catch(function(error) {
console.error(error);
});
}
},
checkClient() {
var clientsId = JSON.parse($("#object-new-client-vue").val());
// console.log(clientsId.length);
if (clientsId.length > 0) {
for (var i = 0; i < clientsId.length; i++) {
this.clientId = clientsId[i];
this.search_client(clientsId[i]);
}
}
}
},
mounted() {
},
created: function() {
this.getClientsList();
this.checkClient();
$("#object-new-client-input-vue").closest('.klient').removeClass("hidden");
}
})
//console.log(typeof object_new_client_input_vue);
}