const Magix = require('magix') const paramsStr = 'pageSize,currentPage,businessType,creatorName,name' const GetBusinessType = require('./getBusinessType') // const permissionMap = Magix.config('permissionMap') const View = require('dmp-new/view') Magix.applyStyle('@./list.less') module.exports = View.extend({ mixins: [GetBusinessType], tmpl: '@list.html', init() { const me = this me.observeLocation(paramsStr) }, async render() { const { showBatch = false, templateIdList = [] } = this.updater.get() const me = this const params = {} const loc = Magix.Router.parse() paramsStr.split(',').forEach(function (item) { const val = loc.get(item) if (val) { params[item] = val } }) params.pageSize = params.pageSize || 20 params.currentPage = params.currentPage || 1 try { const models = [ { name: 'api_operation_new_template_find_get', params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) me.updater.digest({ templateIdList, showBatch, list: data.list, total: data.pager.total, params }) } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, // 删除模板 async 'remove'(e) { const me = this const id = e.params.templateId me.confirm( { title: '提示', content: '确定要删除本条数据吗?', enterCallback: async () => { try { const models = [ { name: 'api_operation_template_$id_delete', pathParams: [id] } ] await me.fetch(models) me.render() } catch (error) { me.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } } }, { mask: true } ) }, 'search'(e) { if (e.keyCode == 13) { const params = this.updater.get('params') params.currentPage = '1' Magix.Router.to(params) } }, 'reset'(e) { const params = this.updater.get('params') for (const key in params) { params[key] = '' } Magix.Router.to(params) }, 'changePage'(e) { Magix.Router.to({ pageSize: e.size, currentPage: e.page }) }, 'createTemplate'(e) { const { template = {} } = e.params const { id = '' } = template // 1 表示未授权 // 2 表示已经授权 // 3 表示过期 if (!id || template.status == 1) { // 未授权的可以完整编辑模板 Magix.Router.to('/crowds-new/create', { templateId: true, id }) } else { // 其他状态的模板只能修改部分 this.mxDialog( '@./edit', { template, callback: () => { this.render() } }, { width: 500, top: 100 } ) } }, 'copy'(e) { const { id } = e.params Magix.Router.to('/crowds-new/create', { id, templateId: true, isCopy: true }) }, // 授权设置 'accredit'(e) { const templateId = e.params.id const d = this.mxModal( '@../../../xsite-proxy', { xview: 'dmp-xiaoer/views/pages/strategy/template/auth-setting', params: { templateId } }, { width: 1000, header: { title: '推送精选人群' }, footer: { enter: true, cancel: true } } ) d.afterClose(() => { this.render() }) }, // 批量授权设置 'accreditBatch'(e) { const { templateIdList } = this.updater.get() if (!templateIdList.length) { return this.alert('提示', '请至少选择一个模板') } // const templateId = e.params.id const d = this.mxModal( '@../../../xsite-proxy', { xview: 'dmp-xiaoer/views/pages/strategy/template/auth-setting', params: { templateIdList } }, { width: 1000, header: { title: '推送精选人群' }, footer: { enter: true, cancel: true } } ) d.afterClose(() => { this.render() }) }, 'create'(e) { this.mxDialog( '@./createCrowd', { data: { templateId: e.params.templateId } }, { width: 400, top: 100 } ) }, async 'showHideTmpl'(e) { const { list } = this.updater.get() const { tmpl } = e.params try { const visible = tmpl.visible == 1 ? 2 : 1 const models = [ { name: 'api_operation_template_$id_$id_get', pathParams: [tmpl.id, visible] } ] await this.fetch(models) this._alert('提示', `模板${tmpl.visible == 1 ? '隐藏' : '显示'}成功`) tmpl.visible = visible this.updater.digest({ list }) } catch (error) { this.alert('错误提示', error.msg || error.message || error) } }, // 模板推荐 'recommendTmpls'(e) { const viewPath = '@./recommend-tmpls' const viewOptions = {} const dialogOptions = { width: 700, top: 100 } this.mxDialog(viewPath, viewOptions, dialogOptions) }, 'batch'(e) { const { showBatch } = this.updater.get() this.updater.digest({ showBatch: !showBatch }) }, 'selectTmpl'(e) { const { templateIdList } = this.updater.get() if (e.target.checked) { templateIdList.push(e.target.value) } else { templateIdList.splice( templateIdList.findIndex(id => id == e.target.value), 1 ) } this.updater.digest({ templateIdList }) } })