// 此view用于钻展再营销里面调用,dmp没用到,请勿删除 import Magix from 'magix' import View from '../../../view' Magix.applyStyle('@./create-crowd-wrap.less') module.exports = View.extend({ tmpl: '@create-crowd-wrap.html', init(options) { this.options = options }, render() { const tagId = 141309 //钻展再营销的调用的dmp标签:广告渠道用户 let tagSelected = { selects: [{ optionGroupId: 25830, values: '1~' }, { optionGroupId: 25834, values: '30' }] } this['@{owner-node}'] = $(`#${this.id}`) this.updater.digest({ tagSelected, crowds: this.options.crowds || [], tagId: this.options.tagId || tagId, limit: this.options.limit || 3, callback: (tag) => { this.createCrowd(tag) } }); }, getSelectTagOptionSet(tag) { const all = this.updater.get('all') const selectTagOptionSet = $.extend(true, {}, all.selectTagOptionSet_412) const selects = [] for (const group of tag.optionGroups) { let select = { tagId: group.tagId, optionGroupId: group.id, values: group.selected.values.join(','), names: group.selected.names.join(',') } selects.push(select) } selectTagOptionSet.selectTagOptionSet[0].selectTagOptionSet[0].selectTagOptionSet.push({ selects }) return selectTagOptionSet }, async createCrowd(tag) { const me = this const crowds = me.updater.get('crowds') const limit = this.updater.get('limit') if (crowds.length >= limit) { return this.alert('提示', `最多添加${limit}个人群,请先删除人群再添加`, null, { mask: true }) } let crowdName = `钻展再营销人群_${new Date().getTime()}` let selectTagOptionSet = this.getSelectTagOptionSet(tag) let params = { selectTagOptionSet, crowdName, appId: 41, // validDate: '2099-12-31', businessType: 65, deliverAppId: 109 } let tagSelectView = Magix.Vframe.get('tagSelect') tagSelectView.invoke('saveLoading', [true]) try { let models = [{ name: 'api_crowd__post', params, isJson: true }] let [model] = await this.fetch(models) let crowdId = model.get('data.crowdId') tagSelectView.invoke('saveLoading', [false]) for (const crowd of crowds) { if (crowd.crowdId == crowdId) { return this.alert('提示', '添加失败,已存在相同规则的人群', () => { me.mountTagSelect() }, { mask: true }) } } this.alert('提示', '恭喜,人群添加成功', () => { //将所有选项names拼一起作为显示名称 let names = [] for (const group of tag.optionGroups) { for (const name of group.selected.names) { names.push(name) } } crowds.push({ crowdId, showName: `${names.join(',')}` }) me.updater.digest({ crowds }) this['@{owner-node}'].trigger({ type: 'crowdchange', crowds }) me.mountTagSelect() }, { mask: true }) } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) tagSelectView.invoke('saveLoading', [false]) // me.mountTagSelect() } }, mountTagSelect() { let tagSelectView = Magix.Vframe.get('tagSelect') const { tagId, limit, callback, saveLoading, tagSelected } = this.updater.get() tagSelectView.mountView('@./tag-select', { tagId, limit, callback, isZuanshiRemarket: true, saveLoading, tagSelected }) }, 'removeTag'(e) { const crowds = this.updater.get('crowds') crowds.splice(e.params.index, 1) this['@{owner-node}'].trigger({ type: 'crowdchange', crowds }) this.updater.digest({ crowds }) }, check() { const me = this return new Promise((resolve) => { const crowds = me.updater.get('crowds') // 此处返回promise,防止有接口提交校验等 resolve({ ok: !!crowds.length, // true or false,是否校验通过,false的时候不关闭按钮 data: crowds, // callback回调数据,可选 msg: '请至少添加一个人群' }) }) } })