import Magix from 'magix' import View from '../../../view' Magix.applyStyle('@./l-brand-analysis.less') const TYPE1 = 'firstparty' const TYPE2 = 'ad_outer' const TYPE3 = 'lianmeng' // 联盟外投资产 const KEY_QA = 'qa' const KEY_DMP = 'dmp' const KEY_OTHER = 'other' const KEY_UD = 'ud_eff' const KEY_UD_BRAND = 'ud_brand' // 外投UD品牌渠道 const KEY_TIANHE = 'llbum' // 流量宝 const KEY_LIANMENG = 'lianmeng' // 联盟 const SVG_HEIGHT = 70 const NULL_VALUE = -1 // uv为-1的表示无数据 export default View.extend({ tmpl: '@l-brand-analysis.html', init (options) { this.options = options // this.observeLocation(['type']) }, async render () { const loc = Magix.Router.parse() const { brandId, theDate, maxDate } = this.options const type = loc.get('type') || TYPE1 this.updater.digest({ loading: true }) const data = await this.getData() this.updater.digest({ maxDate, loading: false, NULL_VALUE, TYPE1, TYPE2, TYPE3, KEY_QA, KEY_DMP, KEY_OTHER, KEY_UD, KEY_UD_BRAND, KEY_TIANHE, KEY_LIANMENG, type, subTypes: this.getCrowdLevels(type), brandId, theDate, data }) this.renderSvg() }, renderSvg () { const svgWidth = $(`#${this.id}_svg`).outerWidth() const circleY = 6 const circleRadius = 4 const halfWidth = svgWidth / 2 const quarterWidth = svgWidth / 4 const { type } = this.updater.get() this.updater.set({ svgHeight: SVG_HEIGHT, svgWidth, halfWidth, quarterWidth, circleY, circleRadius, lineY: circleY + circleRadius, halfHeight: (SVG_HEIGHT - (circleY + circleRadius)) / 2, triangleH: 7, triangleW: 5, svgColor: '#bbbbbb', partWidth: svgWidth / 3.5 }) const startX = this.getStartX(type) this.updater.digest({ startX }) }, async getData () { try { const { brandId, theDate } = this.options const params = { brandId, theDate } const models = [{ name: 'api_assets_deeplink_brand_summary_get', params }] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error) } }, getCrowdLevels (type) { const typeMap = { [TYPE1]: [KEY_QA, KEY_DMP, KEY_OTHER], [TYPE2]: [KEY_UD, KEY_UD_BRAND, KEY_TIANHE], [TYPE3]: [KEY_LIANMENG] // 联盟外投资产 } return typeMap[type] }, getStartX (type) { const { partWidth, svgWidth } = this.updater.get() let startX if (type === TYPE1) { startX = svgWidth / 6 } else if (type === TYPE2) { startX = partWidth * 2 + (partWidth * 1.5 / 4) } else if (type === TYPE3) { startX = svgWidth / 2 } return startX }, 'selectType' (e) { const { type } = e.params const startX = this.getStartX(type) this.updater.digest({ type, subTypes: this.getCrowdLevels(type), startX }) Magix.Router.to({ type }) } })