Kgshop commited on
Commit
7ebb735
·
verified ·
1 Parent(s): c67b84b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +133 -5
app.py CHANGED
@@ -1173,7 +1173,15 @@ ORDER_TEMPLATE = '''
1173
  .close-modal { position: absolute; top: -30px; right: 0; color: white; font-size: 2rem; cursor: pointer; }
1174
  .tag-marker { position: absolute; width: 24px; height: 24px; background-color: var(--accent); border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 10px rgba(0,0,0,0.8); transform: translate(-50%, -50%); pointer-events: none; }
1175
  @media (max-width: 600px) { .order-item { grid-template-columns: 60px 1fr; } .item-quantity-total { grid-column: 1 / -1; grid-row: 2; text-align: left; margin-top: 10px; display: flex; justify-content: space-between; align-items: center; } }
1176
- @media print { body { background: white; padding: 0; } .container { box-shadow: none; border: none; padding: 0; margin: 0; } .no-print, .actions, .catalog-link { display: none !important; } }
 
 
 
 
 
 
 
 
1177
  </style>
1178
  </head>
1179
  <body>
@@ -1203,7 +1211,12 @@ ORDER_TEMPLATE = '''
1203
  <span>{{ "%.2f"|format(item.price) }} {{ currency_code }}</span>
1204
  </div>
1205
  <div class="item-quantity-total">
1206
- <div class="item-quantity"><span>Кол-во: {{ item.quantity }}</span></div>
 
 
 
 
 
1207
  <div class="item-total">{{ "%.2f"|format(item.price * item.quantity) }} {{ currency_code }}</div>
1208
  </div>
1209
  </div>
@@ -1218,9 +1231,43 @@ ORDER_TEMPLATE = '''
1218
  <div class="actions">
1219
  <button class="button" onclick="sendOrderViaWhatsApp()"><i class="fab fa-whatsapp"></i> Отправить в WhatsApp</button>
1220
  <button class="button button-print" onclick="window.print()"><i class="fas fa-print"></i> Печать накладной</button>
 
1221
  </div>
1222
  <a href="{{ url_for('catalog', env_id=env_id) }}" class="catalog-link">← Вернуться в каталог</a>
1223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1224
  <div id="tagModal" class="modal" onclick="closeTagModal(event)">
1225
  <div class="modal-content" onclick="event.stopPropagation()">
1226
  <span class="close-modal" onclick="closeTagModal(event)">&times;</span>
@@ -1232,8 +1279,10 @@ ORDER_TEMPLATE = '''
1232
  </div>
1233
 
1234
  <script>
 
 
 
