const Magix = require('magix') Magix.applyStyle('@./direction.less') const View = require('dmp-new/view') module.exports = View.extend({ tmpl: '@empower-set.html', init (options) { this.options = options }, async getData () { const me = this const user = this.updater.get('user') const all = this.updater.get('all') const pushType = user.loginUser.operType == all.isvOperType ? 2 : 1 try { const models = [{ name: 'api_operation_channel_find_get', params: { pushType } }] const [model] = await this.fetch(models) const data = model.get('data', { result: [] }) // 授权状态附上 data.result.forEach(item => { if (me.options.data.deliverChannels) { me.options.data.deliverChannels.forEach(app => { if (app.channelId == item.id) { item.channelStatus = app.status item.message = app.message } }) } }) return data } catch (error) { this.alert('错误提示', error.msg) } }, async render (e) { const me = this const data = await this.getData() // DRAFT,草稿, GRANTING,授权中, GRANT_SUCCESS,已授权 data.statusMap = { 1: '授权中', 2: '授权成功', 3: '授权失败' } me.updater.digest(data) }, async 'empower' (e) { const me = this try { const models = [{ name: 'api_operation_crowd_package_$id_push_put', pathParams: [this.options.data.id, 'push'], params: { channelId: e.params.id } }] await this.fetch(models) this.alert('提示', '恭喜,渠道授权成功', () => { // 授权成功直接设置为授权中状态 const result = me.updater.get('result') for (const item of result) { if (item.id == e.params.id) { item.channelStatus = 1 } } me.updater.digest({ result }) }, { mask: true }) } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } } })