/** * ShippingNoteList Component * * Lists unsigned shipping notes for the current user. * Features: * - Pull to refresh * - Tap to open signature modal * - Shows customer, date, note preview */ import { shippingNoteApi } from '/mobile/modules/lager/shippingnote/ShippingNoteModule.js'; export default { name: 'ShippingNoteList', emits: ['sign', 'toast'], props: { user: Object }, setup(props, { emit }) { const { ref, onMounted } = Vue; // Data const shippingNotes = ref([]); const loading = ref(true); const refreshing = ref(false); const error = ref(null); // Load shipping notes const loadShippingNotes = async (isRefresh = false) => { if (isRefresh) { refreshing.value = true; } else { loading.value = true; } error.value = null; try { const data = await shippingNoteApi.get('getMyShippingNotes'); if (data.success) { shippingNotes.value = data.shippingNotes || []; } else { error.value = data.error || 'Fehler beim Laden'; } } catch (e) { console.error('Failed to load shipping notes:', e); error.value = 'Netzwerkfehler'; } finally { loading.value = false; refreshing.value = false; } }; // Pull to refresh let touchStartY = 0; let isPulling = false; const handleTouchStart = (e) => { const scrollTop = e.currentTarget.scrollTop; if (scrollTop === 0) { touchStartY = e.touches[0].clientY; isPulling = true; } }; const handleTouchMove = (e) => { if (!isPulling) return; const deltaY = e.touches[0].clientY - touchStartY; if (deltaY > 80 && !refreshing.value) { loadShippingNotes(true); isPulling = false; } }; const handleTouchEnd = () => { isPulling = false; }; // Open signature for a shipping note const openSignature = (shippingNote) => { emit('sign', shippingNote); navigator.vibrate?.([50]); }; // Format date const formatDate = (dateStr) => { if (!dateStr) return ''; const date = new Date(dateStr); return date.toLocaleDateString('de-AT', { day: '2-digit', month: '2-digit', year: 'numeric' }); }; // Initialize onMounted(() => { loadShippingNotes(); }); return { shippingNotes, loading, refreshing, error, loadShippingNotes, handleTouchStart, handleTouchMove, handleTouchEnd, openSignature, formatDate }; }, template: `
Lade Lieferscheine...
{{ error }}
Alles unterschrieben!
Keine offenen Lieferscheine zum Unterschreiben.