1235
  function sendOrderViaWhatsApp() {
1236
- const orderId = document.getElementById('orderId').textContent;
1237
  const defaultWhatsapp = "{{ settings.whatsapp_number }}".replace(/[^0-9]/g, '');
1238
  const employeeWhatsapp = "{{ order.employee_whatsapp if order.employee_whatsapp else '' }}".replace(/[^0-9]/g, '');
1239
  const whatsappNumber = employeeWhatsapp || defaultWhatsapp;
@@ -1254,6 +1303,30 @@ ORDER_TEMPLATE = '''
1254
  function closeTagModal(e) {
1255
  document.getElementById('tagModal').style.display = 'none';
1256
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1257
  </script>
1258
  {% else %}
1259
  <h1 style="color: #dc3545;"><i class="fas fa-exclamation-triangle"></i> Ошибка</h1>
@@ -1782,9 +1855,11 @@ ADMIN_TEMPLATE = '''
1782
  </div>
1783
  </details>
1784
 
1785
- <h3>Список постов:</h3>
 
 
1786
  {% if products %}
1787
- <div class="item-list">
1788
  {% for product in products %}
1789
  <div class="item">
1790
  <div style="display: flex; gap: 15px; align-items: flex-start;">
@@ -1821,6 +1896,7 @@ ADMIN_TEMPLATE = '''
1821
  <p><strong>Отметок:</strong> {{ product.tags|length }}</p>
1822
  {% endif %}
1823
  <p><strong>Просмотров:</strong> {{ product.get('views', 0) }}</p>
 
1824
  </div>
1825
  </div>
1826
 
@@ -1913,6 +1989,20 @@ ADMIN_TEMPLATE = '''
1913
  const formStates = {};
1914
  let adminAiHistory = [];
1915
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1916
  function toggleCheckoutFields() {
1917
  const cb = document.getElementById('checkout_fields_enabled');
1918
  const list = document.getElementById('checkout_fields_list');
@@ -2419,6 +2509,44 @@ def create_order(env_id):
2419
  except Exception:
2420
  return jsonify({"error": "Ошибка сервера при сохранении заказа."}), 500
2421
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2422
  @app.route('/<env_id>/order/<order_id>')
2423
  def view_order(env_id, order_id):
2424
  data = get_env_data(env_id)
 
1173
  .close-modal { position: absolute; top: -30px; right: 0; color: white; font-size: 2rem; cursor: pointer; }
1174
  .tag-marker { position: absolute; width: 24px; height: 24px; background-color: var(--accent); border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 10px rgba(0,0,0,0.8); transform: translate(-50%, -50%); pointer-events: none; }
1175
  @media (max-width: 600px) { .order-item { grid-template-columns: 60px 1fr; } .item-quantity-total { grid-column: 1 / -1; grid-row: 2; text-align: left; margin-top: 10px; display: flex; justify-content: space-between; align-items: center; } }
1176
+
1177
+ @media print {
1178
+ body { background: white; padding: 0; }
1179
+ .container { box-shadow: none; border: none; padding: 0; margin: 0; }
1180
+ .no-print, .actions, .catalog-link, .item-quantity button { display: none !important; }
1181
+ body.print-table .container > *:not(#printTableContainer) { display: none !important; }
1182
+ body.print-table #printTableContainer { display: block !important; }
1183
+ }
1184
+ #printTableContainer { display: none; }
1185
  </style>
1186
  </head>
1187
  <body>
 
1211
  <span>{{ "%.2f"|format(item.price) }} {{ currency_code }}</span>
1212
  </div>
1213
  <div class="item-quantity-total">
1214
+ <div class="item-quantity">
1215
+ <button onclick="updateOrderItem({{ loop.index0 }}, 'dec')" style="padding: 2px 8px; cursor: pointer; border: 1px solid #ccc; background: #eee; border-radius: 4px;">-</button>
1216
+ <span style="margin: 0 10px;">Кол-во: {{ item.quantity }}</span>
1217
+ <button onclick="updateOrderItem({{ loop.index0 }}, 'inc')" style="padding: 2px 8px; cursor: pointer; border: 1px solid #ccc; background: #eee; border-radius: 4px;">+</button>
1218
+ <button onclick="if(confirm('Удалить товар из заказа?')) updateOrderItem({{ loop.index0 }}, 'remove')" style="padding: 2px 8px; cursor: pointer; color: white; background: var(--danger); border: none; border-radius: 4px; margin-left: 10px;"><i class="fas fa-trash"></i></button>
1219
+ </div>
1220
  <div class="item-total">{{ "%.2f"|format(item.price * item.quantity) }} {{ currency_code }}</div>
1221
  </div>
1222
  </div>
 
1231
  <div class="actions">
1232
  <button class="button" onclick="sendOrderViaWhatsApp()"><i class="fab fa-whatsapp"></i> Отправить в WhatsApp</button>
1233
  <button class="button button-print" onclick="window.print()"><i class="fas fa-print"></i> Печать накладной</button>
1234
+ <button class="button button-print-table" style="background-color: #28a745; color: white;" onclick="printTable()"><i class="fas fa-table"></i> Печать таблицей</button>
1235
  </div>
1236
  <a href="{{ url_for('catalog', env_id=env_id) }}" class="catalog-link">← Вернуться в каталог</a>
1237
 
1238
+ <div id="printTableContainer">
1239
+ <h2 style="text-align: center; color: black; border-bottom: none; margin-bottom: 5px;">Заказ №{{ order.id }}</h2>
1240
+ <p style="text-align: center; margin-bottom: 20px;">Дата: {{ order.created_at }}</p>
1241
+ <table style="width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px;">
1242
+ <thead>
1243
+ <tr>
1244
+ <th style="border: 1px solid #000; padding: 6px; background-color: #f0f0f0;">№</th>
1245
+ <th style="border: 1px solid #000; padding: 6px; background-color: #f0f0f0; text-align: left;">Наименование</th>
1246
+ <th style="border: 1px solid #000; padding: 6px; background-color: #f0f0f0;">Кол-во</th>
1247
+ <th style="border: 1px solid #000; padding: 6px; background-color: #f0f0f0;">Цена</th>
1248
+ <th style="border: 1px solid #000; padding: 6px; background-color: #f0f0f0;">Сумма</th>
1249
+ </tr>
1250
+ </thead>
1251
+ <tbody>
1252
+ {% for item in order.cart %}
1253
+ <tr>
1254
+ <td style="border: 1px solid #000; padding: 6px; text-align: center;">{{ loop.index }}</td>
1255
+ <td style="border: 1px solid #000; padding: 6px;">{{ item.name }}</td>
1256
+ <td style="border: 1px solid #000; padding: 6px; text-align: center;">{{ item.quantity }}</td>
1257
+ <td style="border: 1px solid #000; padding: 6px; text-align: right;">{{ "%.2f"|format(item.price) }}</td>
1258
+ <td style="border: 1px solid #000; padding: 6px; text-align: right;">{{ "%.2f"|format(item.price * item.quantity) }}</td>
1259
+ </tr>
1260
+ {% endfor %}
1261
+ </tbody>
1262
+ <tfoot>
1263
+ <tr>
1264
+ <td colspan="4" style="border: 1px solid #000; padding: 8px; text-align: right; font-weight: bold;">ИТОГО:</td>
1265
+ <td style="border: 1px solid #000; padding: 8px; text-align: right; font-weight: bold;">{{ "%.2f"|format(order.total_price) }}</td>
1266
+ </tr>
1267
+ </tfoot>
1268
+ </table>
1269
+ </div>
1270
+
1271
  <div id="tagModal" class="modal" onclick="closeTagModal(event)">
1272
  <div class="modal-content" onclick="event.stopPropagation()">
1273
  <span class="close-modal" onclick="closeTagModal(event)">&times;</span>
 
1279
  </div>
1280
 
1281
  <script>
1282
+ const envId = '{{ env_id }}';
1283
+ const orderId = '{{ order.id }}';
1284
+
1285
  function sendOrderViaWhatsApp() {
 
1286
  const defaultWhatsapp = "{{ settings.whatsapp_number }}".replace(/[^0-9]/g, '');
1287
  const employeeWhatsapp = "{{ order.employee_whatsapp if order.employee_whatsapp else '' }}".replace(/[^0-9]/g, '');
1288
  const whatsappNumber = employeeWhatsapp || defaultWhatsapp;
 
1303
  function closeTagModal(e) {
1304
  document.getElementById('tagModal').style.display = 'none';
1305
  }
1306
+ function printTable() {
1307
+ document.body.classList.add('print-table');
1308
+ window.print();
1309
+ setTimeout(() => { document.body.classList.remove('print-table'); }, 1000);
1310
+ }
1311
+ function updateOrderItem(index, action) {
1312
+ fetch(`/${envId}/update_order/${orderId}`, {
1313
+ method: 'POST',
1314
+ headers: { 'Content-Type': 'application/json' },
1315
+ body: JSON.stringify({ index: index, action: action })
1316
+ })
1317
+ .then(res => res.json())
1318
+ .then(data => {
1319
+ if (data.success) {
1320
+ location.reload();
1321
+ } else {
1322
+ alert(data.error || 'Ошибка обновления заказа');
1323
+ }
1324
+ })
1325
+ .catch(err => {
1326
+ console.error('Ошибка:', err);
1327
+ alert('Сетевая ошибка при обновлении заказа');
1328
+ });
1329
+ }
1330
  </script>
1331
  {% else %}
1332
  <h1 style="color: #dc3545;"><i class="fas fa-exclamation-triangle"></i> Ошибка</h1>
 
1855
  </div>
1856
  </details>
1857
 
1858
+ <h3 style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;">Список постов:</h3>
1859
+ <input type="text" id="adminProductSearch" placeholder="Поиск по постам..." style="margin-bottom: 15px; width: 100%; padding: 10px; border-radius: 6px; border: 1px solid #ccc; font-family: inherit;" oninput="filterAdminProducts()">
1860
+
1861
  {% if products %}
1862
+ <div class="item-list" id="admin-products-list">
1863
  {% for product in products %}
1864
  <div class="item">
1865
  <div style="display: flex; gap: 15px; align-items: flex-start;">
 
1896
  <p><strong>Отметок:</strong> {{ product.tags|length }}</p>
1897
  {% endif %}
1898
  <p><strong>Просмотров:</strong> {{ product.get('views', 0) }}</p>
1899
+ <span style="display:none;" class="hidden-description">{{ product.get('description', '')|lower }}</span>
1900
  </div>
1901
  </div>
1902
 
 
1989
  const formStates = {};
1990
  let adminAiHistory = [];
1991
 
1992
+ function filterAdminProducts() {
1993
+ const query = document.getElementById('adminProductSearch').value.toLowerCase().trim();
1994
+ const items = document.querySelectorAll('#admin-products-list .item');
1995
+ items.forEach(item => {
1996
+ const title = item.querySelector('h3').textContent.toLowerCase();
1997
+ const desc = item.querySelector('.hidden-description') ? item.querySelector('.hidden-description').textContent : '';
1998
+ if (title.includes(query) || desc.includes(query)) {
1999
+ item.style.display = 'block';
2000
+ } else {
2001
+ item.style.display = 'none';
2002
+ }
2003
+ });
2004
+ }
2005
+
2006
  function toggleCheckoutFields() {
2007
  const cb = document.getElementById('checkout_fields_enabled');
2008
  const list = document.getElementById('checkout_fields_list');
 
2509
  except Exception:
2510
  return jsonify({"error": "Ошибка сервера при сохранении заказа."}), 500
2511
 
2512
+ @app.route('/<env_id>/update_order/<order_id>', methods=['POST'])
2513
+ def update_order(env_id, order_id):
2514
+ data = get_env_data(env_id)
2515
+ order = data.get('orders', {}).get(order_id)
2516
+ if not order:
2517
+ return jsonify({"error": "Заказ не найден."}), 404
2518
+
2519
+ req = request.get_json()
2520
+ idx = req.get('index')
2521
+ action = req.get('action')
2522
+
2523
+ if idx is None or action not in ['inc', 'dec', 'remove']:
2524
+ return jsonify({"error": "Некорректный запрос."}), 400
2525
+
2526
+ try:
2527
+ idx = int(idx)
2528
+ cart = order.get('cart', [])
2529
+ if idx < 0 or idx >= len(cart):
2530
+ return jsonify({"error": "Товар не найден."}), 404
2531
+
2532
+ if action == 'inc':
2533
+ cart[idx]['quantity'] += 1
2534
+ elif action == 'dec':
2535
+ cart[idx]['quantity'] -= 1
2536
+ if cart[idx]['quantity'] <= 0:
2537
+ cart.pop(idx)
2538
+ elif action == 'remove':
2539
+ cart.pop(idx)
2540
+
2541
+ total = sum(float(item['price']) * int(item['quantity']) for item in cart)
2542
+ order['total_price'] = round(total, 2)
2543
+ order['cart'] = cart
2544
+
2545
+ save_env_data(env_id, data)
2546
+ return jsonify({"success": True})
2547
+ except Exception as e:
2548
+ return jsonify({"error": str(e)}), 500
2549
+
2550
  @app.route('/<env_id>/order/<order_id>')
2551
  def view_order(env_id, order_id):
2552
  data = get_env_data(env_id)