������� �� Avalonia 2.0 (�����-���������, ����������, �������� ��������) #1

Merged
Exest merged 18 commits from feature/avalonia-ui into master 2026-08-11 09:41:09 +03:00
5 changed files with 44 additions and 22 deletions
Showing only changes of commit cd2fb57bca - Show all commits

View File

@ -134,6 +134,7 @@ public partial class OrdersViewModel : ViewModelBase
Busy = true; Busy = true;
var req = new BuyerOrderCreateRequest var req = new BuyerOrderCreateRequest
{ {
GlobalSign = d.Number.StartsWith("EX-", StringComparison.OrdinalIgnoreCase) ? d.Number : null,
LocationId = d.LocationId, LocationId = d.LocationId,
Comment = d.Comment, Comment = d.Comment,
Items = d.Items.Select(i => new BuyerOrderItemReq Items = d.Items.Select(i => new BuyerOrderItemReq

View File

@ -88,28 +88,37 @@ public partial class PriceListViewModel : ViewModelBase
private void RemoveFromCart(CartItem? item) => _cart.Remove(item!); private void RemoveFromCart(CartItem? item) => _cart.Remove(item!);
[RelayCommand] [RelayCommand]
private void SaveDraft() private async Task SaveDraftAsync()
{ {
if (_cart.Count == 0) { Status = "Заказ пуст — добавьте позиции."; return; } if (_cart.Count == 0) { Status = "Заказ пуст — добавьте позиции."; return; }
try
var draft = new DraftOrder
{ {
LocationId = SelectedLocation?.BuyerLocationId, Busy = true;
LocationAddress = SelectedLocation?.Address, // Резервируем настоящий номер заказа EX-####### (как в WinForms)
Comment = string.IsNullOrWhiteSpace(Comment) ? null : Comment.Trim(), var sign = await _api.NextGlobalSignAsync();
Items = _cart.Items.Select(c => new DraftItem
var draft = new DraftOrder
{ {
SupplierPriceId = c.Source.SupplierPriceId ?? "", Number = string.IsNullOrWhiteSpace(sign) ? $"ЧРН-{DateTime.Now:HHmmss}" : sign!,
Name = c.Name, LocationId = SelectedLocation?.BuyerLocationId,
Supplier = c.Supplier, LocationAddress = SelectedLocation?.Address,
Barcode = c.Source.Barcode, Comment = string.IsNullOrWhiteSpace(Comment) ? null : Comment.Trim(),
Price = c.Price, Items = _cart.Items.Select(c => new DraftItem
Qty = c.Qty {
}).ToList() SupplierPriceId = c.Source.SupplierPriceId ?? "",
}; Name = c.Name,
var saved = DraftStore.Add(draft); Supplier = c.Supplier,
_cart.Clear(); Barcode = c.Source.Barcode,
Comment = ""; Price = c.Price,
Status = $"Заказ сохранён как черновик {saved.Number} → раздел «Заказы» (не отправлен)."; Qty = c.Qty
}).ToList()
};
DraftStore.Add(draft);
_cart.Clear();
Comment = "";
Status = $"Заказ сохранён: {draft.Number} → раздел «Заказы» (не отправлен).";
}
catch (Exception ex) { Status = "Ошибка сохранения: " + ex.Message; }
finally { Busy = false; }
} }
} }

View File

@ -129,6 +129,19 @@ public sealed class ApiClient
return JsonSerializer.Deserialize<BuyerOrderResponse>(text, Json) ?? new BuyerOrderResponse(); return JsonSerializer.Deserialize<BuyerOrderResponse>(text, Json) ?? new BuyerOrderResponse();
} }
/// <summary>Резервирует следующий номер заказа EX-####### (как в WinForms до создания заказа).</summary>
public async Task<string?> NextGlobalSignAsync()
{
EnsureAuth();
var text = await AuthorizedGetAsync("/api/buyer/global-sign/next", "резервирование номера").ConfigureAwait(false);
try
{
using var doc = JsonDocument.Parse(text);
return doc.RootElement.TryGetProperty("global_sign", out var v) ? v.GetString() : null;
}
catch { return null; }
}
/// <summary>Адреса-грузополучатели покупателя.</summary> /// <summary>Адреса-грузополучатели покупателя.</summary>
public async Task<List<BuyerLocationDto>> GetBuyerLocationsAsync() public async Task<List<BuyerLocationDto>> GetBuyerLocationsAsync()
{ {

View File

@ -29,7 +29,7 @@ public sealed class DraftOrder
/// <summary>Локальные черновики заказов (%APPDATA%\ElfisaAvalonia\drafts.json).</summary> /// <summary>Локальные черновики заказов (%APPDATA%\ElfisaAvalonia\drafts.json).</summary>
public static class DraftStore public static class DraftStore
{ {
private sealed class Box { public int Seq { get; set; } public List<DraftOrder> Drafts { get; set; } = new(); } private sealed class Box { public List<DraftOrder> Drafts { get; set; } = new(); }
private static readonly string Dir = private static readonly string Dir =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ElfisaAvalonia"); Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ElfisaAvalonia");
@ -62,8 +62,6 @@ public static class DraftStore
public static DraftOrder Add(DraftOrder draft) public static DraftOrder Add(DraftOrder draft)
{ {
_box.Seq++;
draft.Number = $"ЧРН-{_box.Seq:0000}";
_box.Drafts.Insert(0, draft); _box.Drafts.Insert(0, draft);
Save(); Save();
return draft; return draft;

View File

@ -94,6 +94,7 @@ public sealed class BuyerOrderCreateRequest
{ {
[JsonPropertyName("location_id")] public string? LocationId { get; set; } [JsonPropertyName("location_id")] public string? LocationId { get; set; }
[JsonPropertyName("comment")] public string? Comment { get; set; } [JsonPropertyName("comment")] public string? Comment { get; set; }
[JsonPropertyName("global_sign")] public string? GlobalSign { get; set; }
[JsonPropertyName("items")] public List<BuyerOrderItemReq> Items { get; set; } = new(); [JsonPropertyName("items")] public List<BuyerOrderItemReq> Items { get; set; } = new();
} }