-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
557 lines (495 loc) · 27.5 KB
/
admin.html
File metadata and controls
557 lines (495 loc) · 27.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Админ-панель - Cordoba Legal Group</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.4.0/css/all.min.css">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
}
</style>
</head>
<body class="bg-gray-100">
<!-- Header -->
<header class="bg-gray-900 shadow-md">
<div class="container mx-auto px-4 py-4">
<div class="flex items-center justify-between">
<div class="flex items-center space-x-3">
<img src="assets/logo.svg"
alt="Cordoba Legal Group"
class="h-10 w-auto">
<div class="ml-4">
<h1 class="text-xl font-bold text-white">Административная панель</h1>
<p class="text-sm text-gray-300">Управление лидами и результатами</p>
</div>
</div>
<a href="index.html" class="text-blue-400 hover:text-blue-300 font-semibold transition">
<i class="fas fa-home mr-2"></i>
На главную
</a>
</div>
</div>
</header>
<!-- Main Content -->
<main class="container mx-auto px-4 py-8">
<!-- Stats Cards -->
<div class="grid md:grid-cols-4 gap-6 mb-8">
<div class="bg-white rounded-lg shadow-lg p-6">
<div class="flex items-center justify-between mb-2">
<h3 class="text-gray-600 font-semibold">Всего лидов</h3>
<i class="fas fa-users text-blue-600 text-2xl"></i>
</div>
<p class="text-3xl font-bold text-gray-800" id="total-leads">0</p>
<p class="text-sm text-gray-500 mt-2">За все время</p>
</div>
<div class="bg-white rounded-lg shadow-lg p-6">
<div class="flex items-center justify-between mb-2">
<h3 class="text-gray-600 font-semibold">Сегодня</h3>
<i class="fas fa-calendar-day text-green-600 text-2xl"></i>
</div>
<p class="text-3xl font-bold text-gray-800" id="today-leads">0</p>
<p class="text-sm text-gray-500 mt-2">Новых заявок</p>
</div>
<div class="bg-white rounded-lg shadow-lg p-6">
<div class="flex items-center justify-between mb-2">
<h3 class="text-gray-600 font-semibold">Расчетов</h3>
<i class="fas fa-calculator text-yellow-600 text-2xl"></i>
</div>
<p class="text-3xl font-bold text-gray-800" id="total-calculations">0</p>
<p class="text-sm text-gray-500 mt-2">Использовано калькулятор</p>
</div>
<div class="bg-white rounded-lg shadow-lg p-6">
<div class="flex items-center justify-between mb-2">
<h3 class="text-gray-600 font-semibold">Конверсия</h3>
<i class="fas fa-chart-line text-purple-600 text-2xl"></i>
</div>
<p class="text-3xl font-bold text-gray-800" id="conversion-rate">0%</p>
<p class="text-sm text-gray-500 mt-2">От посетителей к лидам</p>
</div>
</div>
<!-- Tabs -->
<div class="bg-white rounded-lg shadow-lg mb-8">
<div class="border-b border-gray-200">
<nav class="flex">
<button onclick="switchTab('leads')" id="tab-leads"
class="px-6 py-4 font-semibold border-b-2 border-blue-600 text-blue-600">
<i class="fas fa-users mr-2"></i>
Лиды
</button>
<button onclick="switchTab('calculations')" id="tab-calculations"
class="px-6 py-4 font-semibold border-b-2 border-transparent text-gray-600 hover:text-gray-800">
<i class="fas fa-calculator mr-2"></i>
Результаты калькулятора
</button>
</nav>
</div>
</div>
<!-- Leads Table -->
<div id="content-leads" class="bg-white rounded-lg shadow-lg overflow-hidden">
<div class="p-6 border-b border-gray-200">
<div class="flex flex-col md:flex-row md:items-center md:justify-between space-y-4 md:space-y-0">
<h2 class="text-2xl font-bold text-gray-800">
<i class="fas fa-users text-blue-600 mr-2"></i>
Список лидов
</h2>
<div class="flex items-center space-x-4">
<input type="text" id="search-leads" placeholder="Поиск по имени, телефону..."
class="px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:border-blue-500">
<button onclick="refreshLeads()" class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition">
<i class="fas fa-sync-alt mr-2"></i>
Обновить
</button>
<button onclick="exportLeads()" class="bg-green-600 text-white px-4 py-2 rounded-lg hover:bg-green-700 transition">
<i class="fas fa-download mr-2"></i>
Экспорт
</button>
</div>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-50 border-b border-gray-200">
<tr>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Дата</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Имя</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Телефон</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Email</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Брокер</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Сумма</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Тип формы</th>
</tr>
</thead>
<tbody id="leads-tbody" class="divide-y divide-gray-200">
<tr>
<td colspan="8" class="px-6 py-8 text-center text-gray-500">
<i class="fas fa-spinner fa-spin text-3xl mb-3"></i>
<p>Загрузка данных...</p>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Pagination -->
<div class="px-6 py-4 border-t border-gray-200 flex items-center justify-between">
<div class="text-sm text-gray-600">
Показано <span id="leads-showing">0</span> из <span id="leads-total">0</span> записей
</div>
<div class="flex space-x-2" id="leads-pagination">
<!-- Pagination buttons will be inserted here -->
</div>
</div>
</div>
<!-- Calculator Results Table -->
<div id="content-calculations" class="bg-white rounded-lg shadow-lg overflow-hidden hidden">
<div class="p-6 border-b border-gray-200">
<div class="flex flex-col md:flex-row md:items-center md:justify-between space-y-4 md:space-y-0">
<h2 class="text-2xl font-bold text-gray-800">
<i class="fas fa-calculator text-yellow-600 mr-2"></i>
Результаты калькулятора
</h2>
<div class="flex items-center space-x-4">
<input type="text" id="search-calculations" placeholder="Поиск по брокеру..."
class="px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:border-blue-500">
<button onclick="refreshCalculations()" class="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 transition">
<i class="fas fa-sync-alt mr-2"></i>
Обновить
</button>
</div>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-50 border-b border-gray-200">
<tr>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Дата</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Брокер</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Сумма</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Вероятность</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Срок</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Методика</th>
<th class="px-6 py-3 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">Контакт</th>
</tr>
</thead>
<tbody id="calculations-tbody" class="divide-y divide-gray-200">
<tr>
<td colspan="7" class="px-6 py-8 text-center text-gray-500">
<i class="fas fa-spinner fa-spin text-3xl mb-3"></i>
<p>Загрузка данных...</p>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Pagination -->
<div class="px-6 py-4 border-t border-gray-200 flex items-center justify-between">
<div class="text-sm text-gray-600">
Показано <span id="calc-showing">0</span> из <span id="calc-total">0</span> записей
</div>
<div class="flex space-x-2" id="calc-pagination">
<!-- Pagination buttons will be inserted here -->
</div>
</div>
</div>
</main>
<script>
// Global variables
let currentPage = 1;
let currentTab = 'leads';
const itemsPerPage = 20;
// Initialize on page load
document.addEventListener('DOMContentLoaded', function() {
loadLeads();
loadCalculations();
updateStats();
// Search functionality
document.getElementById('search-leads').addEventListener('input', function() {
loadLeads(1, this.value);
});
document.getElementById('search-calculations').addEventListener('input', function() {
loadCalculations(1, this.value);
});
});
// Switch tabs
function switchTab(tab) {
currentTab = tab;
// Update tab buttons
document.getElementById('tab-leads').className = tab === 'leads' ?
'px-6 py-4 font-semibold border-b-2 border-blue-600 text-blue-600' :
'px-6 py-4 font-semibold border-b-2 border-transparent text-gray-600 hover:text-gray-800';
document.getElementById('tab-calculations').className = tab === 'calculations' ?
'px-6 py-4 font-semibold border-b-2 border-blue-600 text-blue-600' :
'px-6 py-4 font-semibold border-b-2 border-transparent text-gray-600 hover:text-gray-800';
// Toggle content
document.getElementById('content-leads').classList.toggle('hidden', tab !== 'leads');
document.getElementById('content-calculations').classList.toggle('hidden', tab !== 'calculations');
}
// Load leads
async function loadLeads(page = 1, search = '') {
try {
const url = `tables/leads?page=${page}&limit=${itemsPerPage}${search ? '&search=' + search : ''}&sort=-created_at`;
const response = await fetch(url);
const data = await response.json();
const tbody = document.getElementById('leads-tbody');
tbody.innerHTML = '';
if (data.data && data.data.length > 0) {
data.data.forEach(lead => {
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50';
row.innerHTML = `
<td class="px-6 py-4 text-sm text-gray-600">#${lead.id.substring(0, 8)}</td>
<td class="px-6 py-4 text-sm text-gray-600">${formatDate(lead.created_at)}</td>
<td class="px-6 py-4 text-sm font-semibold text-gray-800">${lead.name || '-'}</td>
<td class="px-6 py-4 text-sm text-gray-800">
<a href="tel:${lead.phone}" class="text-blue-600 hover:underline">${lead.phone || '-'}</a>
</td>
<td class="px-6 py-4 text-sm text-gray-600">${lead.email || '-'}</td>
<td class="px-6 py-4 text-sm text-gray-800">${lead.broker_name || '-'}</td>
<td class="px-6 py-4 text-sm font-semibold text-green-600">${lead.amount ? '$' + lead.amount : '-'}</td>
<td class="px-6 py-4">
<span class="px-3 py-1 text-xs font-semibold rounded-full ${getFormTypeBadge(lead.form_type)}">
${getFormTypeLabel(lead.form_type)}
</span>
</td>
`;
tbody.appendChild(row);
});
// Update pagination
document.getElementById('leads-showing').textContent = data.data.length;
document.getElementById('leads-total').textContent = data.total;
renderPagination('leads', data.page, Math.ceil(data.total / itemsPerPage), data.total);
} else {
tbody.innerHTML = `
<tr>
<td colspan="8" class="px-6 py-8 text-center text-gray-500">
<i class="fas fa-inbox text-3xl mb-3"></i>
<p>Лидов пока нет</p>
</td>
</tr>
`;
}
} catch (error) {
console.error('Error loading leads:', error);
document.getElementById('leads-tbody').innerHTML = `
<tr>
<td colspan="8" class="px-6 py-8 text-center text-red-500">
<i class="fas fa-exclamation-triangle text-3xl mb-3"></i>
<p>Ошибка загрузки данных</p>
</td>
</tr>
`;
}
}
// Load calculator results
async function loadCalculations(page = 1, search = '') {
try {
const url = `tables/calculator_results?page=${page}&limit=${itemsPerPage}${search ? '&search=' + search : ''}&sort=-created_at`;
const response = await fetch(url);
const data = await response.json();
const tbody = document.getElementById('calculations-tbody');
tbody.innerHTML = '';
if (data.data && data.data.length > 0) {
data.data.forEach(calc => {
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50';
row.innerHTML = `
<td class="px-6 py-4 text-sm text-gray-600">${formatDate(calc.created_at)}</td>
<td class="px-6 py-4 text-sm font-semibold text-gray-800">${calc.broker || '-'}</td>
<td class="px-6 py-4 text-sm font-semibold text-green-600">$${calc.amount || '0'}</td>
<td class="px-6 py-4 text-sm">
<span class="px-3 py-1 text-xs font-semibold rounded-full ${getProbabilityBadge(calc.success_probability)}">
${calc.success_probability}%
</span>
</td>
<td class="px-6 py-4 text-sm text-gray-600">${calc.estimated_days || '-'} дней</td>
<td class="px-6 py-4 text-sm text-gray-800">${calc.recommended_method || '-'}</td>
<td class="px-6 py-4 text-sm text-gray-600">
<div>${calc.contact_name || '-'}</div>
<div class="text-xs text-blue-600">${calc.contact_phone || '-'}</div>
</td>
`;
tbody.appendChild(row);
});
// Update pagination
document.getElementById('calc-showing').textContent = data.data.length;
document.getElementById('calc-total').textContent = data.total;
renderPagination('calc', data.page, Math.ceil(data.total / itemsPerPage), data.total);
} else {
tbody.innerHTML = `
<tr>
<td colspan="7" class="px-6 py-8 text-center text-gray-500">
<i class="fas fa-inbox text-3xl mb-3"></i>
<p>Расчетов пока нет</p>
</td>
</tr>
`;
}
} catch (error) {
console.error('Error loading calculations:', error);
document.getElementById('calculations-tbody').innerHTML = `
<tr>
<td colspan="7" class="px-6 py-8 text-center text-red-500">
<i class="fas fa-exclamation-triangle text-3xl mb-3"></i>
<p>Ошибка загрузки данных</p>
</td>
</tr>
`;
}
}
// Update statistics
async function updateStats() {
try {
// Get leads stats
const leadsResponse = await fetch('tables/leads?limit=1000');
const leadsData = await leadsResponse.json();
// Get calculator stats
const calcResponse = await fetch('tables/calculator_results?limit=1000');
const calcData = await calcResponse.json();
document.getElementById('total-leads').textContent = leadsData.total || 0;
document.getElementById('total-calculations').textContent = calcData.total || 0;
// Calculate today's leads
const today = new Date();
today.setHours(0, 0, 0, 0);
const todayLeads = leadsData.data ? leadsData.data.filter(lead => {
const leadDate = new Date(lead.created_at);
leadDate.setHours(0, 0, 0, 0);
return leadDate.getTime() === today.getTime();
}).length : 0;
document.getElementById('today-leads').textContent = todayLeads;
// Calculate conversion (mock)
const conversionRate = leadsData.total > 0 ? ((leadsData.total / (leadsData.total * 3)) * 100).toFixed(1) : 0;
document.getElementById('conversion-rate').textContent = conversionRate + '%';
} catch (error) {
console.error('Error updating stats:', error);
}
}
// Render pagination
function renderPagination(type, currentPage, totalPages, totalItems) {
if (totalItems === 0) return;
const container = document.getElementById(`${type}-pagination`);
container.innerHTML = '';
// Previous button
if (currentPage > 1) {
const prevBtn = document.createElement('button');
prevBtn.className = 'px-3 py-1 border border-gray-300 rounded hover:bg-gray-50';
prevBtn.innerHTML = '<i class="fas fa-chevron-left"></i>';
prevBtn.onclick = () => type === 'leads' ? loadLeads(currentPage - 1) : loadCalculations(currentPage - 1);
container.appendChild(prevBtn);
}
// Page numbers (show max 5 pages)
const startPage = Math.max(1, currentPage - 2);
const endPage = Math.min(totalPages, currentPage + 2);
for (let i = startPage; i <= endPage; i++) {
const pageBtn = document.createElement('button');
pageBtn.className = i === currentPage ?
'px-3 py-1 bg-blue-600 text-white rounded' :
'px-3 py-1 border border-gray-300 rounded hover:bg-gray-50';
pageBtn.textContent = i;
pageBtn.onclick = () => type === 'leads' ? loadLeads(i) : loadCalculations(i);
container.appendChild(pageBtn);
}
// Next button
if (currentPage < totalPages) {
const nextBtn = document.createElement('button');
nextBtn.className = 'px-3 py-1 border border-gray-300 rounded hover:bg-gray-50';
nextBtn.innerHTML = '<i class="fas fa-chevron-right"></i>';
nextBtn.onclick = () => type === 'leads' ? loadLeads(currentPage + 1) : loadCalculations(currentPage + 1);
container.appendChild(nextBtn);
}
}
// Refresh functions
function refreshLeads() {
loadLeads(currentPage);
updateStats();
}
function refreshCalculations() {
loadCalculations(currentPage);
updateStats();
}
// Export leads to CSV
async function exportLeads() {
try {
const response = await fetch('tables/leads?limit=10000');
const data = await response.json();
if (!data.data || data.data.length === 0) {
alert('Нет данных для экспорта');
return;
}
// Create CSV content
const headers = ['ID', 'Дата', 'Имя', 'Телефон', 'Email', 'Брокер', 'Сумма', 'Тип формы'];
const rows = data.data.map(lead => [
lead.id,
formatDate(lead.created_at),
lead.name || '',
lead.phone || '',
lead.email || '',
lead.broker_name || '',
lead.amount || '',
getFormTypeLabel(lead.form_type)
]);
let csvContent = headers.join(',') + '\n';
rows.forEach(row => {
csvContent += row.map(cell => `"${cell}"`).join(',') + '\n';
});
// Download file
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = `leads_${new Date().toISOString().split('T')[0]}.csv`;
link.click();
} catch (error) {
console.error('Export error:', error);
alert('Ошибка экспорта данных');
}
}
// Helper functions
function formatDate(timestamp) {
const date = new Date(timestamp);
return date.toLocaleString('ru-RU', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
});
}
function getFormTypeBadge(type) {
const badges = {
'cold': 'bg-blue-100 text-blue-800',
'hot': 'bg-orange-100 text-orange-800',
'final': 'bg-red-100 text-red-800',
'calculator': 'bg-yellow-100 text-yellow-800',
'consultant': 'bg-green-100 text-green-800',
'exit-popup-case': 'bg-purple-100 text-purple-800',
'exit-popup-messenger': 'bg-pink-100 text-pink-800'
};
return badges[type] || 'bg-gray-100 text-gray-800';
}
function getFormTypeLabel(type) {
const labels = {
'cold': 'Холодная',
'hot': 'Теплая',
'final': 'Финальная',
'calculator': 'Калькулятор',
'consultant': 'Консультант',
'exit-popup-case': 'Exit (Кейс)',
'exit-popup-messenger': 'Exit (Мессенджер)'
};
return labels[type] || type;
}
function getProbabilityBadge(probability) {
const prob = parseInt(probability);
if (prob >= 80) return 'bg-green-100 text-green-800';
if (prob >= 60) return 'bg-yellow-100 text-yellow-800';
return 'bg-red-100 text-red-800';
}
</script>
</body>
</html>