| | |
| | | type: { type: String, required: true } |
| | | }, |
| | | data() { |
| | | return { stats: {}, rows: [], chart: null } |
| | | return { stats: {}, rows: [], chart: null, loadSeq: 0 } |
| | | }, |
| | | computed: { |
| | | title() { |
| | |
| | | }, |
| | | methods: { |
| | | load() { |
| | | const requests = { |
| | | overview: api.get('/reports/overview').then(res => { this.stats = res.data || {}; this.rows = this.stats.chart || [] }), |
| | | 'top-equipment': api.get('/reports/top-equipment').then(res => { this.rows = res.data || []; this.stats = {} }), |
| | | 'by-team': api.get('/reports/by-team').then(res => { this.rows = res.data || []; this.stats = {} }), |
| | | contractors: api.get('/reports/contractors').then(res => { this.rows = res.data || []; this.stats = {} }), |
| | | trend: api.get('/reports/yearly-trend').then(res => { this.rows = res.data || []; this.stats = {} }) |
| | | const loaders = { |
| | | overview: () => api.get('/reports/overview').then(res => ({ |
| | | stats: res.data || {}, |
| | | rows: (res.data && res.data.chart) || [] |
| | | })), |
| | | 'top-equipment': () => api.get('/reports/top-equipment').then(res => ({ stats: {}, rows: res.data || [] })), |
| | | 'by-team': () => api.get('/reports/by-team').then(res => ({ stats: {}, rows: res.data || [] })), |
| | | contractors: () => api.get('/reports/contractors').then(res => ({ stats: {}, rows: res.data || [] })), |
| | | trend: () => api.get('/reports/yearly-trend').then(res => ({ stats: {}, rows: res.data || [] })) |
| | | } |
| | | ;(requests[this.type] || Promise.resolve()).then(() => this.$nextTick(this.renderChart)) |
| | | const seq = ++this.loadSeq |
| | | const loader = loaders[this.type] |
| | | const request = loader ? loader() : Promise.resolve({ stats: {}, rows: [] }) |
| | | request.then(result => { |
| | | if (seq !== this.loadSeq) return |
| | | this.stats = result.stats |
| | | this.rows = result.rows |
| | | this.$nextTick(this.renderChart) |
| | | }).catch(() => {}) |
| | | }, |
| | | renderChart() { |
| | | if (!this.$refs.chart) return |