import Magix from 'magix' import * as View from '../../../../view' Magix.applyStyle('@./detail.less') export default View.extend({ tmpl: '@detail.html', init (options) { this.options = options }, async render () { const loc = Magix.Router.parse() const { noChannels } = this.options this.updater.digest({}) const { beginDate, endDate, dateType } = await this.getDates() const { selectedIndicators, indicators } = await this.getIndicators() const id = loc.get('id') || this.options.id const name = loc.get('name') || this.options.crowdName this.updater.set({ id, name, beginDate, endDate, dateType, selectedIndicators, indicators, noChannels }) const indicatorData = await this.getIndicatorData() this.updater.digest({ indicatorData, keyword: loc.get('keyword') }) }, // 获取指标数据 async getIndicatorData () { try { const loc = Magix.Router.parse() const { beginDate, endDate, selectedIndicators } = this.updater.get() const params = { beginDate, endDate, indicators: selectedIndicators.map(ind => ind.key), crowdId: this.options.id || loc.get('id') } const models = [{ name: 'api_report_overview_get', params }] 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 getDates () { const vf = await this.waitVframeCreated(Magix.Vframe.get(`${this.id}_datePick`)) const dates = vf.invoke('getDates') return dates }, // 获取指标 async getIndicators () { const vf = await this.waitVframeCreated(Magix.Vframe.get(`${this.id}_indicatorPick`)) const inds = vf.invoke('getIndicators') return inds }, async 'changeInd' (e) { const { selectedIndicators } = await this.getIndicators() this.updater.set({ selectedIndicators }) const indicatorData = await this.getIndicatorData() this.updater.digest({ indicatorData }) }, async 'changeDate' (e) { const { beginDate, endDate, dateType } = await this.getDates() this.updater.digest({ beginDate, endDate, dateType }) const indicatorData = await this.getIndicatorData() this.updater.digest({ indicatorData }) }, async check () { return { ok: true } } })