Vue.component('wd-kpi-card', { props: { title: { type: String, required: true }, value: { type: [Number, String], required: true }, icon: { type: String, default: 'fas fa-chart-bar' }, color: { type: String, default: 'primary' }, suffix: { type: String, default: '' }, subtitle: { type: String, default: '' } }, template: `
{{ value }}{{ suffix }}
{{ title }}
{{ subtitle }}
` }); Vue.component('wd-status-chart', { props: { data: { type: Array, required: true } }, template: '
', data() { return { chart: null }; }, mounted() { this.renderChart(); }, watch: { data: { handler() { this.renderChart(); }, deep: true } }, methods: { renderChart() { if (this.chart) this.chart.destroy(); if (!this.data || this.data.length === 0) return; this.chart = new Chart(this.$refs.chart.getContext('2d'), { type: 'doughnut', data: { labels: this.data.map(d => d.label), datasets: [{ data: this.data.map(d => d.count), backgroundColor: this.data.map(d => d.color), borderWidth: 2, borderColor: '#fff' }] }, options: { responsive: true, maintainAspectRatio: false, cutout: '60%', plugins: { legend: { position: 'right', labels: { padding: 15, usePointStyle: true, font: { size: 11 } } }, tooltip: { callbacks: { label: (ctx) => `${ctx.label}: ${ctx.raw} (${((ctx.raw / ctx.dataset.data.reduce((a, b) => a + b, 0)) * 100).toFixed(1)}%)` } } } } }); } } }); Vue.component('wd-company-chart', { props: { data: { type: Array, required: true } }, template: '
', data() { return { chart: null }; }, mounted() { this.renderChart(); }, watch: { data: { handler() { this.renderChart(); }, deep: true } }, methods: { renderChart() { if (this.chart) this.chart.destroy(); if (!this.data || this.data.length === 0) return; this.chart = new Chart(this.$refs.chart.getContext('2d'), { type: 'bar', data: { labels: this.data.map(d => d.company), datasets: [ { label: 'Abgeschlossen', data: this.data.map(d => d.completed), backgroundColor: '#10b981', borderRadius: 4 }, { label: 'In Bearbeitung', data: this.data.map(d => d.pending), backgroundColor: '#f59e0b', borderRadius: 4 }, { label: 'Probleme', data: this.data.map(d => d.issues), backgroundColor: '#ef4444', borderRadius: 4 } ] }, options: { responsive: true, maintainAspectRatio: false, indexAxis: 'y', plugins: { legend: { position: 'top', labels: { usePointStyle: true } } }, scales: { x: { stacked: true, grid: { display: false } }, y: { stacked: true, grid: { display: false } } } } }); } } }); Vue.component('wd-trends-chart', { props: { data: { type: Array, required: true } }, template: '
', data() { return { chart: null }; }, mounted() { this.renderChart(); }, watch: { data: { handler() { this.renderChart(); }, deep: true } }, methods: { renderChart() { if (this.chart) this.chart.destroy(); if (!this.data || this.data.length === 0) return; this.chart = new Chart(this.$refs.chart.getContext('2d'), { type: 'line', data: { labels: this.data.map(d => d.date), datasets: [ { label: 'Erstellt', data: this.data.map(d => d.created), borderColor: '#3b82f6', backgroundColor: 'rgba(59, 130, 246, 0.1)', fill: true, tension: 0.3, pointRadius: 4, pointHoverRadius: 6 }, { label: 'Abgeschlossen', data: this.data.map(d => d.completed), borderColor: '#10b981', backgroundColor: 'rgba(16, 185, 129, 0.1)', fill: true, tension: 0.3, pointRadius: 4, pointHoverRadius: 6 } ] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'top', labels: { usePointStyle: true } } }, scales: { x: { type: 'time', time: { unit: 'day', displayFormats: { day: 'DD.MM.YYYY' }, tooltipFormat: 'DD.MM.YYYY' }, grid: { display: false } }, y: { beginAtZero: true, grid: { color: 'rgba(0,0,0,0.05)' } } } } }); } } }); Vue.component('wd-intervention-rates', { props: { data: { type: Array, required: true } }, template: `
{{ item.company }}
{{ item.rate }}%
{{ item.total }} Ges.
Keine Daten verfügbar
`, methods: { getRateClass(rate) { return rate >= 20 ? 'rate--danger' : rate >= 10 ? 'rate--warning' : 'rate--success'; } } }); Vue.component('workorder-dashboard', { template: `

Dashboard wird geladen...

Bitte wählen Sie einen Mandanten aus

Wählen Sie oben einen Mandanten, um das Dashboard anzuzeigen.

Status-Verteilung

Firmen-Performance

Zeitlicher Verlauf

Firma → Status → Kampagne (Detailansicht)

FirmaStatusAnzahlKampagnen-Aufschlüsselung
{{ row.company }} {{ row.statusLabel }} {{ row.count }} {{ c.name }}: {{ c.count }}
Keine Daten verfügbar

Problemquote pro Firma

Häufigste Status-Übergänge

{{ t.transition }} {{ t.count }}
Keine Daten verfügbar
`, data() { return { selectedTenant: '', dateRange: null, selectedCompany: '', selectedStatuses: [], selectedCampaign: '', filterOptions: { tenants: [], companies: [], statuses: [], campaigns: [] }, kpis: null, statusDistribution: [], companyPerformance: [], timeTrends: [], companyStatusCampaign: [], interventionRates: [], statusTransitions: [], loading: false }; }, async mounted() { const today = new Date(); today.setHours(23, 59, 59, 0); const threeMonthsAgo = new Date(today); threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3); threeMonthsAgo.setHours(0, 0, 0, 0); this.dateRange = { from: Math.floor(threeMonthsAgo.getTime() / 1000), to: Math.floor(today.getTime() / 1000) }; await this.fetchFilterOptions(); }, methods: { async fetchFilterOptions() { try { const response = await axios.get(`${window.TT_CONFIG['BASE_URL']}/getFilterOptions`); this.filterOptions.tenants = response.data.tenants; this.filterOptions.companies = response.data.companies; this.filterOptions.statuses = response.data.statuses; if (this.filterOptions.tenants.length === 1) { await this.onTenantChange(this.filterOptions.tenants[0].value); } } catch (error) { console.error('Error fetching filter options:', error); } }, async onTenantChange(tenantId) { this.selectedTenant = tenantId; this.selectedCampaign = ''; if (tenantId) { try { const response = await axios.post(`${window.TT_CONFIG['BASE_URL']}/getCampaignsForTenant`, { tenantId }); this.filterOptions.campaigns = response.data; } catch (error) { console.error('Error fetching campaigns:', error); } await this.fetchDashboardData(); } }, onDateRangeChange(range) { this.dateRange = range; this.onFilterChange(); }, onFilterChange() { if (this.selectedTenant) this.fetchDashboardData(); }, async fetchDashboardData() { if (!this.selectedTenant) return; this.loading = true; try { const response = await axios.post(`${window.TT_CONFIG['BASE_URL']}/getDashboardData`, { tenantId: this.selectedTenant, dateFrom: this.dateRange?.from || null, dateTo: this.dateRange?.to || null, companyIds: this.selectedCompany ? [this.selectedCompany] : [], statuses: this.selectedStatuses, campaignIds: this.selectedCampaign ? [this.selectedCampaign] : [] }); this.kpis = response.data.kpis; this.statusDistribution = response.data.statusDistribution; this.companyPerformance = response.data.companyPerformance; this.timeTrends = response.data.timeTrends; this.companyStatusCampaign = response.data.companyStatusCampaign; this.interventionRates = response.data.interventionRates; this.statusTransitions = response.data.statusTransitions; } catch (error) { console.error('Error fetching dashboard data:', error); alert('Fehler beim Laden der Dashboard-Daten.'); } finally { this.loading = false; } } } });