Vue.component('warehouse-project-modal', { props: { id: { type: [String, Number], required: true }, }, data() { return { window: window, loading: false, allUsers: [], project: { title: '', description: '', startDate: null, endDate: null, storageLocation: '', externalTeam: '', internalTeam: [], // Array of user IDs status: 'new', financials: 0.00 }, statusOptions: [ { text: 'Neu', value: 'new' }, { text: 'In Bearbeitung', value: 'wip' }, { text: 'Abgeschlossen', value: 'finished' }, { text: 'Storniert', value: 'cancelled' } ] }; }, //language=Vue template: `
Strg+Klick für Mehrfachauswahl
Wird automatisch berechnet.
`, async mounted() { this.fetchUsers(); if (this.id !== 'create') { this.loading = true; try { const { data } = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseProject/getById`, { params: { id: this.id } }); if (data) { this.project = { ...this.project, ...data }; // Ensure dates are in YYYY-MM-DD format for input type="date" if (this.project.startDate) this.project.startDate = this.formatDateForInput(this.project.startDate); if (this.project.endDate) this.project.endDate = this.formatDateForInput(this.project.endDate); } } catch (e) { console.error(e); window.notify('error', 'Projekt konnte nicht geladen werden.'); } finally { this.loading = false; } } }, methods: { async fetchUsers() { try { const res = await axios.get(`${window.TT_CONFIG["BASE_PATH"]}/WarehouseProject/getUsers`); this.allUsers = res.data; } catch(e) { console.error(e); } }, formatDateForInput(timestamp) { if (!timestamp) return null; return new Date(timestamp * 1000).toISOString().split('T')[0]; }, formatPrice(val) { return new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(val || 0); }, async submit() { if (!this.project.title || !this.project.startDate || !this.project.endDate) { return window.notify('error', 'Bitte füllen Sie alle Pflichtfelder aus (*).'); } this.loading = true; try { const payload = { ...this.project }; if (payload.startDate) payload.startDate = Math.floor(new Date(payload.startDate).getTime() / 1000); if (payload.endDate) payload.endDate = Math.floor(new Date(payload.endDate).getTime() / 1000); const url = `${window.TT_CONFIG["BASE_PATH"]}/WarehouseProject/${this.id === 'create' ? 'create' : 'update'}`; const response = await axios.post(url, payload); if (response.data.success) { this.$emit('close'); window.notify('success', response.data.message || 'Gespeichert.'); } else { window.notify('error', response.data.message || 'Fehler beim Speichern.'); } } catch (e) { console.error(e); window.notify('error', 'Ein Systemfehler ist aufgetreten.'); } finally { this.loading = false; } } } });