import Magix from 'magix' import View from 'dmp-new/view' import { COLOR_NEW, COLOR_STOCK, COLOR_BRAND } from '../../constant' Magix.applyStyle('@../summary.less') Magix.applyStyle('@./proportion.less') export default View.extend({ tmpl: '@proportion.html', init(options) { this.options = options }, async render() { const loc = Magix.Router.parse() const { isCompare, data, dataCompare, loadingCompare, config, isCustom } = this.options const blocks = [ { name: '累计', key: 'total', color: COLOR_BRAND, bgColor: '#DECBF9', chartData: this._getChartData('total'), chartOptions: this._getChartOptions('total') }, { isSymbol: true, icon: '' }, { name: '新增', key: 'new', color: COLOR_NEW, bgColor: '#FFD3DF', chartData: this._getChartData('new'), chartOptions: this._getChartOptions('new') }, { isSymbol: true, icon: '' }, { name: '存量', key: 'stock', color: COLOR_STOCK, bgColor: '#D3DDFF', chartData: this._getChartData('stock'), chartOptions: this._getChartOptions('stock') } ] this.updater.digest({ isCustom, blocks, COLOR_BRAND, COLOR_NEW, COLOR_STOCK, config, isCompare, data, dataCompare, loadingCompare }) }, _getChartData(type) { const { data, config } = this.options let proportion if (type === 'total') { proportion = 100 } else { proportion = data[config.key][config[type].proportionKey] * 100 } return [{ proportion }] }, _getChartOptions(type) { const options = this.getChartOptions(13) const colorMap = { total: COLOR_BRAND, new: COLOR_NEW, stock: COLOR_STOCK } options.graphs[0].radius = 30 options.graphs[0].node.width = 7 options.graphs[0].field = 'proportion' options.graphs[0].animation = false options.graphs[0].node.fillStyle = colorMap[type] options.graphs[0].label.fontSize = 15 options.graphs[0].label.format = (v, node) => { return Math.round(v) + '%' } return options } })