// RMLWorkorderAdmin.js
Vue.component('r-m-l-workorder-admin', {
template: `
{{ workordersToAssign.length }} Workorder(s) zuweisen:
Kunde: {{ row.customerCompany || row.customerName }}
Anschluss:
{{ row.street }} {{ row.hausnummer }}
/{{ row.stiege }}
/ WE: {{ row.apartment }}
, {{ row.plz }} {{ row.city }}
OAID: {{ row.oaid }}
{{ getStatusColumn(row.status).text }}
{{ row.companyName || 'N/A' }}
{{ row.additionalInfo || '-' }}
{{ formatDate(row.deadlineDate) }}
{{ formatDate(row.appointmentDate, true) }}
`,
data() {
return {
window,
workordersToAssign: [],
editingWorkorderId: null,
editingDeadlineId: null,
editingAdditionalInfoId: null,
tempAdditionalInfo: '',
companiesByTenant: {},
companiesLoading: false,
massAssignCompanyId: null,
massAssignLoading: false,
companiesForMassAssign: [],
crudConfig: {
...window.TT_CONFIG.CRUD_CONFIG, selectable: false, expandable: true,
customRowClass: (row) => {
if (['completed', 'new', 'cancelled'].includes(row.status)) return 'tt-rml-workorder-irrelevant';
if (['correction_requested', 'intervention_required'].includes(row.status)) return 'tt-rml-workorder-high';
const deadlineDate = moment.unix(row.deadlineDate);
if (!deadlineDate.isValid()) return 'tt-rml-workorder-irrelevant';
const daysLeft = deadlineDate.diff(moment(), 'days');
if (daysLeft <= 7) return 'tt-rml-workorder-urgent';
if (daysLeft <= 21) return 'tt-rml-workorder-medium';
return 'tt-rml-workorder-ontrack';
},
additionalActions: []
}
}
},
methods: {
addToAssignList(row) {
if (!this.workordersToAssign.includes(row.id)) this.workordersToAssign.push(row.id);
},
removeFromAssignList(row) {
this.workordersToAssign = this.workordersToAssign.filter(id => id !== row.id);
},
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 getCompaniesForWorkorder(workorder) {
if (!workorder.tenantId || this.companiesByTenant[workorder.tenantId]) return;
this.companiesLoading = true;
try {
const {data} = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/getCompanies`, {params: {tenantId: workorder.tenantId}});
this.$set(this.companiesByTenant, workorder.tenantId, data);
} catch (e) {
window.notify('error', 'Firmenliste konnte nicht geladen werden.');
} finally {
this.companiesLoading = false;
}
},
async startCompanyEdit(row) {
await this.getCompaniesForWorkorder(row);
this.editingWorkorderId = row.id;
},
async assignCompany(workorder, companyId) {
if (!companyId) {
this.editingWorkorderId = null;
return;
}
try {
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/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.');
} catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
} finally {
this.editingWorkorderId = null;
}
},
async massAssignCompanies(companyId) {
if (!companyId) return;
if (!confirm(`${this.workordersToAssign.length} Workorder(s) der ausgewählten Firma zuweisen?`)) {
this.massAssignCompanyId = null;
return;
}
this.massAssignLoading = true;
try {
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/massAssignWorkorders`, {
companyId: companyId,
workorderIds: this.workordersToAssign
});
if (data.success) {
window.notify('success', data.message);
this.workordersToAssign = [];
this.$refs.table.$refs.table.refreshTable();
} else window.notify('error', data.message || 'Ein Fehler ist aufgetreten.');
} catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
} finally {
this.massAssignLoading = false;
this.massAssignCompanyId = null;
}
},
async updateDeadline(workorder, newDate) {
if (!newDate) {
this.editingDeadlineId = null;
return;
}
try {
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/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', 'Ein Netzwerkfehler ist aufgetreten.');
} finally {
this.editingDeadlineId = null;
}
},
async acceptDocumentation(workorderId) {
if (!confirm('Soll die Dokumentation für diesen Arbeitsauftrag wirklich akzeptiert und der Auftrag abgeschlossen werden?')) return;
try {
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/acceptDocumentation`, {workorderId});
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', 'Ein Netzwerkfehler ist aufgetreten.');
}
},
async setToProblemSolved(row) {
const text = prompt('Bitte geben Sie einen kurzen Text für den Journaleintrag ein:', '');
if (text === null) return;
if (!text.trim()) {
window.notify('error', 'Bitte geben Sie einen Text ein.');
return;
}
try {
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/setToProblemSolved`, {
workorderId: row.id,
text: text
});
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', 'Ein Netzwerkfehler ist aufgetreten.');
}
},
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, newInfo) {
if (row.additionalInfo === newInfo) {
this.cancelEdit();
return;
}
try {
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/updateAdditionalInfo`, {
workorderId: row.id,
additionalInfo: newInfo
});
if (data.success) {
window.notify('success', data.message);
row.additionalInfo = newInfo;
} else window.notify('error', data.message || 'Update fehlgeschlagen.');
} catch (e) {
window.notify('error', 'Netzwerkfehler beim Update.');
} finally {
this.cancelEdit();
}
},
async cancelWorkorder(row) {
const reason = prompt('Bitte geben Sie einen Grund für die Stornierung an (optional):');
if (reason === null) return;
try {
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/cancelWorkorder`, {
workorderId: row.id,
reason: reason
});
if (data.success) {
window.notify('success', data.message);
this.$refs.table.$refs.table.refreshTable();
} else window.notify('error', data.message || 'Stornierung fehlgeschlagen.');
} catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
}
}
},
watch: {
workordersToAssign: {
async handler(newVal) {
if (newVal.length === 0) {
this.companiesForMassAssign = [];
return;
}
const firstWorkorder = this.$refs.table.$refs.table.rows.find(r => r.id === newVal[0]);
if (!firstWorkorder) return;
const firstTenantId = firstWorkorder.tenantId;
if (!newVal.every(id => {
const wo = this.$refs.table.$refs.table.rows.find(r => r.id === id);
return wo && wo.tenantId === firstTenantId;
})) {
window.notify('error', 'Massen-Zuweisung nur für Aufträge des gleichen Mandanten möglich.');
this.workordersToAssign.pop();
return;
}
await this.getCompaniesForWorkorder(firstWorkorder);
this.companiesForMassAssign = this.companiesByTenant[firstTenantId] || [];
},
deep: true
}
}
});
Vue.component('traffic-light', {
props: ['deadline', 'status'],
computed: {
lightInfo() {
if (['completed', 'new', 'cancelled'].includes(this.status)) return {
color: '#cccccc',
title: 'Status irrelevant für Dringlichkeit'
};
const deadlineDate = moment.unix(this.deadline);
if (!deadlineDate.isValid()) return {color: '#cccccc', title: 'Keine Deadline gesetzt'};
if (deadlineDate.isBefore(moment())) return {color: '#dc3545', title: 'Deadline überschritten'};
const daysLeft = deadlineDate.diff(moment(), 'days');
if (daysLeft <= 7) return {color: '#dc3545', title: 'Dringend: Weniger als 1 Woche'};
if (daysLeft <= 21) return {color: '#ffc107', title: 'Mittel: Weniger als 3 Wochen'};
return {color: '#28a745', title: 'Im Plan: Mehr als 3 Wochen'};
}
},
template: `●`
});
Vue.component('rml-documentation-viewer-admin', {
props: ['workorderId'],
template: `
Wählen Sie die zu korrigierenden Dokumente aus der Galerie aus und geben Sie
einen Grund an.
Prüfen Sie, ob alle erforderlichen Dokumente vorhanden und korrekt sind.
-
{{ formatDate(log.create) }} ({{ log.createByName }}):
{{ log.text }}
Keine Journaleinträge.
`,
data: () => ({
loading: true,
loadingConfig: true,
correctionLoading: false,
docs: [],
journals: [],
selectedDocs: [],
correctionText: '',
newJournalMessage: '',
addingJournalEntry: false,
tenantDocTypes: null
}),
computed: {
requiredDocTypes() {
if (this.tenantDocTypes) return this.tenantDocTypes;
return [{value: 'photo_hup_mounted', text: 'Foto vom montierten HÜP'}, {
value: 'photo_hup_open',
text: 'Foto von dem offenen HÜP'
}, {
value: 'photo_splice_cassette_hup',
text: 'Foto der Spleißkassette – HÜP'
}, {
value: 'photo_splice_cassette_fcp',
text: 'Foto der Spleißkassette - FCP'
}, {
value: 'photo_hup_closed_stickers',
text: 'Foto vom geschlossenen HÜP mit allen Aufklebern'
}, {value: 'photo_fcp_labeled', text: 'Foto vom FCP beschriftet'}, {
value: 'photo_patch_position_osp',
text: 'Foto der Patch-Position - OSP-Seite'
}, {
value: 'photo_patch_position_anb',
text: 'Foto der Patch-Position - ANB-Seite'
}, {value: 'measurement_protocol_otdr', text: 'ODTR – Messung (1310nm & 1550nm)'}];
}
},
methods: {
isUploaded(docType) {
return this.docs.some(doc => doc.documentType === docType);
},
async fetchData() {
this.loading = true;
try {
const {data} = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/getDocumentation`, {params: {workorderId: this.workorderId}});
this.docs = data.docs;
this.journals = data.journals;
} catch (e) {
window.notify('error', 'Dokumentation konnte nicht geladen werden.');
} finally {
this.loading = false;
}
},
async loadTenantConfig() {
this.loadingConfig = true;
try {
const {data} = await axios.get(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderCompany/getTenantConfig`, {params: {workorderId: this.workorderId}});
if (data.success) this.tenantDocTypes = data.documentationTypes;
} catch (e) {
console.error("Konnte Mandantenkonfiguration nicht laden", e);
} finally {
this.loadingConfig = false;
}
},
async requestCorrection() {
if (!this.correctionText) return window.notify('error', 'Bitte geben Sie einen Grund für die Korrektur an.');
if (this.selectedDocs.length === 0) return window.notify('error', 'Bitte wählen Sie mindestens ein Dokument für die Korrektur aus.');
this.correctionLoading = true;
try {
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/requestCorrection`, {
workorderId: this.workorderId,
text: this.correctionText,
fileIds: this.selectedDocs
});
if (data.success) {
window.notify('success', data.message);
this.correctionText = '';
this.selectedDocs = [];
await this.fetchData();
this.$emit('workorder-updated');
} else window.notify('error', data.message);
} catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
}
this.correctionLoading = false;
},
async addJournalEntry() {
if (!this.newJournalMessage.trim()) return window.notify('error', 'Bitte geben Sie eine Nachricht ein.');
this.addingJournalEntry = true;
try {
const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/RMLWorkorderAdmin/addJournal`, {
workorderId: this.workorderId,
text: this.newJournalMessage
});
if (data.success) {
window.notify('success', data.message || 'Journal-Eintrag hinzugefügt.');
this.newJournalMessage = '';
this.journals = data.journals;
} else window.notify('error', data.message || 'Eintrag konnte nicht gespeichert werden.');
} catch (e) {
window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.');
} finally {
this.addingJournalEntry = false;
}
},
formatDate(timestamp) {
return window.moment.unix(timestamp).format('DD.MM.YYYY HH:mm');
},
},
async mounted() {
await this.loadTenantConfig();
await this.fetchData();
}
});