import Magix from 'magix' import * as View from '../../../../view' Magix.applyStyle('@./overview.less') export default View.extend({ tmpl: '@overview.html', init (options) { this.options = options }, async render () { const { dateType, latelyDate } = this.options const overviewDatas = await this.getOverviewData() const curInd = overviewDatas[0].key // 选中的指标 this.updater.digest({ latelyDate, dateType, overviewDatas, curInd }) // 加载趋势图 this.renderTrend() }, // 加载趋势图 async renderTrend () { this.updater.digest({ loadingTrend: true }) const { selectedIndicators } = this.options const { curInd, Accounting } = this.updater.get() const chartOptions = this.getChartOptions(16) const selectedIndicatorsMap = Magix.toMap(selectedIndicators, 'key') const trendData = await this.getTrendData(curInd) const selfName = '本店' const peerName = '同行' const indName = selectedIndicatorsMap[curInd].name // 指标中文名 for (const trend of trendData) { trend[selfName] = trend[curInd] trend[peerName] = trend.peerValue } delete chartOptions.legend chartOptions.graphs[0].field = selfName chartOptions.graphs[1].field = peerName chartOptions.tips = { content: (data, e) => { return `
${indName}: ${data.title}
${data.nodes.map(node => { let value = `${node.rowData.valueType == 2 ? `${Accounting.formatNumber(node.value * 100, 2)}%` : `${Accounting.formatNumber(node.value)}`}` if (node.rowData.valueType == 1) { value = Accounting.formatNumber(node.value, 2) } return `
${node.field}:${value}
` }).join('')} ` } } this.updater.digest({ chartOptions, trendData, loadingTrend: false }) }, async getTrendData (key) { try { const { beginDate, endDate } = this.options const models = [{ name: 'api_report_indicator_trend_get', params: { beginDate, endDate, indicators: [key] } }] const [model] = await this.fetch(models) const data = model.get('data', []) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, async getOverviewData () { try { const { beginDate, endDate, selectedIndicators } = this.options const models = [{ name: 'api_report_overview_get', params: { beginDate, endDate, indicators: selectedIndicators.map(ind => ind.key) } // isJson: true }] const [model] = await this.fetch(models) const data = model.get('data', []) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, 'changeIndicator' (e) { this.updater.set({ curInd: e.params.key }) this.renderTrend() } })