// WorkorderTenantConfig.js Vue.component('workorder-tenant-config', { template: `
{{ config.name }}
Dokumentationstypen
  • {{ doc.text }}{{ doc.value }}
Interventionstypen
  • {{ intervention.text }}{{ intervention.value }}

Filter für Auftragserstellung
{{ JSON.stringify(JSON.parse(config.workorderCreationFilters || '{}'), null, 2) }}
Filter für aktive Arbeitsaufträge
{{ JSON.stringify(JSON.parse(config.workorderActiveFilters || '{}'), null, 2) }}
Optionen

Workorder: {{ config.enableWorkorder ? 'Aktiviert' : 'Deaktiviert' }}

WorkorderMPH: {{ config.enableWorkorderMph ? 'Aktiviert' : 'Deaktiviert' }}


Tiefbau-Doku: {{ config.civilEngineeringDocsRequired ? 'Ja' : 'Nein' }}

Kabellänge-Doku: {{ config.requireCableLength ? 'Ja' : 'Nein' }}

Kabeltyp-Doku: {{ config.requireCableType ? 'Ja' : 'Nein' }}

Zugeordnete Firmen
  • {{ company.name }}
Keine Firmen zugeordnet.
{{ company.name }}
Sichtbar für Mandanten
Zugehörige Mitarbeiter (mit RMLCompany-Recht)
  • {{ worker.name }} ( {{ worker.email }})
Keine Mitarbeiter für diese Firma gefunden.
`, data() { return { loading: true, activeTab: 'configs', configs: [], companies: [], editingId: null, editableItem: {}, editableJsonFilter: '', editableJsonActiveFilter: '', showModal: false, newItem: {}, tenantToAdd: null, addressApiUrl: `${window.TT_CONFIG.BASE_PATH}/WorkorderTenantConfig/addressAutocomplete`, docTypesConfig: { fields: { text: {type: 'input', label: 'Anzeigename'}, value: {type: 'input', label: 'Schlüssel'} } }, interventionTypesConfig: { fields: { text: {type: 'input', label: 'Anzeigename'}, value: {type: 'input', label: 'Schlüssel'} } }, }; }, computed: { modalTitle() { return this.activeTab === 'configs' ? 'Neue Konfiguration erstellen' : 'Neue Firma anlegen'; }, companiesByTenantMap() { const map = {}; this.configs.forEach(config => { map[config.addressId] = []; }); this.companies.forEach(company => { try { const visibleFor = JSON.parse(company.visibleForAddressId || '[]'); if (Array.isArray(visibleFor)) { visibleFor.forEach(tenantId => { if (map[tenantId]) map[tenantId].push(company); }); } } catch (e) { } }); return map; } }, methods: { async fetchData() { this.loading = true; try { const [configsRes, companiesRes] = await Promise.all([ axios.get(`${window.TT_CONFIG.BASE_PATH}/WorkorderTenantConfig/getTenantConfigs`), axios.get(`${window.TT_CONFIG.BASE_PATH}/WorkorderTenantConfig/getCompanies`), ]); this.configs = configsRes.data; this.companies = companiesRes.data; } catch (e) { window.notify('error', 'Daten konnten nicht geladen werden.'); } finally { this.loading = false; } }, startEdit(item) { this.editingId = item.id; this.editableItem = JSON.parse(JSON.stringify(item)); if (this.activeTab === 'configs') { this.editableItem.documentationTypes = JSON.parse(this.editableItem.documentationTypes || '[]'); this.editableItem.interventionTypes = JSON.parse(this.editableItem.interventionTypes || '[]'); this.editableJsonFilter = JSON.stringify(JSON.parse(this.editableItem.workorderCreationFilters || '{}'), null, 2); this.editableItem.workorderActiveFilters = this.editableItem.workorderActiveFilters || '{}'; this.editableJsonActiveFilter = JSON.stringify(JSON.parse(this.editableItem.workorderActiveFilters), null, 2); } else { try { this.editableItem.visibleForAddressId = JSON.parse(this.editableItem.visibleForAddressId || '[]'); } catch (e) { this.editableItem.visibleForAddressId = []; } } }, cancelEdit() { this.editingId = null; this.editableItem = {}; this.editableJsonFilter = ''; this.editableJsonActiveFilter = ''; }, async saveItem() { const endpoint = this.activeTab === 'configs' ? 'saveTenantConfig' : 'saveCompany'; let payload = {...this.editableItem}; if (this.activeTab === 'configs') { try { JSON.parse(this.editableJsonFilter); payload.workorderCreationFilters = this.editableJsonFilter; } catch (e) { return window.notify('error', 'Filter für Auftragserstellung ist kein valides JSON.'); } try { JSON.parse(this.editableJsonActiveFilter); payload.workorderActiveFilters = this.editableJsonActiveFilter; } catch (e) { return window.notify('error', 'Filter für aktive Arbeitsaufträge ist kein valides JSON.'); } } try { const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/WorkorderTenantConfig/${endpoint}`, payload); if (data.success) { window.notify('success', data.message); this.cancelEdit(); await this.fetchData(); } else { window.notify('error', data.message || 'Speichern fehlgeschlagen.'); } } catch (e) { window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.'); } }, async deleteItem(item, type) { if (!confirm(`Soll der Eintrag "${item.name}" wirklich gelöscht werden?`)) return; const endpoint = type === 'configs' ? 'deleteTenantConfig' : 'deleteCompany'; try { const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/WorkorderTenantConfig/${endpoint}`, {id: item.id}); if (data.success) { window.notify('success', data.message); await this.fetchData(); } else { window.notify('error', data.message || 'Löschen fehlgeschlagen.'); } } catch (e) { window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.'); } }, openCreateModal() { this.newItem = this.activeTab === 'configs' ? { documentationTypes: [], interventionTypes: [], workorderCreationFilters: '{}', workorderActiveFilters: '{}', civilEngineeringDocsRequired: 0, requireCableLength: 0, requireCableType: 0, enableWorkorder: 1, enableWorkorderMph: 1 } : {visibleForAddressId: []}; this.showModal = true; }, async saveNewItem() { const endpoint = this.activeTab === 'configs' ? 'saveTenantConfig' : 'saveCompany'; try { const {data} = await axios.post(`${window.TT_CONFIG.BASE_PATH}/WorkorderTenantConfig/${endpoint}`, this.newItem); if (data.success) { window.notify('success', data.message); this.showModal = false; await this.fetchData(); } else { window.notify('error', data.message || 'Speichern fehlgeschlagen.'); } } catch (e) { window.notify('error', 'Ein Netzwerkfehler ist aufgetreten.'); } }, addTenant(tenant, isNewItem = false) { const tenantId = typeof tenant === 'object' && tenant !== null ? tenant.value : tenant; const targetArray = isNewItem ? this.newItem.visibleForAddressId : this.editableItem.visibleForAddressId; if (tenantId && !targetArray.includes(tenantId)) targetArray.push(tenantId); this.$nextTick(() => { this.tenantToAdd = null; }); }, removeTenant(index, isNewItem = false) { const targetArray = isNewItem ? this.newItem.visibleForAddressId : this.editableItem.visibleForAddressId; targetArray.splice(index, 1); }, }, async mounted() { await this.fetchData(); } });