import Magix from 'magix' import * as View from '../../../../view' Magix.applyStyle('@./index.less') export default View.extend({ tmpl: '@index.html', init (options) { this.options = options this.observeLocation(['sortType', 'sortIndicator', 'keyword', 'isSort']) }, async render () { const loc = Magix.Router.parse() this.updater.digest({ loading: true }) const { beginDate, endDate, dateType } = await this.getDates() const { selectedIndicators, indicators } = await this.getIndicators() // 默认以消耗降序排序 if (!loc.get('isSort')) { return Magix.Router.to({ isSort: '1', sortType: '2', sortIndicator: 'charge' }) } this.updater.digest({ keyword: loc.get('keyword') || '', sortType: loc.get('sortType'), sortIndicator: loc.get('sortIndicator'), beginDate, endDate, dateType, selectedIndicators, indicators, page: 1, pageSize: 15, total: 0 }) this.renderReports() }, async renderReports () { this.updater.digest({ loading: true }) const { pager, list } = await this.getReports() this.updater.digest({ list, page: pager.currentPage, pageSize: pager.pageSize, total: pager.total, loading: false }) }, async getReports () { try { const { beginDate, endDate, selectedIndicators, keyword, pageSize, page, sortType, sortIndicator } = this.updater.get() const params = { beginDate, endDate, keyword, pageSize, page, sortType, sortIndicator, indicators: selectedIndicators.map(ind => ind.key) } const models = [{ name: 'api_report_crowd_list_get', params }] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, // 获取日期 async getDates () { const vf = await this.waitVframeCreated(Magix.Vframe.get(`${this.id}_datePick`)) const dates = vf.invoke('getDates') return dates }, // 获取指标 async getIndicators () { const vf = await this.waitVframeCreated(Magix.Vframe.get(`${this.id}_indicatorPick`)) const inds = vf.invoke('getIndicators') return inds }, async 'changeInd' (e) { const { selectedIndicators } = await this.getIndicators() this.updater.set({ selectedIndicators, page: 1 }) this.renderReports() }, async 'changeDate' (e) { const { beginDate, endDate, dateType } = await this.getDates() this.updater.set({ beginDate, endDate, dateType, page: 1 }) this.renderReports() }, 'changePage' (e) { this.updater.set({ page: e.page, pageSize: e.size }) this.renderReports() }, 'search' (e) { const { keyword } = this.updater.get() this.updater.set({ page: 1 }) Magix.Router.to({ keyword }) }, 'sort' (e) { const { key } = e.params const { sortIndicator, sortType } = this.updater.get() let _sortType let _sortIndicator = key // 1: 升序 // 2:降序 if (key == sortIndicator) { if (sortType == '2') { _sortType = '1' } else if (sortType == '1') { _sortType = '' _sortIndicator = '' } else { _sortType = '2' } } else { _sortType = '2' } Magix.Router.to({ isSort: 1, // 标识已排序 sortType: _sortType, sortIndicator: _sortIndicator }) }, async 'download' (e) { const { beginDate, endDate, Moment } = this.updater.get() if (Moment(beginDate).add(14, 'days').isBefore(Moment(endDate))) { this.alert('提示', '日期期间不能超过15天') e.preventDefault() } } })