import Magix from 'magix' import * as View from '../../../../view' Magix.applyStyle('@./ad-trend.less') export default View.extend({ tmpl: '@ad-trend.html', init (options) { this.options = options }, async render () { const { indicators } = this.options const selectedKey = indicators[0].key this.updater.digest({ loading: true, indicators, selectedKey }) this.renderTrend(selectedKey) }, async renderTrend (key) { this.updater.digest({ loadingTrend: true }) const { indicators } = this.options const { Accounting } = this.updater.get() const chartOptions = this.getChartOptions(16) const indicatorsMap = Magix.toMap(indicators, 'key') const trendData = await this.getTrendData(key) const selfName = '本店' const peerName = '同行' const indName = indicatorsMap[key].name // 指标中文名 const valueType = indicatorsMap[key].valueType // 数据类型:0,整数,1:小数,2:小数并且百分比 for (const trend of trendData) { trend[selfName] = trend[key] 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 = valueType == 2 ? `${Accounting.formatNumber(node.value * 100, 2)}%` : `${Accounting.formatNumber(node.value)}` if (valueType == 1) { value = Accounting.formatNumber(node.value, 2) } return `
${node.field}:${value}
` }).join('')} ` } } this.updater.digest({ chartOptions, trendData, loadingTrend: false }) }, async getTrendData (key) { const { beginDate, endDate, deliverType } = this.options try { const models = [{ name: 'api_report_indicator_trend_get', params: { beginDate, endDate, indicators: [key], deliverType } }] 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 }) } }, 'changeKey' (e) { const { selectedKey } = this.updater.get() this.renderTrend(selectedKey) }, async check () { return { ok: true } } })