import Magix from 'magix' import * as View from '../../../../view' Magix.applyStyle('@./customer-analysis.less') const THEME = ['#7E62CC', '#44d699', '#6fc2ff', '#ffc024'] const TREND_THEME = ['#775cd0', '#6588FC', '#5DB7E8', '#55D4B6', '#F06560', '#F08848', '#F2BD49', '#FFD4B5'] export default View.extend({ tmpl: '@customer-analysis.html', init (options) { this.options = options }, async render () { const loc = Magix.Router.parse() const { endDate, beginDate, dateType } = this.options // -1为自定义日期,不显示页面 if (dateType == '-1') { this.updater.digest({ dateType }) return } this._currSelected = 0 const usageLayerData = await this.getUsagelayer() const pieOptions = this.getPieOptions() // 日趋势图 const { usageLayerTrend, field } = await this.getUsagelayerTrend() const trendOptions = this.getTrendOptions(field) // 流转分析类型 const flowTypes = [{ text: '广告曝光', value: '5' }, { text: '达摩盘曝光', value: '4' }, { text: '全店消费者', value: '1' }] this.updater.digest({ flowTypes, selectedFlowType: flowTypes[0].value, options: {}, pieOptions, THEME, TREND_THEME, usageLayerData, usageLayerTrend, trendOptions, endDate, beginDate, dateType }) // 默认选中第一个 const pieVf = await this.waitVframeCreated(Magix.Vframe.get(`${this.id}_pie`)) const pieChart = pieVf.invoke('capture', ['chart']) pieChart.getGraph().selectAt(this._currSelected) this.renderSelected(this._currSelected) }, // 饼图中间显示选中的数据 renderSelected (i) { const { usageLayerData } = this.updater.get() const selectedLayer = usageLayerData[i] this.updater.digest({ selectedLayer }) }, // 处理饼图options getPieOptions () { const me = this const chartOptions = this.getChartOptions(15) chartOptions.theme = THEME chartOptions.graphs[0].node.onclick = function (e, nodeData) { if (me._currSelected == nodeData.iNode) { return } if (me._currSelected !== undefined) { this.unselectAt(me._currSelected) } this.selectAt(nodeData.iNode) me._currSelected = nodeData.iNode me.renderSelected(nodeData.iNode) } return chartOptions }, // 获取饼图分层数据 async getUsagelayer () { try { const { endDate, beginDate } = this.options const params = { endDate, beginDate, type: 2 } const models = [{ name: 'api_report_usagelayer_get', params }] const [model] = await this.fetch(models) const data = model.get('data', []) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, // 处理日趋势图options getTrendOptions (field) { const { Accounting } = this.updater.get() const chartOptions = this.getChartOptions(17) chartOptions.theme = TREND_THEME chartOptions.coord.yAxis = { label: { format: (v, i) => { return Accounting.formatNumber(v) } } } chartOptions.tips = { content: (data, e) => { return `
${data.title}
${data.nodes.map(_data => { // let peerPortion const findData = _data.rowData.list.find(item => { return _data.field.includes(item.name) }) peerPortion = _data.field.includes('本店') ? findData.portion : findData.peerPortion peerPortion = Accounting.formatNumber(peerPortion * 100) return `
${_data.field} ${Accounting.formatNumber(_data.value)}(${peerPortion}%)
` }).join('')} ` } } chartOptions.graphs[0].field = field return chartOptions }, // 获取日趋势分层数据 async getUsagelayerTrend () { try { const { endDate, beginDate } = this.options const params = { endDate, beginDate, type: 2 } const models = [{ name: 'api_report_usagelayer_trend_get', params }] const [model] = await this.fetch(models) const usageLayerTrend = model.get('data', []) const field = [[], []] usageLayerTrend.forEach((trendData, i) => { for (const legend of trendData.list) { const selfKey = `本店${legend.name}` const peerKey = `同行${legend.name}` trendData[selfKey] = legend.value trendData[peerKey] = legend.peerValue if (i === 0) { field[0].push(selfKey) field[1].push(peerKey) } } }) return { usageLayerTrend, field } } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } } })