import Magix from 'magix' import View from 'dmp-new/view' Magix.applyStyle('@./layer.less') export default View.extend({ tmpl: '@layer.html', init(options) { this.options = options }, async render() { const { isCustom, report, benchmarkBrands, benchmarkId } = this.options const { indsOverview, indsTotal, indsReached, indsMap } = await this.getIndicators() const list = await this.getData(0) const indsReachedDefault = indsReached .filter(item => item.default) .map(item => item.value) const indsReachedCustoms = indsReachedDefault const indsReachedShow = indsReachedDefault this.updater.digest({ benchmarkBrands, benchmarkId, report, isCustom, isCompare: false, indsReachedShow, indsReachedCustoms, indsMap, indsReached, custom: false, indsOverview, indsTotal, indsReachedDefault, list, formatInd: (value, valueType) => { const { formatValue } = this.updater.get() switch (valueType) { case 0: return formatValue(value) case 1: return formatValue(value, 'float2') case 2: return formatValue(value, 'rate') case 3: return value } } }) // 加载对比同行数据 this.renderBenchmark() }, async getData(benchmark) { const { report: { brandId }, taskId, isCustom } = this.options const { benchmarkId } = this.updater.get() const params = { brandId, taskId, benchmark } if (benchmark == '1' && !isCustom) { params.benchmarkId = benchmarkId } const models = [ { name: 'api_deeplink_report_detail_layer_get', params } ] const [model] = await this.fetch(models) const data = model.get('data.list', []) return data }, // 加载对比同行数据 async renderBenchmark() { const { isCompare, listCompare } = this.updater.get() if (isCompare) { this.updater.digest({ loadingCompare: true }) try { const listCompare = await this.getData('1') const { list } = this.updater.get() for (const item of list) { const matchItem = listCompare.find( _item => _item.statusId === item.statusId ) item.compare = matchItem } this.updater.set({ list, listCompare }) } catch (error) { this.alert('提示', error.msg || error.message) } this.updater.digest({ loadingCompare: false }) } }, async getIndicators() { try { const { reportType } = this.options const models = { name: 'api_deeplink_report_indicators_get', params: { reportType } } const [model] = await this.fetch(models) const data = model.get('data', []) for (const item of data) { item.text = item.name item.value = item.key item.tip = item.tips } const indsMap = Magix.toMap(data, 'key') // 指标所属维度 // 1:资产概览 // 2:总资产表现 // 3:营销触达资产表现 const indsOverview = data.filter(item => item.dimType === 1) const indsTotal = data.filter(item => item.dimType === 2) const indsReached = data.filter(item => item.dimType === 3) indsOverview[0].width = 90 // 宽度特殊 indsTotal[0].width = 130 // 宽度特殊 indsTotal[3].width = 120 // 宽度特殊 return { indsOverview, indsTotal, indsReached, indsMap } } catch (error) { console.error(error) } }, 'changeInds'(e) { this.updater.digest({ indsReachedShow: e.custom ? e.customs : e.defaults }) }, 'showCompare'(e) { this.renderBenchmark() }, 'changeBenchmarkBrand'(e) { this.renderBenchmark() } })