import Magix from 'magix' import View from 'dmp-new/view' Magix.applyStyle('@./top20.less') export default View.extend({ tmpl: '@top20.html', init(options) { this.options = options }, async render() { // const loc = Magix.Router.parse() const { report, taskId, transferType, isInflow, statusIds } = this.options const transferTypeText = isInflow ? '流入' : '流出' const uvField = isInflow ? '流入资产规模UV' : '流出资产规模UV' const gmvField = isInflow ? '流入资产本店成交金额' : '流出资产竞品店铺成交金额' const sortTypes = [ { text: '按资产规模排序', value: 'uv' }, { text: isInflow ? '按本店成交人数排序' : '按竞店成交人数排序', value: 'dealUv' }, { text: isInflow ? '按本店成交金额排序' : '按竞店成交金额排序', value: 'dealGmv' } ] const sortType = sortTypes[0].value this.updater.set({ uvField, gmvField, isInflow, sortType, sortTypes, transferTypeText, statusIds }) const top20 = await this.getTop20() const top20Fixed = $.extend(true, [], top20) this.sortData(top20) const chartData = this._getChartData(top20) const chartOptions = this._getChartOptions() const brandsMap = Magix.toMap(top20, 'brandId') this.updater.digest({ brandsMap, chartOptions, chartData, report, taskId, top20, top20Fixed, transferType }) }, _getChartData(top20) { const chartData = $.extend(true, [], top20) return chartData }, _getChartOptions() { const { isInflow } = this.options const { formatValue } = this.updater.get() const chartOptions = this.getChartOptions(29) const uvField = isInflow ? '流入资产规模UV' : '流出资产规模UV' const gmvField = isInflow ? '流入资产本店成交金额' : '流出资产竞品店铺成交金额' chartOptions.coord.fieldsConfig = { // brandName: { // format: e => { // const maxCount = 6 // if (!e) { // return e // } // const brandName = e.toString() // if (brandName.length < maxCount) { // return brandName // } // // 超过的加折行 // const arr = brandName.split('') // // arr.splice(maxCount - 1, 0, '\n') // return arr.join('') // } // }, uv: { name: uvField, format: e => { return formatValue(e) } }, dealGmv: { name: gmvField, format: e => { return formatValue(e) } } } // chartOptions.tips.content = (e, a, b) => { // const { formatValue, transferTypeText } = this.updater.get() // return ` //
//
${e.xAxis.value}${transferTypeText}资产
// ${e.nodes // .map(node => { // return `
// ${ // node.field // }: ${formatValue( // node.value // )} //
` // }) // .join('')} //
// ` // } return chartOptions }, sortData(top20) { const { sortType } = this.updater.get() return top20.sort((a, b) => { return b[sortType] - a[sortType] }) }, async getTop20() { try { const { transferType, taskId } = this.options const params = { taskId, transferType } const models = [ { name: 'api_deeplink_compete_asset_list_get', params } ] const [model] = await this.fetch(models) const data = model.get('data.list', []) return data } catch (error) { console.error(error) } }, 'createCrowd'(e) { const { report, taskId, transferType, isInflow, statusIds } = this.options const { top20, brandsMap } = this.updater.get() const viewPath = '@./dialog/create-crowd-level' const viewOptions = { report, taskId, transferType, top20, brandsMap, isInflow, statusIds } const dialogOptions = { header: { title: isInflow ? '圈选流入本品牌资产TOP20竞争品牌人群' : '圈选本品牌流出资产TOP20竞争品牌人群' }, footer: { enter: false, cancel: false }, width: 780 } this.mxModal(viewPath, viewOptions, dialogOptions) }, 'changeSortType'(e) { const { top20 } = this.updater.get() this.sortData(top20) this.updater.digest({ top20 }) } })