import Magix from 'magix' import View from '../../../../view' import TopBarFixed from 'dmp-new/views/mixins/top-bar-fixed' Magix.applyStyle('@dmp-new/views/mixins/top-bar-fixed.less') Magix.applyStyle('@./top-bar.less') export default View.extend({ tmpl: '@top-bar.html', mixins: [TopBarFixed], init(options) { this.on('destroy', e => { $(window).off(`scroll.${this.id}`) }) const { user } = this.updater.get() this.updater.set({ LOCALSTORAGE_KEY_DEEPLINK_BRAND_ID: `_dmp_deeplink_brandId_${user?.loginUser?.userId}` }) // this.assign(options) }, assign(options) { this.options = options return true }, async render() { const loc = Magix.Router.parse() const { localStorage } = window const { LOCALSTORAGE_KEY_DEEPLINK_BRAND_ID, user: { permissions2 }, all } = this.updater.get() const [statusIds, brands, analyseCrowds] = await Promise.all([ this.getStatusIds(), this.getBrands(), this.getAnalyseCrowds() ]) const statusIdsMap = Magix.toMap(statusIds, 'value') const statusId = loc.get('statusId') || '2001' // 默认2001:发现人群 const brandsMap = Magix.toMap(brands, 'value') const brandId = loc.get('brandId') || localStorage.getItem(LOCALSTORAGE_KEY_DEEPLINK_BRAND_ID) || (brands[0] && brands[0].value) // 分析人群默认取第一个 let analyseCrowd = {} if (loc.get('crowdId')) { analyseCrowd = analyseCrowds.find(crowd => crowd.crowdId == loc.get('crowdId')) || {} } else { // crowdType=0代表预定义默认人群 analyseCrowd = analyseCrowds.find(crowd => crowd.crowdType == 0) } const dataObj = { statusIds, statusIdsMap, analyseCrowd, statusId, brandsMap, brands, brandId, startDate: analyseCrowd?.marketCreateDate, bizDate: analyseCrowd?.marketEndDate, dateType: 4 } // 白金用户才有自定义品牌池 if (permissions2[all.DEEPLINK_ASSETS_PERMISSION_KEY] && brandId) { const { list: benchmarkBrands } = await this.getBenchmarkBrands(brandId) const { benchmarkId = benchmarkBrands[0].benchmarkId } = loc.params Object.assign(dataObj, { benchmarkBrands, benchmarkId }) } this.updater.digest(dataObj) // 回传 this.options.topBarCallback(dataObj) // 计算好要吸顶的topbar的宽度 this._setTopBarWidth() // 吸顶处理 this._setBarTop() if (loc.get('showMoreCrowds')) { this.showMoreCrowds() Magix.Router.to({ showMoreCrowds: '' }) } }, // invoke from '../flow-crowd' setStatusId(statusId) { this.updater.digest({ statusId }) // 计算好要吸顶的topbar的宽度 this._setTopBarWidth() // 吸顶处理 this._setBarTop() }, // 获取品牌标杆池下拉 async getBenchmarkBrands(brandId) { try { const params = { brandId } const models = [ { name: 'api_deeplink_benchmark_list_get', params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) data.list = data.list.filter( item => item.benchmarkBrands && item.benchmarkBrands.length ) return data } catch (error) { console.error(error) } }, // 获取已添加的分析人群 async getAnalyseCrowds() { try { const params = {} const models = [ { name: 'api_asset_deeplink_market_crowdList_get', params } ] const [model] = await this.fetch(models) const data = model.get('data.list', []) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error) } }, async getStatusIds() { try { const params = {} const models = [ { name: 'api_asset_deeplink_statusList_get', params // cache: 10 * 60 * 1000 } ] const [model] = await this.fetch(models) const data = model.get('data', []) // data = data.filter(item => { // return item.id != 0 // }) return data.map(item => { return { text: item.name + '人群', value: item.id } }) } catch (error) { this.alert('错误提示', error.msg || error.message || error) } }, async getBrands() { try { const params = { type: 4 } const models = [ { name: 'api_deeplink_vip_brand_list_get', params } ] const [model] = await this.fetch(models) const data = model.get('data', []) const result = data.filter(item => { return item.status == 1 }) // return [] return result.map(item => { return { text: item.brandName, value: item.brandId } }) } catch (error) { this.alert('错误提示', error.msg || error.message || error) } }, 'changeBrandId'(e) { const { brandId, LOCALSTORAGE_KEY_DEEPLINK_BRAND_ID } = this.updater.get() Magix.Router.to({ brandId }) // brandId记录在localStorage里,切换页面时还原 window.localStorage.setItem(LOCALSTORAGE_KEY_DEEPLINK_BRAND_ID, brandId) }, 'changeStatusId'(e) { const { statusId } = this.updater.get() Magix.Router.to({ statusId }) }, showMoreCrowds() { const { analyseCrowd } = this.updater.get() const viewPath = '@./analyse-crowds' const viewOptions = { analyseCrowd } const dialogOptions = { header: { title: '选择自定义的 DEEPLINK 细分市场' // tip: '添加当天开始计算,人群规模小于XXX不支持添加!' }, footer: { enter: false, cancel: true, cancelText: '关闭' }, width: 780 } this.mxModal(viewPath, viewOptions, dialogOptions) }, 'showMoreCrowds'(e) { this.showMoreCrowds() }, // 切换标杆品牌池下拉,将页面上第一个模块的同行switch自动打开 'changeBenchmarkBrand'(e) { const { benchmarkId } = this.updater.get() Magix.Router.to({ benchmarkSubdivide: true, benchmarkId }) }, 'manageBenchmark'(e) { const { brandId } = this.updater.get() const loc = Magix.Router.parse() Magix.Router.to('/deeplink/compete-brands/list', { brandId, backPath: loc.path, backPathParams: JSON.stringify(loc.params) }) } })