import Magix from 'magix' import View from '../../../../view' import * as GlobalHelper from '../../../mixins/helper' Magix.applyStyle('@./channels-effect.less') export default View.extend({ tmpl: '@channels-effect.html', init(options) { this.options = options }, async render() { // 渠道 const { beginDate, endDate } = this.options // 总消耗 const { chargeData, chargeTotal } = await this.getAllChannelsData() this.updater.set({ beginDate, endDate, chargeData, chargeTotal }) await this.getChannelsData() this.updater.digest() }, // 获取所有渠道消耗数据 async getAllChannelsData() { try { const { beginDate, endDate, id } = this.options const params = { beginDate, endDate, crowdId: id, indicators: [] } const models = [ { name: 'api_report_channel_list_get', params } ] const [model] = await this.fetch(models) const data = model.get('data', []) let chargeTotal = 0 data.forEach((item, i) => { item.charge = item.charge || 0 chargeTotal += item.charge }) for (const item of data) { item.chargeRatio = item.charge / chargeTotal } const result = { chargeData: data, chargeTotal } return result } catch (error) { this.alert('错误提示', error.msg || error.message || error) } }, // 获取分渠道数据 async getChannelsData() { try { const { chargeData } = this.updater.get() const { beginDate, endDate, id, selectedIndicators } = this.options const models = [] for (const channel of chargeData) { const params = { beginDate, endDate, crowdId: id, indicators: selectedIndicators.map(ind => ind.key), deliverType: channel.deliverType } models.push({ name: 'api_report_overview_get', params }) } const respModels = await this.fetch(models) respModels.forEach((resp, i) => { const data = resp.get('data', []) chargeData[i].data = data }) } catch (error) { this.alert('错误提示', error.msg || error.message || error) } }, 'showChannelEffect'(e) { const { channel } = e.params const { id, beginDate, endDate, indicators } = this.options const viewPath = '@./crowd-trend' const viewOptions = { deliverType: channel.deliverType, id, beginDate, endDate, indicators, isModal: true } const dialogOptions = { width: 1060, header: { title: `${channel.name}渠道效果趋势` }, footer: { cancel: false, enterText: '关闭' } } this.mxModal(viewPath, viewOptions, dialogOptions) }, showPlanAnalysis(e) { const { channel } = e.params const { id, beginDate, endDate, indicators, selectedIndicators } = this.options const viewPath = '@./plan-analysis' const viewOptions = { deliverType: channel.deliverType, id, beginDate, endDate, indicators, selectedIndicators, channelName: channel.name } const dialogOptions = { width: 1220, header: { title: `${channel.name}投放计划分析` }, footer: { cancel: false, enterText: '关闭' } } this.mxModal(viewPath, viewOptions, dialogOptions) }, 'showPlanAnalysis'(e) { this.showPlanAnalysis(e) } })