Joywork/js/requisitions_client_vue.js
2026-07-06 21:13:55 +03:00

1305 lines
48 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Vue.config.devtools = true;
Vue.component('v-select', VueSelect.VueSelect);
// JW-style toast (стили — crm.css). Дубликат из requisitions_vue.js с idempotent-гардом.
if (typeof window.jwShowCopyToast !== 'function') {
window.jwShowCopyToast = function (text) {
var container = document.getElementById('jw-toast-container');
if (!container) {
container = document.createElement('div');
container.id = 'jw-toast-container';
container.className = 'jw-toast-container';
document.body.appendChild(container);
}
var toast = document.createElement('div');
toast.className = 'jw-toast';
toast.textContent = String(text || '');
container.appendChild(toast);
void toast.offsetWidth; // reflow для transition
toast.classList.add('jw-toast-show');
setTimeout(function () {
toast.classList.remove('jw-toast-show');
setTimeout(function () {
if (toast.parentNode) toast.parentNode.removeChild(toast);
}, 250);
}, 3500);
};
}
var requisitions_client = new Vue({
el: '#requisitions_list_client',
name: 'requisitions_list_client',
components: {
Multiselect: window.VueMultiselect.default,
vuejsDatepicker: window.vuejsDatepicker
},
data() {
return {
req: [],
isAddObj: 0,
isPreloader: 0,
user_id: $("#sid").attr("data-id"),
funnel_id: $('#funnelIdClients').val(),
clientId: 0,
isReqClient: 0,
}
},
methods: {
//Список
getList() {
if (this.clientId > 0) {
this.req = [];
this.isAddObj = 0;
$('#addReqClientFormList').attr("data-client", this.clientId);
this.isReqClient = 0;
if (document.location.pathname == '/add-object.php' || document.location.pathname == '/my-objects.php' || document.location.pathname == '/agency-objects.php') {
this.isAddObj = 1;
}
//requisitions_client.isPreloader=true;
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_all',
client_id: this.clientId,
funnel_id: this.funnel_id,
//user_id: this.user_id,
}, )
.then((response) => {
this.req = response.data.req;
//requisitions_client.isPreloader=false;
if (!requisitions_client.isEmpty(requisitions_client.req)) {
this.isReqClient = 1;
//$("#requisitions_list_client .clients").show();
} else {
this.isReqClient = 2;
}
})
.catch(function(error) {
console.log(error);
});
}
},
//Получение бара воронки
getBarFunnel(reqId) {
if (this.req['req' + reqId]) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_bar_funnel',
funnel_id: this.req['req' + reqId].funnel_id,
req_id: reqId
}, )
.then((response) => {
this.req['req' + reqId].steps = response.data;
requisitions_client.isPreloader = 0;
})
.catch(function(error) {
console.log(error);
});
}
},
//Для редактирования
getReq(id) {
$('#send_bg_new .closer').click();
req_form.openReqForm();
if (this.req[id] === undefined) {
//console.log(this.req[id]);
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_req_id',
req_id: id
}, )
.then((response) => {
//console.log(response.data);
requisitions_client.$set(requisitions_client, 'req', response.data);
//console.log(requisitions_client.req[id].object_id);
if (requisitions_client.req[id].object_id > 0 && requisitions_client.isEmpty(requisitions_client.req[id].object)) {
requisitions_client.getObject(requisitions_client.req[id].object_id, id, 1);
} else {
req_form.setReq(requisitions_client.req[id]);
}
if (this.req[id].client_id > 0 && this.isEmpty(this.req[id].client)) {
this.getClient(this.req[id].client_id, id, 1);
} else {
req_form.setReq(requisitions_client.req[id]);
}
})
.catch(function(error) {
console.log(error);
});
} else {
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_client.req[id]);
}
if (this.req[id].client_id > 0 && this.isEmpty(this.req[id].client)) {
this.getClient(this.req[id].client_id, id, 1);
} else {
req_form.setReq(requisitions_client.req[id]);
}
}
},
//Получение объекта
getObject(object_id, reqId, forma) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_object',
object_id: object_id
}, )
.then((response) => {
console.log(response.data);
this.req[reqId].object = response.data;
if (forma) {
req_form.setReq(requisitions_client.req[reqId]);
}
})
.catch(function(error) {
console.log(error);
});
},
//Получение клиента
getClient(client_id, reqId, forma) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_client',
client_id: client_id
}, )
.then((response) => {
console.log(response.data);
this.req[reqId].client = response.data;
if (forma) {
req_form.setReq(requisitions_client.req[reqId]);
}
})
.catch(function(error) {
console.log(error);
});
},
//открыть/закрыть подробности
toggleClient(id) {
if (this.req[id].isMainInfo) {
this.req[id].isMainInfo = false;
} else {
if (this.req[id].object_id > 0 && this.isEmpty(this.req[id].object)) {
this.getObject(this.req[id].object_id, id);
}
if (this.req[id].client_id > 0 && this.isEmpty(this.req[id].client)) {
this.getClient(this.req[id].client_id, id);
}
this.req[id].isMainInfo = true;
}
},
//показать объект
showObject(id) {
$('#liObject').click();
},
//показать клиента
showClient() {
$('#liGlobal').click();
},
openCardClient(client_id, ignoreFunnelsUpdate = false) {
openClientEventsWindowNew(client_id, $('#session_to_send').val(), 0, undefined, undefined, ignoreFunnelsUpdate);
},
//Проверка на пустоту
isEmpty(data) {
if (typeof(data) === 'object') {
if (JSON.stringify(data) === '{}' || JSON.stringify(data) === '[]') {
return true;
} else if (!data) {
return true;
}
return false;
} else if (typeof(data) === 'string') {
if (!data.trim()) {
return true;
}
return false;
} else if (typeof(data) === 'undefined') {
return true;
} else {
return false;
}
},
//Открыть редактирование параметров автопоиска
openAutoSearchFiltr(req_id, filter_id) {
autosearch_filtr.openAutoSearchFiltr(req_id, filter_id);
},
//Открыть список объектов автопоиска
showAutoSearchObjects(filter_id, event) {
let req_id = $(event.target).data('id');
$('#send_bg_new').fadeOut(300);
$('#send_new').toggle(100);
$("body").removeClass("lock");
autosearch_objs.openAutoSearchResults(filter_id, req_id);
},
},
mounted() {
//this.getList();
},
created: function() {
$(".clients").removeClass("hidden");
}
})
var requisitions_object = new Vue({
el: '#requisitions_list_object',
components: {
Multiselect: window.VueMultiselect.default,
vuejsDatepicker: window.vuejsDatepicker
},
data() {
return {
req: [],
//isPreloader: true,
agency_id: $('#session_agency_id').val(),
user_id: $("#sid").attr("data-id"),
//funnel_id: $('#funnelIdClients').val(),
objectId: 0,
isReqClient: 0,
isShow: false,
page: 1,
all_pages: 1,
prevPage: 0,
ot: 0,
do: 0,
pagePagin: [],
}
},
methods: {
//Список
getList() {
this.req = [];
requisitions_object.isReqClient = 0;
this.pagePagin = [];
this.ot = 0;
this.do = 0;
var requestData = {
request: 'get_all',
object_id: this.objectId,
page: this.page,
per_page: 5,
};
if (this.periodStart && this.periodEnd) {
requestData.filtr = {
period: 'period',
onDate: this.periodStart,
offDate: this.periodEnd
};
}
//console.log(this.objectId);
//requisitions_client.isPreloader=true;
axios.post('/ajax/ajax_vue_requisitions.php', requestData)
.then((response) => {
// console.log(response.data);
this.req = response.data.req;
//requisitions_client.isPreloader=false;
if (!requisitions_object.isEmpty(requisitions_object.req)) {
requisitions_object.isReqClient = 1;
this.all_pages = parseInt(response.data.allPages);
if (this.all_pages > 1) {
if (this.page > 1)
this.prevPage = this.page - 1;
}
if (this.all_pages > 8) {
if (this.page > 4) {
this.ot = this.page - 3;
} else {
this.ot = 2;
}
if (this.page < this.all_pages - 4) {
this.do = this.page + 3;
} else {
this.do = this.all_pages;
}
} else {
this.ot = 2;
this.do = this.all_pages;
}
for (var i = this.ot; i < this.do; i++) {
this.pagePagin.push(i);
}
//$("#requisitions_list_client .clients").show();
} else {
requisitions_object.isReqClient = 2;
}
})
.catch(function(error) {
console.log(error);
});
},
//Пагинация
pagin(page) {
this.page = page;
this.getList();
},
//Пагинация
goToRequisitionsPage(event) {
if (event.keyCode === 13) {
var pageNum = $('#requisitionClientPageNumberInputForManualGoToPage').val();
if (pageNum) {
this.page = Number.parseInt(pageNum);
this.getList();
$('#requisitionClientPageNumberInputForManualGoToPage').val('');
}
}
},
//Получение бара воронки
getBarFunnel(reqId) {
if (this.req['req' + reqId]) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_bar_funnel',
funnel_id: this.req['req' + reqId].funnel_id,
req_id: reqId
}, )
.then((response) => {
this.req['req' + reqId].steps = response.data;
requisitions_client.isPreloader = 0;
})
.catch(function(error) {
console.log(error);
});
}
},
//Для редактирования
getReq(id) {
$('#send_bg_new .closer').click();
req_form.openReqForm();
if (this.req[id] === undefined) {
//console.log(this.req[id]);
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_req_id',
req_id: id
}, )
.then((response) => {
//console.log(response.data);
requisitions_object.$set(requisitions_object, 'req', response.data);
//console.log(requisitions_client.req[id].object_id);
if (requisitions_object.req[id].object_id > 0 && requisitions_object.isEmpty(requisitions_object.req[id].object)) {
requisitions_object.getObject(requisitions_object.req[id].object_id, id, 1);
} else {
req_form.setReq(requisitions_object.req[id]);
}
if (this.req[id].client_id > 0 && this.isEmpty(this.req[id].client)) {
this.getClient(this.req[id].client_id, id, 1);
} else {
req_form.setReq(requisitions_object.req[id]);
}
})
.catch(function(error) {
console.log(error);
});
} else {
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_object.req[id]);
}
if (this.req[id].client_id > 0 && this.isEmpty(this.req[id].client)) {
this.getClient(this.req[id].client_id, id, 1);
} else {
req_form.setReq(requisitions_object.req[id]);
}
}
},
//Получение объекта
getObject(object_id, reqId, forma) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_object',
object_id: object_id
}, )
.then((response) => {
console.log(response.data);
this.req[reqId].object = response.data;
if (forma) {
req_form.setReq(requisitions_object.req[reqId]);
}
})
.catch(function(error) {
console.log(error);
});
},
//Получение клиента
getClient(client_id, reqId, forma) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_client',
client_id: client_id
}, )
.then((response) => {
console.log(response.data);
this.req[reqId].client = response.data;
if (forma) {
req_form.setReq(requisitions_object.req[reqId]);
}
})
.catch(function(error) {
console.log(error);
});
},
//открыть/закрыть подробности
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) {
$('#liObject').click();
},
//показать клиента
showClient() {
$('#liGlobal').click();
},
//Открыть форму
openForm(objectId, periodStart, periodEnd) {
console.log('openForm', objectId, periodStart, periodEnd);
this.page = 1;
this.isShow = true;
this.objectId = objectId;
this.periodStart = periodStart;
this.periodEnd = periodEnd;
this.getList();
$("body").addClass("lock");
},
//закрыть форму
closeForm() {
this.isShow = false;
$("body").removeClass("lock");
},
openCardClient(client_id, ignoreFunnelsUpdate = false) {
openClientEventsWindowNew(client_id, $('#session_to_send').val(), 0, undefined, undefined, ignoreFunnelsUpdate);
},
//Проверка на пустоту
isEmpty(data) {
if (typeof(data) === 'object') {
if (JSON.stringify(data) === '{}' || JSON.stringify(data) === '[]') {
return true;
} else if (!data) {
return true;
}
return false;
} else if (typeof(data) === 'string') {
if (!data.trim()) {
return true;
}
return false;
} else if (typeof(data) === 'undefined') {
return true;
} else {
return false;
}
},
},
mounted() {
//this.getList();
},
created: function() {
$("#requisitions_list_object").removeClass("hidden");
}
})
var room_requisitions = new Vue({
name: 'room_requisitions',
el: '#room_requisitions',
components:
{
Multiselect: window.VueMultiselect.default,
vuejsDatepicker: window.vuejsDatepicker
},
data()
{
return {
requisitions: [],
agency_id: $('#session_agency_id').val(),
user_id: $("#sid").attr("data-id"),
complexRoomId: 0,
apartmentTitle: null,
inProgress: false,
isShow: false,
page: 1,
all_pages: 1,
prevPage: 0,
ot: 0,
do: 0,
pagePagin: [],
complexBus: null,
// Состояние модалки копирования заявки. employees — серверный пререндер window.__copyEmployeesList; фильтр в Vue (без Select2).
copyModal: {
open: false,
srcId: null,
funnels: [],
funnelId: null,
employees: [],
whoWorkId: null,
whoWorkSearch: '',
whoWorkOpen: false,
whoWorkLabel: '',
defaultWhoWorkId: null,
warnings: [],
submitting: false,
error: null,
},
}
},
computed: {
// Фильтр сотрудников по whoWorkSearch (case-insensitive).
copyFilteredEmployees: function() {
var q = (this.copyModal.whoWorkSearch || '').toLowerCase().trim();
var emps = this.copyModal.employees || [];
if (!q) return emps;
return emps.filter(function(e) {
return (e.name || '').toLowerCase().indexOf(q) !== -1;
});
}
},
methods:
{
//Список
getList()
{
this.requisitions = [];
this.inProgress = true;
this.pagePagin = [];
this.ot = 0;
this.do = 0;
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_all',
complex_room_id: this.complexRoomId,
page: this.page,
per_page: 5,
})
.then((response) => {
this.requisitions = response.data.req;
if (!this.isEmpty(this.requisitions)) {
this.all_pages = parseInt(response.data.allPages);
if (this.all_pages > 1) {
if (this.page > 1)
this.prevPage = this.page - 1;
}
if (this.all_pages > 8) {
if (this.page > 4) {
this.ot = this.page - 3;
} else {
this.ot = 2;
}
if (this.page < this.all_pages - 4) {
this.do = this.page + 3;
} else {
this.do = this.all_pages;
}
} else {
this.ot = 2;
this.do = this.all_pages;
}
for (var i = this.ot; i < this.do; i++) {
this.pagePagin.push(i);
}
//$("#requisitions_list_client .clients").show();
}
})
.catch(function(error) {
console.log(error);
})
.finally(() => this.inProgress = false);
},
//Пагинация
pagin(page)
{
this.page = page;
this.getList();
},
//Пагинация
goToRequisitionsPage(event)
{
if (event.keyCode === 13) {
var pageNum = $('#requisitionClientPageNumberInputForManualGoToPage').val();
if (pageNum) {
this.page = Number.parseInt(pageNum);
this.getList();
$('#requisitionClientPageNumberInputForManualGoToPage').val('');
}
}
},
//Получение бара воронки
getBarFunnel(reqId)
{
if (this.requisitions['req' + reqId]) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_bar_funnel',
funnel_id: this.requisitions['req' + reqId].funnel_id,
req_id: reqId
}, )
.then((response) => {
this.requisitions['req' + reqId].steps = response.data;
requisitions_client.isPreloader = 0;
})
.catch(function(error) {
console.log(error);
});
}
},
//Для редактирования
getReq(id)
{
$('#send_bg_new .closer').click();
req_form.openReqForm();
if (this.requisitions[id] === undefined) {
//console.log(this.req[id]);
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_req_id',
req_id: id
}, )
.then((response) => {
this.$set(this, 'requisitions', response.data);
if (this.requisitions[id].complex_room_id > 0 && this.isEmpty(this.requisitions[id].object)) {
this.getRoom(this.requisitions[id].complex_room_id, id, 1);
} else {
req_form.setReq(this.requisitions[id]);
}
if (this.requisitions[id].client_id > 0 && this.isEmpty(this.requisitions[id].client)) {
this.getClient(this.requisitions[id].client_id, id, 1);
} else {
req_form.setReq(this.requisitions[id]);
}
})
.catch(function(error) {
console.log(error);
});
} else {
if (this.requisitions[id].complex_room_id > 0 && this.isEmpty(this.requisitions[id].object)) {
this.getRoom(this.requisitions[id].complex_room_id, id, 1);
} else {
req_form.setReq(this.requisitions[id]);
}
if (this.requisitions[id].client_id > 0 && this.isEmpty(this.requisitions[id].client)) {
this.getClient(this.requisitions[id].client_id, id, 1);
} else {
req_form.setReq(this.requisitions[id]);
}
}
},
//Получение объекта
getRoom(complex_room_id, reqId, forma)
{
axios.post('/ajax/vue_ajax/complex_axios.php', {
request: 'get_room_requisitions',
complex_room_id
}, )
.then((response) => {
this.requisitions[reqId].object = response.data;
if (forma) {
req_form.setReq(this.requisitions[reqId]);
}
})
.catch(function(error) {
console.log(error);
});
},
//Получение клиента
getClient(client_id, reqId, forma)
{
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_client',
client_id: client_id
}, )
.then((response) => {
this.requisitions[reqId].client = response.data;
if (forma) {
req_form.setReq(this.requisitions[reqId]);
}
})
.catch(function(error) {
console.log(error);
});
},
//открыть/закрыть подробности
toggleClient(id)
{
if (this.requisitions[id].isMainInfo) {
this.requisitions[id].isMainInfo = false;
} else {
if (this.requisitions[id].complex_room_id > 0 && this.isEmpty(this.requisitions[id].object)) {
this.getRoom(this.requisitions[id].complex_room_id, id);
}
if (this.requisitions[id].client_id > 0 && this.isEmpty(this.requisitions[id].client)) {
this.getClient(this.requisitions[id].client_id, id);
}
this.requisitions[id].isMainInfo = true;
}
},
//показать объект
showObject()
{
$('#liObject').click();
},
//показать клиента
showClient()
{
$('#liGlobal').click();
},
//Открыть форму
openForm(complexRoomId)
{
this.page = 1;
this.isShow = true;
this.complexRoomId = complexRoomId;
this.getList();
$("body").addClass("lock");
},
//закрыть форму
closeForm()
{
this.isShow = false;
$("body").removeClass("lock");
},
openCardClient(client_id, ignoreFunnelsUpdate = false) {
openClientEventsWindowNew(client_id, $('#session_to_send').val(), 0, undefined, undefined, ignoreFunnelsUpdate);
},
//Проверка на пустоту
isEmpty(data)
{
if (typeof(data) === 'object') {
if (JSON.stringify(data) === '{}' || JSON.stringify(data) === '[]') {
return true;
} else if (!data) {
return true;
}
return false;
} else if (typeof(data) === 'string') {
if (!data.trim()) {
return true;
}
return false;
} else if (typeof(data) === 'undefined') {
return true;
} else {
return false;
}
},
observeRefs()
{
setInterval(() => {
if (window.complexBus) {
this.complexBus = window.complexBus
}
}, 200)
},
// Открыть модалку копирования. Funnels/employees — серверный пререндер из room_requisitions.php / footer.php.
openCopyRequisitionModal: function(reqId) {
var self = this;
var preFunnels = Array.isArray(window.__copyFunnelsList) ? window.__copyFunnelsList : [];
var preEmployees = Array.isArray(window.__copyEmployeesList) ? window.__copyEmployeesList : [];
var employeesNormalized = preEmployees.map(function (e) {
return {
id: parseInt(e.id, 10),
name: e.name,
group: e.group || null,
};
});
self.copyModal = {
open: true,
srcId: reqId,
funnels: preFunnels.map(function (f) {
return { id: parseInt(f.id, 10), name: f.name };
}),
funnelId: null,
employees: employeesNormalized,
whoWorkId: null,
whoWorkSearch: '',
whoWorkOpen: false,
whoWorkLabel: '',
defaultWhoWorkId: null,
warnings: [],
submitting: false,
error: null,
};
axios.post('/ajax/ajax_vue_requisitions.php', {request: 'copy_preview', req_id: reqId})
.then(function (res) {
if (!res.data.success) {
self.copyModal.error = res.data.error || 'Не удалось загрузить данные';
return;
}
self.copyModal.warnings = res.data.warnings || [];
// Дефолтная воронка — из исходника, иначе первая доступная.
var defaultFunnelId = res.data.default_funnel_id;
var funnelMatch = self.copyModal.funnels.find(function (f) {
return parseInt(f.id, 10) === parseInt(defaultFunnelId, 10);
});
if (funnelMatch) {
self.copyModal.funnelId = parseInt(defaultFunnelId, 10);
} else if (self.copyModal.funnels.length > 0) {
self.copyModal.funnelId = self.copyModal.funnels[0].id;
} else {
self.copyModal.funnelId = null;
}
self.copyModal.defaultWhoWorkId = res.data.default_who_work_id;
var defaultId = res.data.default_who_work_id;
var hasInList = employeesNormalized.some(function (e) { return e.id === parseInt(defaultId, 10); });
var chosenId = hasInList
? parseInt(defaultId, 10)
: (employeesNormalized.length > 0 ? employeesNormalized[0].id : null);
self.copyModal.whoWorkId = chosenId;
// whoWorkLabel — имя в свернутом поле; whoWorkSearch держим пустым (полный список при открытии).
var chosenEmp = employeesNormalized.find(function (e) { return e.id === chosenId; });
self.copyModal.whoWorkLabel = chosenEmp ? chosenEmp.name : '';
self.copyModal.whoWorkSearch = '';
self.copyModal.whoWorkOpen = false;
})
.catch(function () {
self.copyModal.error = 'Сетевая ошибка';
});
},
// Выбор сотрудника. Сбрасываем whoWorkSearch, чтобы следующий раз показать полный список.
selectCopyWhoWork: function(emp) {
this.copyModal.whoWorkId = emp.id;
this.copyModal.whoWorkLabel = emp.name;
this.copyModal.whoWorkSearch = '';
this.copyModal.whoWorkOpen = false;
},
// Отправка копии: создаёт заявку и обновляет список комнаты.
submitCopy: function() {
var self = this;
if (self.copyModal.submitting) return;
var whoWorkId = parseInt(self.copyModal.whoWorkId, 10);
if (isNaN(whoWorkId) || self.copyModal.funnelId === null || self.copyModal.funnelId === undefined) {
self.copyModal.error = 'Заполните воронку и ответственного';
return;
}
self.copyModal.submitting = true;
self.copyModal.error = null;
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'copy',
req_id: self.copyModal.srcId,
funnel_id: self.copyModal.funnelId,
who_work_id: whoWorkId,
}).then(function (res) {
self.copyModal.submitting = false;
if (!res.data.success) {
self.copyModal.error = res.data.error || 'Не удалось создать копию';
return;
}
self.copyModal.open = false;
if (typeof window.jwShowCopyToast === 'function') {
window.jwShowCopyToast('Копия заявки создана');
}
if (typeof self.getList === 'function') self.getList();
}).catch(function () {
self.copyModal.submitting = false;
self.copyModal.error = 'Сетевая ошибка';
});
},
// Закрыть модалку копирования.
closeCopyModal: function() {
this.copyModal.open = false;
},
// Закрытие picker сотрудников по клику вне него (mousedown, чтобы опередить click внутри).
onCopyModalDocumentClick: function(e) {
if (!this.copyModal.whoWorkOpen) return;
var picker = this.$refs && this.$refs.copyWhoWorkPicker;
if (picker && (picker === e.target || picker.contains(e.target))) return;
this.copyModal.whoWorkOpen = false;
}
},
mounted()
{
this.$nextTick(() => {
this.observeRefs();
});
document.addEventListener('mousedown', this.onCopyModalDocumentClick);
},
beforeDestroy: function()
{
document.removeEventListener('mousedown', this.onCopyModalDocumentClick);
},
watch:
{
complexBus(complexBus)
{
if (complexBus) {
complexBus.$on('apartment-open-requisitions', (apartment) => {
if (apartment)
{
this.complexRoomId = apartment.id
this.apartmentTitle = apartment.title
this.getList();
this.isShow = true;
}
});
}
},
// Watch 'copyModal.funnelId' удалён: список сотрудников не зависит от воронки, заполняется один раз из window.__copyEmployeesList.
},
created: function()
{
$("#room_requisitions").removeClass("hidden");
}
})
var room_reservation = new Vue({
name: 'room_reservation',
el: '#room_reservation',
components:
{
Multiselect: window.VueMultiselect.default,
vuejsDatepicker: window.vuejsDatepicker
},
data()
{
return {
reservation: [],
agency_id: $('#session_agency_id').val(),
user_id: $("#sid").attr("data-id"),
reservationId: 0,
apartmentTitle: null,
inProgress: false,
isShow: false,
complexBus: null
}
},
methods:
{
getReservation()
{
this.reservation = [];
this.inProgress = true;
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_req_id',
req_id: this.reservationId
})
.then((response) => {
this.reservation = response.data[`req${this.reservationId}`];
})
.catch(function(error) {
console.error(error);
})
.finally(() => this.inProgress = false);
},
//Получение бара воронки
getBarFunnel(reqId)
{
if (this.reservationId == reqId) {
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_bar_funnel',
funnel_id: this.reservation.funnel_id,
req_id: reqId
}, )
.then((response) => {
this.reservation.steps = response.data;
requisitions_client.isPreloader = 0;
})
.catch(function(error) {
console.error(error);
});
}
},
//Для редактирования
getReq(id)
{
$('#send_bg_new .closer').click();
req_form.openReqForm();
if (this.reservationId === undefined) {
//console.log(this.req[id]);
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_req_id',
req_id: id
}, )
.then((response) => {
this.$set(this, 'reservation', response.data);
if (this.reservation.complex_room_id > 0 && this.isEmpty(this.reservation.object)) {
this.getRoom(this.reservation.complex_room_id, id, 1);
} else {
req_form.setReq(this.reservation);
}
if (this.reservation.client_id > 0 && this.isEmpty(this.reservation.client)) {
this.getClient(this.reservation.client_id, id, 1);
} else {
req_form.setReq(this.reservation);
}
})
.catch(function(error) {
console.error(error);
});
} else {
if (this.reservation.complex_room_id > 0 && this.isEmpty(this.reservation.object)) {
this.getRoom(this.reservation.complex_room_id, id, 1);
} else {
req_form.setReq(this.reservation);
}
if (this.reservation.client_id > 0 && this.isEmpty(this.reservation.client)) {
this.getClient(this.reservation.client_id, id, 1);
} else {
req_form.setReq(this.reservation);
}
}
},
//Получение объекта
getRoom(complex_room_id, reqId, forma)
{
axios.post('/ajax/vue_ajax/complex_axios.php', {
request: 'get_room_requisitions',
complex_room_id
})
.then((response) => {
this.reservation.object = response.data;
if (forma) {
req_form.setReq(this.reservation);
}
})
.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) => {
this.reservation.client = response.data;
if (forma) {
req_form.setReq(this.reservation);
}
})
.catch(function(error) {
console.error(error);
});
},
//открыть/закрыть подробности
toggleClient(id)
{
if (this.reservation.isMainInfo) {
this.reservation.isMainInfo = false;
} else {
if (this.reservation.complex_room_id > 0 && this.isEmpty(this.reservation.object)) {
this.getRoom(this.reservation.complex_room_id, id);
}
if (this.reservation.client_id > 0 && this.isEmpty(this.reservation.client)) {
this.getClient(this.reservation.client_id, id);
}
this.reservation.isMainInfo = true;
}
},
//показать объект
showObject()
{
$('#liObject').click();
},
//показать клиента
showClient()
{
$('#liGlobal').click();
},
//Открыть форму
openForm(reservationId)
{
this.page = 1;
this.isShow = true;
this.reservationId = reservationId;
this.getList();
$("body").addClass("lock");
},
//закрыть форму
closeForm()
{
this.isShow = false;
$("body").removeClass("lock");
},
openCardClient(client_id, ignoreFunnelsUpdate = false) {
openClientEventsWindowNew(client_id, $('#session_to_send').val(), 0, undefined, undefined, ignoreFunnelsUpdate);
},
//Проверка на пустоту
isEmpty(data)
{
if (typeof(data) === 'object') {
if (JSON.stringify(data) === '{}' || JSON.stringify(data) === '[]') {
return true;
} else if (!data) {
return true;
}
return false;
} else if (typeof(data) === 'string') {
if (!data.trim()) {
return true;
}
return false;
} else if (typeof(data) === 'undefined') {
return true;
} else {
return false;
}
},
observeRefs()
{
setInterval(() => {
if (window.complexBus) {
this.complexBus = window.complexBus
}
}, 200)
}
},
mounted()
{
this.$nextTick(() => {
this.observeRefs();
});
},
watch:
{
complexBus(complexBus)
{
if (complexBus) {
complexBus.$on('apartment-open-reservation', (reservation) => {
if (reservation)
{
openClientEventsWindowNew(0, $('#session_to_send').val(), 0, reservation.id);
// this.reservationId = reservation.id
// this.apartmentTitle = reservation.apartment_title
// this.getReservation();
// this.isShow = true;
}
});
}
}
},
created: function()
{
$("#room_reservation").removeClass("hidden");
}
})