import Magix from 'magix' import View from 'dmp-new/view' import { REPORT_TYPE_CUSTOM, REPORT_TYPE_MONTHLY, COLD_BOOT_STEPS } from './constant' Magix.applyStyle('@./list.less') const PAGE_SIZE = 10 export default View.extend({ tmpl: '@list.html', async init(options) { this.options = options this.observeLocation(['reportType', 'page', 'brandId']) this.updater.set({ REPORT_TYPE_CUSTOM, COLD_BOOT_STEPS, REPORT_TYPE_MONTHLY, PAGE_SIZE }) }, async render() { const loc = Magix.Router.parse() const { reportType: reportTypeOld, user, all } = this.updater.get() const { reportType = user.permissions2[all.CUSTOM_REPORT_PERMISSION_KEY] ? REPORT_TYPE_CUSTOM // 有白金版权限默认选中自定义月报 : REPORT_TYPE_MONTHLY } = loc.params this.updater.set({ reportType }) const brands = reportTypeOld === reportType ? this.updater.get('brands') // 只改变品牌,不需要重新请求品牌列表 : await this.getBrands() // 切换了月经月报/自定义月报,重新请求品牌列表 const { brandId = brands[0]?.value, page = 1 } = loc.params // 是否自定义月报 const isCustom = reportType == REPORT_TYPE_CUSTOM this.updater.digest({ brands, isCustom, page, brandId, reportType, loading: true }) const { list, quotaInfo = {}, pager = {} } = await this.getReports() this.updater.digest({ pager, list, quotaInfo, loading: false }) }, async getReports() { try { const { brandId, reportType, page } = this.updater.get() const params = { brandId, reportType, pageSize: PAGE_SIZE, page } const models = [ { name: 'api_deeplink_report_task_list_get', params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } catch (error) { console.error(error) } }, async getBrands() { try { const { reportType } = this.updater.get() const models = reportType === REPORT_TYPE_CUSTOM ? { name: 'api_deeplink_vip_brand_list_get', params: { type: 2 } } : { name: 'api_databank_deeplink_get' } 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 } = this.updater.get() Magix.Router.to({ brandId, page: 1 }) }, 'create'(e) { const { brandId, brands } = this.updater.get() const viewPath = '@./dialogs/create' const viewOptions = { brandId, brands, callback: () => { this.render() } } const dialogOptions = { header: { title: '创建新的经营报告' }, footer: { enter: true, enterText: '创建报告', cancel: true }, width: 780 } this.mxModal(viewPath, viewOptions, dialogOptions) }, 'changePage'(e) { const { page } = this.updater.get() Magix.Router.to({ page }) }, async 'remove'(e) { const { taskId } = e.params if ( await this._confirmAsync({ title: '提示', content: '确认要删除该报告吗?' }) ) { try { await this.removeReport(taskId) this.render() } catch (error) { this.alert('提示', error.msg || error.message) } } }, async removeReport(taskId) { const models = [ { name: 'api_deeplink_report_task_$id_delete', pathParams: [taskId] } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } })