@page "/stock/productimport" @using phronCare.UIBlazor.Services.Stock @inject IJSRuntime JS @inject IToastService toastService @inject NavigationManager Navigation @inject LSProductService productService

Importación masiva de productos

@if (UploadedFile != null) {
} @if (PreviewItems != null) {
Vista previa
@foreach (var item in PreviewItems) { }
Cód. Fábrica Nombre Descripción Tipo Trazabilidad División Unidad Plus Cód. Ext. Errores
@item.FactoryCode @item.Name @item.Description @item.ProductType @item.TraceabilityType @item.DivisionCode @item.UnitCode @(item.PlusProcess ? "Sí" : "No") @item.ExternalCode @item.ErrorMessage
} @code { private List? PreviewItems; private IBrowserFile? UploadedFile; protected override void OnInitialized() { PreviewItems = new List { new() { FactoryCode = "ZIM001", Name = "Clavo tibial largo", Description = "Clavo para tibia", ProductType = 1, TraceabilityType = 3, DivisionCode = "ZIM", UnitCode = "UN", PlusProcess = true, ExternalCode = "EXT001" }, new() { FactoryCode = "ZIM002", Name = "Tornillo esponjoso", Description = "Tornillo de 6.5mm", ProductType = 1, TraceabilityType = 3, DivisionCode = "ZIM", UnitCode = "UN", PlusProcess = false, ExternalCode = "EXT002" }, new() { FactoryCode = "ZIM003", Name = "Placa de compresión", Description = "Placa DCP 4.5", ProductType = 1, TraceabilityType = 2, DivisionCode = "ZIM", UnitCode = "UN", PlusProcess = false, ExternalCode = "EXT003" }, new() { FactoryCode = "ZIM004", Name = "Caja instrumental", Description = "Caja para implantes", ProductType = 2, TraceabilityType = 1, DivisionCode = "ZIM", UnitCode = "CJ", PlusProcess = false, ExternalCode = "EXT004", ErrorMessage = "Unidad no reconocida" }, new() { FactoryCode = "ZIM005", Name = "Perno cortical", Description = "Perno de fijación", ProductType = 1, TraceabilityType = 3, DivisionCode = "ZIM", UnitCode = "UN", PlusProcess = true, ExternalCode = "EXT005" } }; } private async Task DownloadTemplate() { try { await productService.DownloadTemplateAsync(); } catch (Exception ex) { toastService.ShowError($"Error al descargar la plantilla: {ex.Message}"); } } private async Task HandleFileSelected(InputFileChangeEventArgs e) { UploadedFile = e.File; //PreviewItems = null; // Limpiar preview anterior } private async Task ProcessFile() { if (UploadedFile == null) return; using var stream = UploadedFile.OpenReadStream(10 * 1024 * 1024); using var ms = new MemoryStream(); await stream.CopyToAsync(ms); var content = ms.ToArray(); // Aquí deberías llamar al backend para validar y obtener la vista previa // Por ahora se simula con los datos ya cargados en OnInitialized // PreviewItems = await Http.PostAsJsonAsync(...) } private async Task SimulateImport() { // Lógica futura para simular importación } private async Task ConfirmImport() { // Lógica futura para guardar los productos } public class ProductImportPreviewDto { public string FactoryCode { get; set; } = string.Empty; public string Name { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; public int ProductType { get; set; } public int TraceabilityType { get; set; } public string DivisionCode { get; set; } = string.Empty; public string UnitCode { get; set; } = string.Empty; public bool PlusProcess { get; set; } public string ExternalCode { get; set; } = string.Empty; public string? ErrorMessage { get; set; } public bool HasError => !string.IsNullOrWhiteSpace(ErrorMessage); } }