const Magix = require('magix'); const View = require('dmp-new/view') Magix.applyStyle('@./index.less') module.exports = View.extend({ tmpl: '@index.html', init(options) { this.options = options //洞察页面的分渠道接口跟其他页面的不一样 this.options.coverageApi = this.options.coverageApi || 'api_deliverpredict_market_post' }, async render() { await this.setChannelConfig() const { all, user } = this.updater.get() this.updater.digest({ isDmp: all.dmpOperType == user.loginUser.operType }) }, //获取并设置分渠道配置 async setChannelConfig() { try { let models = [{ name: 'api_deliverpredict_config_get' }] let [model] = await this.fetch(models) const channels = model.get('data', []) for (const channel of channels) { if (typeof channel.configDetail === 'string') { try { channel.configDetail = JSON.parse(channel.configDetail) } catch (error) { channel.configDetail = [] } } } this.updater.set({ channels }) } catch (error) { this.alert('错误提示', error.msg || error.message) } }, //获取并设置分渠道coverage async setChannelCoverage() { const channels = this.updater.get('channels') try { let params = this.options.callback() if (!params) { for (const channel of channels) { delete channel.coverage } return this.updater.digest({ channels }) } for (const channel of channels) { if (typeof channel.configDetail === 'string') { try { channel.configDetail = JSON.parse(channel.configDetail) } catch (error) { channel.configDetail = [] } } let isZhitongche = channel.deliverProductId === 49 let idOrName = isZhitongche ? 'name' : 'id' $.extend(true, params, { deliverProductId: channel.deliverProductId, targets: channel.configDetail.map(sub => sub[idOrName]), queryType: 2 }) //没有子渠道的,34:单品,44:优酷,直接请求,不要targets const noSubChannels = [34, 44, 32] if (channel.configDetail.length || noSubChannels.includes(channel.deliverProductId)) { //34:单品,44:优酷,直接请求,不要targets if (noSubChannels.includes(channel.deliverProductId)) { delete params.targets } let models = [{ name: this.options.coverageApi, params, isJson: true }] channel.coverageLoading = true this.updater.digest({ channels }) let [model] = await this.fetch(models) channel.coverageLoading = false let data = model.get('data') channel.coverage = data.mergeCoverage channel.hintDataSecurity = data.hintDataSecurity this.updater.digest({ channels }) } } } catch (error) { console.error(error.msg || error.message) // this.alert('错误提示', error.msg || error.message) } }, 'custom'(e) { const me = this const params = this.options.callback() if (!params) { return this.alert('提示', '请先添加标签逻辑', null, { mask: true }) } const channels = $.extend(true, [], this.updater.get('channels')) this.mxModal('@./custom', { coverageApi: this.options.coverageApi, params, channels, async callback() { //配置保存成功,刷新下分渠道的coverage await me.setChannelConfig() await me.setChannelCoverage() } }, { width: 840, header: { title: '渠道自定义预估', // tip: '提示信息', // iconTip: '提示信息展示类型,=icon时小icon提示,否则直接展示' }, footer: { enter: '是否需要确认按钮', enterText: '保存', cancel: '是否需要取消按钮', cancelText: '关闭' } }); } });