import Magix from 'magix' import View from '../../../../view' Magix.applyStyle('@./initial-channel-flow.less') const STATUS_DEEPEN_ID = 'deeplinkSubdivideStatusDeepenAnalysis' export default View.extend({ tmpl: '@initial-channel-flow.html', init(options) { this.options = options this.observeLocation(['benchmarkFlow', 'statusId']) }, async render() { const loc = Magix.Router.parse() const { statusId } = this.options this.options.statusId = loc.get('statusId') || statusId const benchmarkFlow = loc.get('benchmarkFlow') === 'true' this.updater.set({ benchmarkFlow }) this.updater.set(this.options) const data = await this.getData() this.updater.digest({ data }) // 有同行数据 延迟加载 if (benchmarkFlow) { await this.renderBenchmark() } }, async renderBenchmark() { const { data } = this.updater.get() const { benchmarkId } = this.options const dataBenchmark = await this.getOriginData('1', benchmarkId) data.list.forEach((item, i) => { const benchmarkKeys = [ 'uv', 'reachedUvRate', 'reachedFreq', 'deepenUv', 'deepenRate', 'undeepenUv', 'undeepenRate' ] item.benchmarkLoading = false // 同行数据根据 key 与本店数据做匹配 const benchmarkChannelData = dataBenchmark.list.find(channel => channel.key === item.key) ?? {} if (benchmarkChannelData) { for (const key of benchmarkKeys) { item[`${key}Benchmark`] = benchmarkChannelData[key] } } }) this.updater.digest({ data }) }, async getData() { const { benchmarkFlow } = this.updater.get() const data = await this.getOriginData('0') if (benchmarkFlow) { for (const item of data.list) { item.benchmarkLoading = true } } return data }, async getOriginData(benchmark, benchmarkId) { try { const { brandId, dateType, startDate, bizDate, statusId, analyseCrowd = {} } = this.options const params = { brandId, dateType, startDate, bizDate, statusId, benchmark, benchmarkId, crowdId: analyseCrowd.crowdId } const models = [ { name: 'api_asset_deeplink_transfer_channel_get', params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error) } }, // 切换显示 同行标杆 'toggle'(e) { const { benchmarkFlow } = this.updater.get() Magix.Router.to({ benchmarkFlow }) }, // 查看未加深人群机会 'checkNoDeepenChance'(e) { Magix.Router.to({ statusDeepenType: '1' }) document.getElementById(STATUS_DEEPEN_ID).scrollIntoView({ behavior: 'smooth' }) }, // 查看分层流转详情 'checkFlowContribute'(e) { Magix.Router.to({ statusDeepenType: '2' }) document.getElementById(STATUS_DEEPEN_ID).scrollIntoView({ behavior: 'smooth' }) } })