import Magix from 'magix' import View from 'dmp-new/view' import { REPORT_TYPE_CUSTOM, REPORT_TYPE_MONTHLY } from './constant' Magix.applyStyle('@./report.less') export default View.extend({ tmpl: '@report.html', init(options) { this.options = options }, async render() { const loc = Magix.Router.parse() const { user, all } = this.updater.get() const { taskId, reportType, isLatestMonthly, brandId } = loc.params // 是否自定义月报 const isCustom = reportType == REPORT_TYPE_CUSTOM const [report] = await Promise.all([ this.getReport(taskId), this.readReport(taskId) ]) // 白金用户才有自定义品牌池 if (user.permissions2[all.DEEPLINK_ASSETS_PERMISSION_KEY] && !isCustom) { const { list: benchmarkBrands } = await this.getBenchmarkBrands(brandId) const { benchmarkId = benchmarkBrands[0].benchmarkId } = loc.params this.updater.set({ benchmarkId, benchmarkBrands }) } this.updater.digest({ brandId, isCustom, REPORT_TYPE_CUSTOM, REPORT_TYPE_MONTHLY, reportType, report, taskId }) if (isLatestMonthly === 'true') { // 移除导航上的新月报标识 const currentNewMonthly = Magix.config('currentMonthly') || {} currentNewMonthly.readStatus = 1 $('.globalNewMonthlyMark').remove() } }, // 获取品牌标杆池下拉 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 readReport(taskId) { try { const params = { readStatus: 1 } const models = [ { name: 'api_deeplink_report_task_$id_put', isJson: true, params, pathParams: [taskId] } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } catch (error) { console.error(error) } }, // 获取报告信息 async getReport(taskId) { try { const models = [ { name: 'api_deeplink_report_task_$id_get', pathParams: [taskId] } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } catch (error) { console.error(error) } } })