fix close step
This commit is contained in:
parent
0054d5c328
commit
c7a10511cc
@ -436,19 +436,23 @@ var ac = new Vue({
|
|||||||
|
|
||||||
// Сначала загружаем данные сделки, потом открываем модал
|
// Сначала загружаем данные сделки, потом открываем модал
|
||||||
var loadDealData = function(callback) {
|
var loadDealData = function(callback) {
|
||||||
|
console.log('[DEAL_CLOSE] loadDealData started, reqId:', ac.reqId);
|
||||||
axios.post('/ajax/ajax_vue_requisitions.php', {
|
axios.post('/ajax/ajax_vue_requisitions.php', {
|
||||||
request: 'get_deal_by_req',
|
request: 'get_deal_by_req',
|
||||||
req_id: ac.reqId,
|
req_id: ac.reqId,
|
||||||
})
|
})
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
var res = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
|
var res = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
|
||||||
|
console.log('[DEAL_CLOSE] get_deal_by_req response:', res);
|
||||||
if (res.deal_id) {
|
if (res.deal_id) {
|
||||||
|
console.log('[DEAL_CLOSE] found deal_id:', res.deal_id, ', loading deal data...');
|
||||||
axios.post('/ajax/ajax_vue_requisitions.php', {
|
axios.post('/ajax/ajax_vue_requisitions.php', {
|
||||||
request: 'get_deal_data',
|
request: 'get_deal_data',
|
||||||
deal_id: res.deal_id,
|
deal_id: res.deal_id,
|
||||||
})
|
})
|
||||||
.then(function(dealRes) {
|
.then(function(dealRes) {
|
||||||
var dealData = dealRes.data.deal;
|
var dealData = dealRes.data.deal;
|
||||||
|
console.log('[DEAL_CLOSE] get_deal_data response:', dealData);
|
||||||
if (dealData) {
|
if (dealData) {
|
||||||
ac.dealCloseData = dealData;
|
ac.dealCloseData = dealData;
|
||||||
ac.dealCloseAgentCommission = dealData.agent_commission || 0;
|
ac.dealCloseAgentCommission = dealData.agent_commission || 0;
|
||||||
|
|||||||
@ -4185,66 +4185,113 @@ $user_id = $_SESSION['id'];
|
|||||||
});
|
});
|
||||||
function renderDealCloseContent() {
|
function renderDealCloseContent() {
|
||||||
var d = window.dealCloseData;
|
var d = window.dealCloseData;
|
||||||
if (!d) return;
|
console.log('[DEAL_CLOSE] renderDealCloseContent called, dealCloseData:', d);
|
||||||
|
if (!d) { console.log('[DEAL_CLOSE] dealCloseData is null/undefined'); return; }
|
||||||
var html = '';
|
var html = '';
|
||||||
if (d.title) html += '<div style="margin-bottom: 8px;"><span style="font-weight: 500;">Название:</span> ' + d.title + '</div>';
|
if (d.title) html += '<div style="margin-bottom: 8px;"><span style="font-weight: 500;">Название:</span> ' + d.title + '</div>';
|
||||||
if (d.contract_price) html += '<div style="margin-bottom: 8px;"><span style="font-weight: 500;">Сумма в договоре:</span> ' + Number(d.contract_price).toLocaleString('ru-RU') + ' руб.</div>';
|
if (d.contract_price) html += '<div style="margin-bottom: 8px;"><span style="font-weight: 500;">Сумма в договоре:</span> ' + Number(d.contract_price).toLocaleString('ru-RU') + ' руб.</div>';
|
||||||
if (d.agent_commission) html += '<div style="margin-bottom: 8px;"><span style="font-weight: 500;">Комиссия агента:</span> ' + Number(d.agent_commission).toLocaleString('ru-RU') + ' руб.</div>';
|
if (d.agent_commission) html += '<div style="margin-bottom: 8px;"><span style="font-weight: 500;">Комиссия агента:</span> ' + Number(d.agent_commission).toLocaleString('ru-RU') + ' руб.</div>';
|
||||||
|
console.log('[DEAL_CLOSE] basic html:', html);
|
||||||
|
$('#deal_close_content').html(html);
|
||||||
|
|
||||||
|
// Собираем ID заявок и объектов
|
||||||
var reqIds = [];
|
var reqIds = [];
|
||||||
if (d.side_one_requisition_id) reqIds.push(d.side_one_requisition_id);
|
if (d.side_one_requisition_id) reqIds.push(d.side_one_requisition_id);
|
||||||
if (d.side_two_requisition_id) reqIds.push(d.side_two_requisition_id);
|
if (d.side_two_requisition_id) reqIds.push(d.side_two_requisition_id);
|
||||||
if (reqIds.length > 0) {
|
|
||||||
$.ajax({
|
|
||||||
url: '/ajax/ajax_vue_requisitions.php',
|
|
||||||
type: 'POST',
|
|
||||||
contentType: 'application/json',
|
|
||||||
data: JSON.stringify({ request: 'get_deals_linked_reqs', req_ids: reqIds }),
|
|
||||||
success: function(reqRes) {
|
|
||||||
var reqs = reqRes.reqs || [];
|
|
||||||
if (reqs.length > 0) {
|
|
||||||
html += '<div style="margin-top: 10px;"><b>Связанные заявки:</b></div>';
|
|
||||||
reqs.forEach(function(req) {
|
|
||||||
html += '<div style="padding: 3px 0;">' + req.name;
|
|
||||||
html += req.deleted == 1 ? ' <span style="color: #43A047;">✓ закрыта</span>' : ' <span style="color: #f57c00;">открыта</span>';
|
|
||||||
html += '</div>';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var objIds = [];
|
var objIds = [];
|
||||||
if (d.side_one_object_id) objIds.push(d.side_one_object_id);
|
if (d.side_one_object_id) objIds.push(d.side_one_object_id);
|
||||||
if (d.side_two_object_id) objIds.push(d.side_two_object_id);
|
if (d.side_two_object_id) objIds.push(d.side_two_object_id);
|
||||||
if (objIds.length > 0) {
|
console.log('[DEAL_CLOSE] reqIds:', reqIds, 'objIds:', objIds);
|
||||||
|
|
||||||
|
var pending = 0;
|
||||||
|
if (reqIds.length > 0) pending++;
|
||||||
|
if (objIds.length > 0) pending++;
|
||||||
|
|
||||||
|
if (pending === 0) {
|
||||||
|
console.log('[DEAL_CLOSE] no reqs or objects, rendering fact data');
|
||||||
|
renderFactData(d);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var reqData = null;
|
||||||
|
var objData = null;
|
||||||
|
|
||||||
|
function tryRender() {
|
||||||
|
console.log('[DEAL_CLOSE] tryRender called, reqData:', reqData, 'objData:', objData);
|
||||||
|
if (reqData !== null && objData !== null) {
|
||||||
|
if (reqData.length > 0) {
|
||||||
|
var reqHtml = '<div style="margin-top: 10px;"><b>Связанные заявки:</b></div>';
|
||||||
|
reqData.forEach(function(req) {
|
||||||
|
reqHtml += '<div style="padding: 3px 0;">' + req.name;
|
||||||
|
reqHtml += req.deleted == 1 ? ' <span style="color: #43A047;">✓ закрыта</span>' : ' <span style="color: #f57c00;">открыта</span>';
|
||||||
|
reqHtml += '</div>';
|
||||||
|
});
|
||||||
|
console.log('[DEAL_CLOSE] appending reqHtml:', reqHtml);
|
||||||
|
$('#deal_close_content').append(reqHtml);
|
||||||
|
} else {
|
||||||
|
console.log('[DEAL_CLOSE] no requisitions found');
|
||||||
|
}
|
||||||
|
if (objData.length > 0) {
|
||||||
|
var objHtml = '<div style="margin-top: 10px;"><b>Связанные объекты:</b></div>';
|
||||||
|
objData.forEach(function(obj) {
|
||||||
|
objHtml += '<div style="padding: 3px 0;">' + obj.nazv + ' <span style="color: #999;">' + obj.adres + '</span></div>';
|
||||||
|
});
|
||||||
|
console.log('[DEAL_CLOSE] appending objHtml:', objHtml);
|
||||||
|
$('#deal_close_content').append(objHtml);
|
||||||
|
} else {
|
||||||
|
console.log('[DEAL_CLOSE] no objects found');
|
||||||
|
}
|
||||||
|
renderFactData(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reqIds.length > 0) {
|
||||||
|
console.log('[DEAL_CLOSE] loading requisitions...');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/ajax/ajax_vue_requisitions.php',
|
url: '/ajax/ajax_vue_requisitions.php',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
|
dataType: 'json',
|
||||||
|
data: JSON.stringify({ request: 'get_deals_linked_reqs', req_ids: reqIds }),
|
||||||
|
success: function(reqRes) {
|
||||||
|
console.log('[DEAL_CLOSE] requisitions response:', reqRes);
|
||||||
|
reqData = reqRes.reqs || [];
|
||||||
|
tryRender();
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.log('[DEAL_CLOSE] requisitions error:', status, error);
|
||||||
|
reqData = [];
|
||||||
|
tryRender();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (objIds.length > 0) {
|
||||||
|
console.log('[DEAL_CLOSE] loading objects...');
|
||||||
|
$.ajax({
|
||||||
|
url: '/ajax/ajax_vue_requisitions.php',
|
||||||
|
type: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
dataType: 'json',
|
||||||
data: JSON.stringify({ request: 'get_deals_linked_objects', object_ids: objIds }),
|
data: JSON.stringify({ request: 'get_deals_linked_objects', object_ids: objIds }),
|
||||||
success: function(objRes) {
|
success: function(objRes) {
|
||||||
var objs = objRes.objects || [];
|
console.log('[DEAL_CLOSE] objects response:', objRes);
|
||||||
if (objs.length > 0) {
|
objData = objRes.objects || [];
|
||||||
html += '<div style="margin-top: 10px;"><b>Связанные объекты:</b></div>';
|
tryRender();
|
||||||
objs.forEach(function(obj) {
|
},
|
||||||
html += '<div style="padding: 3px 0;">' + obj.nazv + ' <span style="color: #999;">' + obj.adres + '</span></div>';
|
error: function(xhr, status, error) {
|
||||||
});
|
console.log('[DEAL_CLOSE] objects error:', status, error);
|
||||||
}
|
objData = [];
|
||||||
html += '<div style="margin-top: 12px; padding-top: 10px; border-top: 1px solid #e0e0e0;"><b>Фактические данные</b></div>';
|
tryRender();
|
||||||
html += '<div><span style="color: #666;">Комиссия агента:</span> ' + (d.agent_commission || 0) + ' руб. | <span style="color: #666;">Сумма сделки:</span> ' + (d.contract_price || 0) + ' руб.</div>';
|
|
||||||
$('#deal_close_content').html(html);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
html += '<div style="margin-top: 12px; padding-top: 10px; border-top: 1px solid #e0e0e0;"><b>Фактические данные</b></div>';
|
}
|
||||||
|
|
||||||
|
function renderFactData(d) {
|
||||||
|
console.log('[DEAL_CLOSE] renderFactData called');
|
||||||
|
var html = '<div style="margin-top: 12px; padding-top: 10px; border-top: 1px solid #e0e0e0;"><b>Фактические данные</b></div>';
|
||||||
html += '<div><span style="color: #666;">Комиссия агента:</span> ' + (d.agent_commission || 0) + ' руб. | <span style="color: #666;">Сумма сделки:</span> ' + (d.contract_price || 0) + ' руб.</div>';
|
html += '<div><span style="color: #666;">Комиссия агента:</span> ' + (d.agent_commission || 0) + ' руб. | <span style="color: #666;">Сумма сделки:</span> ' + (d.contract_price || 0) + ' руб.</div>';
|
||||||
$('#deal_close_content').html(html);
|
$('#deal_close_content').append(html);
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
html += '<div style="margin-top: 12px; padding-top: 10px; border-top: 1px solid #e0e0e0;"><b>Фактические данные</b></div>';
|
|
||||||
html += '<div><span style="color: #666;">Комиссия агента:</span> ' + (d.agent_commission || 0) + ' руб. | <span style="color: #666;">Сумма сделки:</span> ' + (d.contract_price || 0) + ' руб.</div>';
|
|
||||||
$('#deal_close_content').html(html);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user