iOS: "Nachschlagen"-Scan (nur ansehen)
Neue Kachel im Scannen-Tab: Barcode -> Artikel, Einzelstueck-QR -> genau das Stueck (Kaufdatum, Garantie, Ort ...), rein lesend ohne Ein-/Auslagern. Praktisch mit Einzelstuecken, um schnell nachzuschauen, welches Exemplar man in der Hand haelt. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
76
ios/Sources/LookupScanView.swift
Normal file
76
ios/Sources/LookupScanView.swift
Normal file
@@ -0,0 +1,76 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Nur ansehen: Barcode → Artikel, Einzelstück-QR → genau dieses Stück.
|
||||
/// Kein Ein-/Auslagern – zum schnellen Nachschauen (z.B. wann gekauft, Garantie).
|
||||
struct LookupScanView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@EnvironmentObject private var display: DisplaySettings
|
||||
|
||||
@State private var paused = false
|
||||
@State private var torchOn = false
|
||||
@State private var error: String?
|
||||
@State private var item: Item?
|
||||
@State private var product: Product?
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(spacing: 14) {
|
||||
ScannerView(onCode: { code in Task { await resolve(code) } },
|
||||
isPaused: $paused, torchOn: $torchOn)
|
||||
.aspectRatio(4.0 / 3.0, contentMode: .fit)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 16))
|
||||
.padding(.horizontal)
|
||||
|
||||
Text("Barcode oder Einzelstück-QR scannen – nur ansehen")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
|
||||
if let error {
|
||||
Text(error).font(.callout).foregroundStyle(.red)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
}
|
||||
.padding(.vertical)
|
||||
}
|
||||
.navigationTitle("Nachschlagen")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarLeading) { Button("Fertig") { dismiss() } }
|
||||
ToolbarItem(placement: .topBarTrailing) { TorchButton(isOn: $torchOn) }
|
||||
}
|
||||
.sheet(item: $item, onDismiss: { paused = false }) { it in
|
||||
NavigationStack { ItemEditView(item: it) }
|
||||
}
|
||||
.sheet(item: $product, onDismiss: { paused = false }) { p in
|
||||
NavigationStack { ProductDetailView(product: p) }
|
||||
.environmentObject(display)
|
||||
}
|
||||
}
|
||||
|
||||
private func resolve(_ code: String) async {
|
||||
paused = true
|
||||
error = nil
|
||||
// Einzelstück-QR (…/i/<UID>)?
|
||||
if let r = code.range(of: "/i/") {
|
||||
let uid = String(code[r.upperBound...])
|
||||
.trimmingCharacters(in: CharacterSet(charactersIn: "/ ")).uppercased()
|
||||
if !uid.isEmpty, let found = try? await APIClient.shared.itemByUid(uid: uid) {
|
||||
item = found
|
||||
return
|
||||
}
|
||||
}
|
||||
// Sonst als Barcode auflösen.
|
||||
do {
|
||||
let result = try await APIClient.shared.lookup(barcode: code)
|
||||
if let existing = result.existingProduct {
|
||||
product = existing
|
||||
} else {
|
||||
error = "Nicht im Katalog: \(code)"
|
||||
paused = false
|
||||
}
|
||||
} catch {
|
||||
self.error = error.localizedDescription
|
||||
paused = false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user