import Magix from 'magix' import * as View from '../../../view' Magix.applyStyle('@./crowds-custom.less') Magix.applyStyle('@./include-tags.less') Magix.applyStyle('@./effect.less') export default View.extend({ tmpl: '@effect.html', init (options) { this.options = options }, async render () { const loc = Magix.Router.parse() const { group } = this.options const chartData = [ { bizDate: '2017-03-21', 本店铺触达用户数: 10, 行业标杆触达用户数: 111 }, { bizDate: '2017-03-22', 本店铺触达用户数: 20, 行业标杆触达用户数: 32 }, { bizDate: '2017-03-23', 本店铺触达用户数: 30, 行业标杆触达用户数: 15 }, { bizDate: '2017-03-24', 本店铺触达用户数: 15, 行业标杆触达用户数: 23 }, { bizDate: '2017-03-25', 本店铺触达用户数: 28, 行业标杆触达用户数: 15 } ] const effects = await this.getEffects() const curMetric = effects.metric[0] || {} this.updater.digest({ curMetric, effects, chartData, group }) this.renderChart() }, // 趋势数据图 async renderChart () { this.updater.digest({ loading: true }) const { Accounting, curMetric } = this.updater.get() const trendData = await this.getEffectsTrend(curMetric.key) const text = curMetric.name || '' const selfKey = `本店${text}` const benmarkKey = `行业标杆${text}` for (const d of trendData) { d[selfKey] = d.value d[benmarkKey] = d.benchmark } const chartOptions = this.getChartOptions(14) chartOptions.graphs[0].field = selfKey chartOptions.graphs[1].field = benmarkKey chartOptions.tips.content = (data, e) => { return `
${data.title}
${data.nodes.map(node => { return `
${node.field}:${Accounting.formatNumber(node.value)}
` }).join('')} ` } this.updater.digest({ chartOptions, chartData: trendData, loading: false }) }, // 获取指标数据 async getEffects () { const emptyData = { usage: {}, metric: [] } try { const models = [{ name: 'api_promotion_double11_tagGroupReport_get', params: { tagGroupId: this.options.group.id } }] const [model] = await this.fetch(models) const data = model.get('data', emptyData) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) return emptyData } }, // 获取趋势数据 async getEffectsTrend (key) { if (!key) { return [] } try { const models = [{ name: 'api_promotion_double11_tagGroupReport_daily_get', params: { key, tagGroupId: this.options.group.id } }] 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 }) return [] } }, 'changeLegend' (e) { const { metric } = e.params this.updater.set({ curMetric: metric }) this.renderChart() } })