| | 0 | 1 | | @{ ViewData["Title"] = "Корзина Japarts"; } |
| | | 2 | | <link rel="stylesheet" href="~/css/Studio2/SupplierCart/supplier-cart-index.css" asp-append-version="true"/> |
| | 0 | 3 | | @Html.AntiForgeryToken() |
| | | 4 | | <div class="sc-hero"><h1><i class="fas fa-cart-shopping me-2"></i>Корзина Japarts</h1><div class="subtitle">Серверная ко |
| | | 5 | | <div class="alert alert-warning"><i class="fas fa-triangle-exclamation me-2"></i>Перед оформлением проверьте баланс: Jap |
| | | 6 | | <div id="japarts-message"></div><div class="d-flex gap-2 mb-3"><button id="japarts-refresh" class="btn btn-outline-prima |
| | | 7 | | <div id="japarts-balance" class="mb-3 text-muted"></div><div class="table-responsive"><table class="table table-sm align |
| | | 8 | | @section Scripts { <script> |
| | | 9 | | (() => { |
| | | 10 | | const token = document.querySelector('input[name="__RequestVerificationToken"]')?.value || ''; |
| | | 11 | | const rows = document.getElementById('japarts-rows'), message = document.getElementById('japarts-message'); |
| | | 12 | | const selected = () => [...document.querySelectorAll('.japarts-item:checked')].map(x => x.value); |
| | | 13 | | const esc = v => String(v ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''} |
| | | 14 | | const buttons = () => { const enabled = selected().length > 0; document.getElementById('japarts-remove').disabled = !en |
| | | 15 | | async function load() { |
| | | 16 | | SkeletonLoader.table(rows, { columns: 7, rows: 5 }); |
| | | 17 | | try { |
| | | 18 | | await PageLoadingBar.run(async () => { |
| | | 19 | | const [basket, balance] = await Promise.all([fetch('/SupplierCart/Japarts/Basket'), fetch('/SupplierCart/Japarts/ |
| | | 20 | | const data = await basket.json(), money = await balance.json(); |
| | | 21 | | document.getElementById('japarts-balance').textContent = `Баланс: ${money.balance} ₽ · долг заказа: ${money.order |
| | | 22 | | rows.innerHTML = data.length ? data.map(x => `<tr><td><input class="japarts-item" type="checkbox" value="${esc(x. |
| | | 23 | | document.querySelectorAll('.japarts-item').forEach(x => x.addEventListener('change', buttons)); |
| | | 24 | | buttons(); |
| | | 25 | | }, { label: 'Корзина Japarts' }); |
| | | 26 | | } finally { SkeletonLoader.finish(rows); } |
| | | 27 | | } |
| | | 28 | | async function post(action) { |
| | | 29 | | const ids = selected(); if (!ids.length) return; |
| | | 30 | | if (window.TabStatus) window.TabStatus.clear('japarts-error'); |
| | | 31 | | if (action === 'Checkout' && !(await St2Dialog.confirm('Создать реальный заказ Japarts для выбранных позиций?', { var |
| | | 32 | | const actionButton = document.getElementById(action === 'Checkout' ? 'japarts-checkout' : 'japarts-remove'); |
| | | 33 | | const feedback = OperationFeedback.begin({ title: action === 'Checkout' ? 'Оформляем заказ Japarts' : 'Удаляем позици |
| | | 34 | | const form = new URLSearchParams(); ids.forEach(x => form.append('basketIds', x)); |
| | | 35 | | actionButton.disabled = true; |
| | | 36 | | try { |
| | | 37 | | feedback.step(1); |
| | | 38 | | const response = await PageLoadingBar.run(() => fetch('/SupplierCart/Japarts/' + action, { method:'POST', headers:{ |
| | | 39 | | const result = await response.json(); |
| | | 40 | | message.innerHTML = `<div class="alert ${response.ok ? 'alert-success' : 'alert-danger'}">${esc(response.ok ? (acti |
| | | 41 | | if (response.ok) { |
| | | 42 | | if (window.TabStatus) { |
| | | 43 | | window.TabStatus.clear('japarts-error'); |
| | | 44 | | window.TabStatus.complete({ key: 'japarts-result', label: action === 'Checkout' ? 'Заказ Japarts создан' : 'Поз |
| | | 45 | | } |
| | | 46 | | feedback.step(2); await load(); |
| | | 47 | | } else if (window.TabStatus) window.TabStatus.error({ key: 'japarts-error', label: action === 'Checkout' ? 'Заказ J |
| | | 48 | | } finally { feedback.finish(); buttons(); } |
| | | 49 | | } |
| | | 50 | | document.getElementById('japarts-refresh').addEventListener('click', load); document.getElementById('japarts-remove').a |
| | | 51 | | })(); |
| | | 52 | | </script> } |