| | | 1 | | @using OzonOrdersWeb.Areas.Studio2.ViewModels.Grid |
| | | 2 | | @using OzonOrdersWeb.Areas.Studio2.ViewModels.Warehouse |
| | | 3 | | @model InterpartsSutCurrencyPageViewModel |
| | | 4 | | @{ |
| | 0 | 5 | | ViewData["Title"] = "Курсы Interparts"; |
| | 0 | 6 | | Layout = "~/Views/Shared/_Layout.cshtml"; |
| | 0 | 7 | | var rows = Model.Rows.Select(r => new { id = r.Id, name = r.Name, longName = r.LongName, rateToRub = r.RateToRub }); |
| | | 8 | | } |
| | | 9 | | |
| | 0 | 10 | | @await Html.PartialAsync("_BsxGridShell") |
| | | 11 | | |
| | | 12 | | <div class="container-fluid py-3 bsx-surface"> |
| | | 13 | | <div class="app-section-hero app-section-hero--import d-flex flex-wrap justify-content-between align-items-start gap |
| | | 14 | | <div> |
| | | 15 | | <h1><i class="fas fa-exchange-alt me-2 text-primary"></i>Курсы Interparts</h1> |
| | | 16 | | <div class="subtitle">Курсы валют учётной системы Interparts к рублю</div> |
| | | 17 | | <div class="app-section-hero__quick-links"> |
| | | 18 | | <a asp-area="Studio2" asp-controller="WarehouseMapping" asp-action="Index"><i class="fas fa-link"></i>Bi |
| | | 19 | | <a asp-area="Studio2" asp-controller="InterpartsWarehouseLogin" asp-action="Index"><i class="fas fa-user |
| | | 20 | | </div> |
| | | 21 | | </div> |
| | 0 | 22 | | @if (Model.Rows.Count > 0) |
| | | 23 | | { |
| | | 24 | | <button type="button" class="btn btn-primary btn-sm" id="ipCurrencySave" disabled><i class="fas fa-save me-1 |
| | | 25 | | } |
| | | 26 | | </div> |
| | | 27 | | |
| | 0 | 28 | | @if (TempData["SuccessMessage"] != null) |
| | | 29 | | { |
| | 0 | 30 | | <div class="alert alert-success">@TempData["SuccessMessage"]</div> |
| | | 31 | | } |
| | 0 | 32 | | @if (TempData["ErrorMessage"] != null) |
| | | 33 | | { |
| | 0 | 34 | | <div class="alert alert-danger">@TempData["ErrorMessage"]</div> |
| | | 35 | | } |
| | | 36 | | |
| | 0 | 37 | | @if (Model.Rows.Count == 0) |
| | | 38 | | { |
| | | 39 | | <div class="alert alert-warning"> |
| | | 40 | | Таблица <code>InterpartsSutCurrencies</code> пуста. Выполните скрипт |
| | | 41 | | <code>Scripts/Sql/mysql_interparts_sut_currency.sql</code> в основной MySQL БД. |
| | | 42 | | </div> |
| | | 43 | | } |
| | | 44 | | else |
| | | 45 | | { |
| | 0 | 46 | | @await Html.PartialAsync("_BsxDirectoryGrid", new BsxDirectoryGridViewModel("ipCurrency", "Валюты", "fa-coins", |
| | 0 | 47 | | "Клик по курсу — правка; изменения сохраняются кнопкой «Сохранить изменения».")) |
| | | 48 | | } |
| | | 49 | | </div> |
| | | 50 | | |
| | | 51 | | @section Scripts { |
| | 0 | 52 | | @if (Model.Rows.Count > 0) |
| | | 53 | | { |
| | | 54 | | |
| | | 55 | | <script src="~/js/Studio2/Grid/bsx-directory.js" asp-append-version="true"></script> |
| | | 56 | | <script> |
| | | 57 | | (function () { |
| | | 58 | | const D = window.BsxDirectory; |
| | | 59 | | const saveBtn = document.getElementById('ipCurrencySave'); |
| | | 60 | | // Курс биндится в культуре сервера — отправляем с её разделителем. |
| | 0 | 61 | | const decimalSeparator = '@System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparat |
| | | 62 | | const grid = D.grid({ |
| | | 63 | | key: 'dirIpCurrency', |
| | | 64 | | prefix: 'ipCurrency', |
| | 0 | 65 | | rows: @Json.Serialize(rows), |
| | | 66 | | autoHeight: true, |
| | | 67 | | gridOptions: { onCellValueChanged: e => { e.data.__dirty = true; e.api.redrawRows({ rowNodes: [e.node] } |
| | | 68 | | columnDefs: [ |
| | | 69 | | D.numCol({ field: 'id', headerName: 'ID', width: 90, sort: 'asc' }), |
| | | 70 | | { field: 'name', headerName: 'Название', width: 200, cellClass: 'fw-semibold' }, |
| | | 71 | | { field: 'longName', headerName: 'Полное имя', flex: 1, minWidth: 220 }, |
| | | 72 | | D.numCol({ field: 'rateToRub', headerName: 'Курс к рублю', headerTooltip: 'RateToRub', width: 180, e |
| | | 73 | | cellEditor: 'agNumberCellEditor', cellEditorParams: { min: 0.000001, precision: 6 }, |
| | | 74 | | valueParser: p => { const v = Number(p.newValue); return v > 0 ? v : p.oldValue; }, |
| | | 75 | | valueFormatter: p => Number(p.value).toLocaleString('ru-RU', { maximumFractionDigits: 6 }) }) |
| | | 76 | | ] |
| | | 77 | | }); |
| | | 78 | | saveBtn.addEventListener('click', () => { |
| | | 79 | | const fields = {}; |
| | | 80 | | let i = 0; |
| | | 81 | | grid.api().forEachNode(n => { |
| | | 82 | | fields[`Rows[${i}].Id`] = n.data.id; |
| | | 83 | | fields[`Rows[${i}].RateToRub`] = String(n.data.rateToRub).replace('.', decimalSeparator); |
| | | 84 | | i++; |
| | | 85 | | }); |
| | | 86 | | saveBtn.disabled = true; |
| | 0 | 87 | | D.submit('@Url.Action("Save", "InterpartsSutCurrency", new { area = "Studio2" })', fields); |
| | | 88 | | }); |
| | | 89 | | })(); |
| | | 90 | | </script> |
| | | 91 | | } |
| | | 92 | | } |