import Magix from 'magix' import * as View from '../../../../view' import * as GlobalHelper from '../../../mixins/helper' import * as RemoveEmptySet from '../../../mixins/removeEmptySet' import crowdHelper from '../../crowds-new/helper' Magix.applyStyle('@./effect-analysis.less') const INDICATORS = [{ text: 'CTR', value: 'ctrRptIndex' }, { text: 'CVR', value: 'cvrRptIndex' }] const CTR_INDEX_KEY = INDICATORS[0].value const INDICATORS_MAP = Magix.toMap(INDICATORS, 'value') const analyseTags = [ { id: '114554', name: '性别分布' }, { id: '114555', name: '年龄分布' }, { id: '113448', name: '消费者层级分布' }, { id: '113671', name: '地域分布' } ] export default View.extend({ tmpl: '@effect-analysis.html', mixins: [RemoveEmptySet], init (options) { this.options = options }, async render () { const { crowd: subsideCrowd, inputType } = this.options const selectedInd = this.updater.get('selectedInd') || INDICATORS[0].value for (const tag of analyseTags) { tag.loading = true } if (!inputType) { // 沉淀人群不需要请求人群信息 const crowd = await this.getCrowdInfo() this.updater.set({ crowd }) } const mainCate = await GlobalHelper.getMainCate(this) let isConfirm if (!inputType) { // 沉淀人群不需要dump const analysisObj = { selectTagOptionSet: [{ id: this.options.crowdId }] } isConfirm = await this.getCrowdDumpStatus(analysisObj.selectTagOptionSet[0].id) } this.updater.digest({ subsideCrowd, INDICATORS_MAP, mainCate, analyseTags, INDICATORS, selectedInd }) if (isConfirm === undefined) { this.renderCharts() } }, async getCrowdInfo () { try { const models = [{ name: 'api_crowd_$id_get', pathParams: [this.options.crowdId] }] const [model] = await this.fetch(models) const data = model.get('data.crowd', {}) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, async renderCharts () { const { analyseTags } = this.updater.get() for (const tag of analyseTags) { this.renderChart(tag) } }, async renderChart (tag) { const { analyseTags } = this.updater.get() const chartDataFull = await this.getTagAnalysis(tag.id) const chartOptions = this._getChartOptions(chartDataFull) tag.loading = false tag.chartOptions = chartOptions tag.chartDataFull = chartDataFull this.updater.digest({ analyseTags }) }, async getTagAnalysis (id) { try { const { inputType } = this.options // 沉淀人群有inputType const { crowd, mainCate, selectedInd, subsideCrowd, all } = this.updater.get() const params = { version: '2.0', needUnknown: false, effectQuery: { indexTypes: [ 'ctr_rpt' ], cateId: mainCate, deliverType: this.options.deliverType }, crowdId: this.options.crowdId, selectTagOptionSet: crowd && crowd.selectTagOptionSet } // 沉淀人群需要手动拼 selectTagOptionSet 结构 // 沉淀人群有inputType if (inputType) { const selectTagOptionSet = $.extend(true, {}, all.selectTagOptionSet_412) const set = crowdHelper.getSubsideSelectTagOptionSet(subsideCrowd) selectTagOptionSet.selectTagOptionSet[0].selectTagOptionSet[0].selectTagOptionSet[0] = set params.selectTagOptionSet = selectTagOptionSet } const models = [{ name: 'api_analysis_tag_$id_post', pathParams: [id], params, isJson: true }] const [model] = await this.fetch(models) const data = model.get('data.chartDataFull', []) // 处理下数据 if (selectedInd === CTR_INDEX_KEY) { for (const item of data) { item[selectedInd] = parseFloat((item[selectedInd] * 100).toFixed(1)) } } return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, // _getChartOptions (chartDataFull) { const { selectedInd, Accounting } = this.updater.get() const chartOptions = this.getChartOptions(18) chartOptions.graphs[0].field = selectedInd chartOptions.tips = { content: (data, e) => { return `