import Magix from 'magix' import View from 'dmp-new/view' import Helper from '../helper' import CONSTANT from '../constant' Magix.applyStyle('@dmp-new/views/pages/deeplink/detail.less') Magix.applyStyle('@./analyse-overview.less') const DATE_TEXT = '日期' export default View.extend({ tmpl: '@analyse-overview.html', init(options) { this.options = options }, async render() { const { query, mountedCallback } = this.options const { all } = this.updater.get() try { const { rpt } = await this.getData() const { rpt0 = [] } = rpt if (!rpt0.length) { this.updater.digest({ error: { message: '暂无数据' } }) } else { // 全量指标 const inds = this.getInds( rpt0.find( _rpt => _rpt.headers[all.DEEPLINK_FINAL_STATUS_TEXT] === 'all' ) ) // 分层人群数据 const data = Helper.getGroupedClassify( rpt0.filter( _rpt => _rpt.headers[all.DEEPLINK_FINAL_STATUS_TEXT] !== 'all' ), all.DEEPLINK_FINAL_STATUS_TEXT, false ) data.groupedList = this.grouped(data.list) const key = data.list[0].key // 选中的分层 const statusMap = Magix.toMap(data.list, 'key') this.updater.set({ statusMap, rpt0, allTargets: [], // all 人群对应的选中 layeredTargets: [], // 其他分层的人群对应的选中,分层人群的选中 targets 固定为 add_new,layeredTargets 收集的是分层的 key query, isCreate: false, // 是否开始圈人 inds, data, key, rpt, // 获取对应指标数据 getStatusData: key => { const { rpt } = this.updater.get() const match = rpt.rpt0.find(item => { return item.headers[all.DEEPLINK_FINAL_STATUS_TEXT] === key }) return match.targets } }) const trendData = this.getTrendData() this.updater.digest({ trendData }) } } catch (error) { this.updater.digest({ error }) } // 模块请求完毕回调通知外面,加载下一个模块 mountedCallback && mountedCallback() }, // 人群分层对应的趋势数据,趋势数据是全量给到 getTrendData() { const { key, rpt, Dayjs, all } = this.updater.get() const { rpt2 } = rpt const currData = rpt2.filter(_rpt => { return _rpt.headers[all.DEEPLINK_FINAL_STATUS_TEXT] === key }) return currData.map(_rtp => { return { date: Dayjs(_rtp?.headers[DATE_TEXT]).format('YYYY-MM-DD'), 消费者新增人数: _rtp?.targets?.uv, 广告触达新增人数: _rtp?.targets?.ad_new } }) }, // 获取数据 async getData() { const { bp, query } = this.options const params = { query, bp, moduleId: CONSTANT.OVERVIEW_MODULE_ID } const models = [ { name: 'api_quickcase_moduledatav2_post', isJson: true, params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data }, // 创建人群时获取选中的人群分层参数 getDumpQueries() { const { allTargets, layeredTargets, all } = this.updater.get() const dumpQueries = [] // 全量人群里 targets 有多选 if (allTargets.length) { dumpQueries.push({ rptTitle: 'rpt0', headers: { [all.DEEPLINK_FINAL_STATUS_TEXT]: 'all' }, targets: allTargets.join(',') }) } // 分层人群里 targets 固定为广告新增 ad_new if (layeredTargets) { for (const target of layeredTargets) { dumpQueries.push({ rptTitle: 'rpt0', headers: { [all.DEEPLINK_FINAL_STATUS_TEXT]: target }, targets: 'ad_new' }) } } return dumpQueries }, // 全量指标 getInds(indsData) { const { targets } = indsData const inds = [ { title: '本次广告触达新增人数', value: targets.ad_new, key: 'ad_new', type: 1 // 1:整数,2:百分比 // tips: '描述' }, { title: '本次广告触达新增占比', value: targets.ad_new_zb, key: 'ad_new_zb', type: 2 // 1:整数,2:百分比 // tips: '描述' }, { title: '本次广告关系触达加深人数', value: targets.ad_deepen, key: 'ad_deepen', type: 1 // 1:整数,2:百分比 // tips: '描述' }, { title: '消费者整体关系加深率', value: targets.deepen_rate, key: 'deepen_rate', type: 2 // 1:整数,2:百分比 // tips: '描述' }, { title: '本次广告关系触达加深率', value: targets.ad_deepen_rate, key: 'ad_deepen_rate', type: 2 // 1:整数,2:百分比 // tips: '描述' } ] return inds }, // 分组 grouped(list) { const _map = {} const result = [] for (const item of list) { if (_map[item.aiplKey]) { _map[item.aiplKey].push(item) } else { _map[item.aiplKey] = [item] result.push(_map[item.aiplKey]) } } return result }, 'stopPropagation'(e) { const { isCreate } = this.updater.get() if (isCreate) { e.stopPropagation() } }, 'selectStatusId'(e) { const { key } = e.params this.updater.set({ key }) const trendData = this.getTrendData() this.updater.digest({ trendData }) }, 'triggerCreate'(e) { const { isCreate } = this.updater.get() this.updater.digest({ isCreate: !isCreate }) }, 'createCrowd'(e) { const { query } = this.options const dumpQueries = this.getDumpQueries() if (!dumpQueries.length) { return this._alert( { title: '系统提示', content: '请至少选择一个人群' }, { type: 'warn' } ) } const { bp } = this.options const params = { query, bp, dumpQueries, moduleId: CONSTANT.OVERVIEW_MODULE_ID } const viewPath = '@../dialogs/create-crowd' const viewOptions = { params } const dialogOptions = { top: 100, width: 360 } this.mxDialog(viewPath, viewOptions, dialogOptions) } })