// WorkorderMphAdmin.js Vue.component('workorder-mph-admin', { template: `

Soll der Auftrag #{{ cancelWorkorderModalData.id }} wirklich storniert werden?

Soll die Zuweisung für Auftrag #{{ unassignWorkorderModalData.id }} aufgehoben werden?

Aktuell zugewiesen an: {{ unassignWorkorderModalData.companyName }}

`, data() { return { window, editingWorkorderId: null, editingDeadlineId: null, editingAdditionalInfoId: null, tempAdditionalInfo: '', companies: [], companiesLoading: false, cancelWorkorderModalData: null, unassignWorkorderModalData: null, crudConfig: { ...window.TT_CONFIG.CRUD_CONFIG, selectable: false, expandable: true, customRowClass: (row) => { if (['completed', 'new', 'cancelled', 'archived'].includes(row.status)) return 'tt-mph-workorder-irrelevant'; const deadlineDate = moment.unix(row.deadlineDate); if (!deadlineDate.isValid()) return 'tt-mph-workorder-irrelevant'; const daysLeft = deadlineDate.diff(moment(), 'days'); if (daysLeft <= 7) return 'tt-mph-workorder-urgent'; if (daysLeft <= 21) return 'tt-mph-workorder-medium'; return 'tt-mph-workorder-ontrack'; } } } }, methods: { getStatusColumn(status) { const column = this.crudConfig.columns.find(c => c.key === 'status'); return column.table.filterOptions.find(opt => opt.value === status) || {}; }, formatDate(timestamp, withTime = false) { if (!timestamp) return '–'; return window.moment.unix(timestamp).format(withTime ? 'DD.MM.YYYY HH:mm' : 'DD.MM.YYYY'); }, async loadCompanies() { if (this.companies.length > 0) return; this.companiesLoading = true; try { const { data } = await axios.get(`${window.TT_CONFIG.BASE_PATH}/WorkorderMphAdmin/getCompanies`); this.companies = data; } catch (e) { window.notify('error', 'Firmenliste konnte nicht geladen werden.'); } finally { this.companiesLoading = false; } }, async startCompanyEdit(row) { await this.loadCompanies(); this.editingWorkorderId = row.id; }, async assignCompany(workorder, companyId) { if (!companyId) { this.editingWorkorderId = null; return; } const { data } = await axios.post(`${window.TT_CONFIG.BASE_PATH}/WorkorderMphAdmin/assignWorkorder`, { workorderId: workorder.id, companyId: companyId }); if (data.success) { window.notify('success', data.message); this.$refs.table.$refs.table.refreshTable(); } else { window.notify('error', data.message || 'Ein Fehler ist aufgetreten.'); } this.editingWorkorderId = null; }, async updateDeadline(workorder, newDate) { if (!newDate) { this.editingDeadlineId = null; return; } try { const { data } = await axios.post(`${window.TT_CONFIG.BASE_PATH}/WorkorderMphAdmin/updateDeadline`, { workorderId: workorder.id, deadlineDate: newDate }); if (data.success) { window.notify('success', data.message); this.$refs.table.$refs.table.refreshTable(); } else { window.notify('error', data.message || 'Ein Fehler ist aufgetreten.'); } } catch (e) { window.notify('error', 'Netzwerkfehler.'); } finally { this.editingDeadlineId = null; } }, startAdditionalInfoEdit(row) { this.editingAdditionalInfoId = row.id; this.tempAdditionalInfo = row.additionalInfo || ''; this.$nextTick(() => this.$refs.editTextarea?.$el.querySelector('textarea').focus()); }, cancelEdit() { this.editingAdditionalInfoId = null; this.tempAdditionalInfo = ''; }, async updateAdditionalInfo(row) { if (row.additionalInfo === this.tempAdditionalInfo) { this.cancelEdit(); return; } try { const { data } = await axios.post(`${window.TT_CONFIG.BASE_PATH}/WorkorderMphAdmin/updateAdditionalInfo`, { workorderMphId: row.id, additionalInfo: this.tempAdditionalInfo }); if (data.success) { window.notify('success', data.message); row.additionalInfo = data.newInfo; } else { window.notify('error', data.message || 'Update fehlgeschlagen.'); } } catch (e) { window.notify('error', 'Netzwerkfehler.'); } finally { this.cancelEdit(); } }, async cancelWorkorder() { const { id, reason } = this.cancelWorkorderModalData; const { data } = await axios.post(`${window.TT_CONFIG.BASE_PATH}/WorkorderMphAdmin/cancelWorkorder`, { workorderId: id, reason: reason }); if (data.success) { window.notify('success', data.message); this.$refs.table.$refs.table.refreshTable(); this.cancelWorkorderModalData = null; } else { window.notify('error', data.message || 'Stornierung fehlgeschlagen.'); } }, async unassignWorkorder() { const { id, reason } = this.unassignWorkorderModalData; const { data } = await axios.post(`${window.TT_CONFIG.BASE_PATH}/WorkorderMphAdmin/unassignWorkorder`, { workorderId: id, reason: reason }); if (data.success) { window.notify('success', data.message); this.$refs.table.$refs.table.refreshTable(); this.unassignWorkorderModalData = null; } else { window.notify('error', data.message || 'Aufheben der Zuweisung fehlgeschlagen.'); } } } });