const Magix = require('magix') const View = require('dmp-new/view') Magix.applyStyle('@../home/index.less') Magix.applyStyle('@./trace.less') module.exports = View.extend({ tmpl: '@trace-report-trend.html', init(options) { this.options = options this.observeLocation(['startDate', 'endDate', 'currentType']) }, async render() { const trackRecord = this.options.trackRecord const loc = Magix.Router.parse() const all = this.updater.get('all') const Moment = this.updater.get('Moment') const types = [{ name: all.consumerFlowTypeMap[this.options.active], value: 1 }, { name: '对比前一天', value: 2 }] this.updater.set({ crowdId: loc.get('crowdId'), isOneDay: this.options.isOneDay, startDate: loc.get('startDate') || trackRecord.startDate, endDate: loc.get('endDate') || trackRecord.endDate || Moment().format('YYYY-MM-DD'), types, currentType: loc.get('currentType') || types[0].value, trackRecord, active: this.options.active }) let chartData = await this.getData() let chartOptions = this._getChartOptions() this.updater.digest({ chartData, chartOptions }) }, _getChartOptions() { const all = this.updater.get('all') const Accounting = this.updater.get('Accounting') let options = this.getChartOptions(1) let currentType = this.updater.get('currentType') let field = currentType == 1 ? all.consumerFlowTypeMap[this.options.active] : all.consumerFlowTypeLastMap[this.options.active] options.coord.xAxis.field = 'date' options.graphs = [{ type: "line", field, yAxisAlign: "left", icon: { enabled: false } }] options.coord.yAxis = { label: { format(data) { return Accounting.formatNumber(data) } } } return options }, 'changeType'(e) { Magix.Router.to({ currentType: this.updater.get('currentType') }) }, //获取趋势数据 async getData() { try { const startDate = this.updater.get('startDate') const endDate = this.updater.get('endDate') const all = this.updater.get('all') let loc = Magix.Router.parse() let crowdId = loc.get('crowdId') let params = { crowdId, startDate, endDate } let models = [{ name: 'api_crowd_track_report_get', params }] let [model] = await this.fetch(models) let data = model.get('data', []) data.forEach((item, index) => { for (const key in item) { if (all.consumerFlowMap[key]) { //转中文key item[all.consumerFlowMap[key]] = item[key] //加上前一天新增 item[all.consumerFlowMap[key] + '(对比前一天)'] = index === 0 ? 0 : item[key] - data[index - 1][key] } } }) return data } catch (error) { this.alert('错误提示', error.msg || error.message) } }, 'changeDate'(e) { Magix.Router.to({ startDate: e.dates.startStr, endDate: e.dates.endStr }) }, //立即投放 'createCrowd'() { let trackRecordTag = JSON.parse(this.options.trackRecord.storageData) for (const select of trackRecordTag.selects) { select.tagName = this.options.trackRecord.title } Magix.config({ '__trackRecordTag': trackRecordTag }) Magix.Router.to('/crowds/create', { isRemarket: true, tagId: '136395', optionGroupIds: '21652', optionValues: '0:1:2:3' }) } })