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('@./l-brand.less') const { localStorage } = window export default View.extend({ tmpl: '@l-brand.html', mixins: [TopBarFixed], init (options) { this.options = options this.on('destroy', (e) => { $(window).off(`scroll.${this.id}`) }) this.observeLocation(['brandId', 'theDate']) const { user } = this.updater.get() this.updater.set({ LOCALSTORAGE_KEY_DEEPLINK_BRAND_ID: `_dmp_deeplink_brandId_${user?.loginUser?.userId}` }) }, async render () { const loc = Magix.Router.parse() const { LOCALSTORAGE_KEY_DEEPLINK_BRAND_ID } = this.updater.get() const [brands, maxDate] = await Promise.all([this.getBrands(), this.getMaxDate()]) const brandId = loc.get('brandId') || localStorage.getItem(LOCALSTORAGE_KEY_DEEPLINK_BRAND_ID) || (brands[0] && brands[0].brandId) const theDate = loc.get('theDate') || maxDate const minDate = '2021-10-27' // 最小日期固定 this.updater.digest({ minDate, maxDate, theDate, brands, brandId }) // 计算好要吸顶的topbar的宽度 this._setTopBarWidth() // 吸顶处理 this._setBarTop() }, async getMaxDate () { try { const models = [{ name: 'api_assets_deeplink_brand_maxDate_get' }] const [model] = await this.fetch(models) const data = model.get('data') return data } catch (error) { this.alert('错误提示', error.msg || error.message || error) } }, async getBrands () { try { const params = {} const models = [{ name: 'api_databank_deeplink_get', params }] const [model] = await this.fetch(models) const data = model.get('data', []) return data.filter(item => { return item.status == 1 }) } catch (error) { this.alert('错误提示', error.msg || error.message || error) } return [{ text: '品牌1', value: 1 }, { text: '品牌2', value: 2 }] }, 'changeBrand' (e) { const { brandId, LOCALSTORAGE_KEY_DEEPLINK_BRAND_ID } = this.updater.get() Magix.Router.to({ brandId }) localStorage.setItem(LOCALSTORAGE_KEY_DEEPLINK_BRAND_ID, brandId) }, 'changeDate' (e) { const { theDate } = this.updater.get() Magix.Router.to({ theDate }) } })