import * as Sub from 'dmp-new/gallery/mx-table/sub' import * as View from 'dmp-new/view' import * as Helper from 'dmp-new/views/mixins/helper' import * as RemoveEmptySet from 'dmp-new/views/mixins/removeEmptySet' import Magix from 'magix' const EMPTY_SYMBOL = '--' // 聚类单品洞察生成的人群,加号打开的信息不同 const specialExpandBusinessTypes = [89, 92, 88] // 单品人群和直播人群修改是特殊的按钮 const ITEM_CROWD_BUSINESSTYPES = [89, 92, 101] // 直播人群的businessType const ZHIBO_CROWD_BUSINESSTYPES = [101] // 不能修改有效期的businessType - 序列化人群 const NO_MODIFY_VALIDDATE_BUSINESSTYPES = [51] // 排序指标 - 消耗 const SORT_KEY_CHARGE = 'charge' Magix.applyStyle('@./list.less') // const noExpandTypes = [41, 42, 46, 47] // 支持打开子标签列表的人群类型 // 1: 默认人群类型 // 14: 数据银行 // 30: 粉丝洞察创建的人群 // 74: 人群组合 // 47: 人群工厂 // const expandTypes = [1, 14, 30, 74] const businessTypePathMap = { 1: '/crowds/create', 41: '/crowds/keywords', // 关键词圈人 42: '/crowds-new/super-new/super-new-create', // 超级新用户 47: '/crowds/custom', // 自定义人群 48: '/crowds/polaris-crowd', // 新用户拓展 49: '/crowds/create?isRemarketing=true', // 再营销圈人 50: '/crowds/lbs/create', // lbs线下圈人 64: '/crowds/lbs/create-building', // lbs线下圈楼 74: '/crowds/custom?isCombine=true' // 自定义组合人群 } const tagMarketPath = '/crowds/create' // 标签市场圈人 const YOUKU_ADM_IDS = [32, 108] const sceneMap = { 0: '自定义场景', 1: '拉新场景', 2: '维旧场景', 3: '大促场景' } const DONGFENG_ID = 35 // 东风系统id const listTypeMap = [ { text: '我的营销人群', value: '1' }, { text: '合作方人群', value: '2' } ] const ZHIBO_TYPE_NAME = { 1: '行业直播智能扩展', 2: '店铺直播智能扩展' } const crowdVersionTypes = [ { text: '旧版人群', value: '2' } ] export default View.extend({ tmpl: '@list-table.html', mixins: [Sub, RemoveEmptySet], init(options) { this.options = options this.observeLocation([ 'currentPage', 'pageSize', 'crowdName', 'groupId', 'status', 'listType', 'crowdNew', 'sortType', 'sortKey', 'strExtraCrowdQueryConditions', 'providerNames', 'deliverAppId' ]) if (options.selectedCrowd) { this._selectedCrowd = options.selectedCrowd } this._crowdsMap = {} }, async render(timeStamp) { const me = this const { user, all } = this.updater.get() const loc = Magix.Router.parse() const { sortType, sortKey = SORT_KEY_CHARGE } = loc.params const groups = await this.getGroups() const status = [ { title: '全部状态', value: '' }, { title: '已同步', value: '2' }, { title: '准备中', value: '1' }, { title: '未同步', value: '0' } ] // 人群类型,1:我创建的人群,2:合作方人群 const listType = this.options.listType || loc.get('listType') || '1' this.updater.set({ sortKey, sortType, SORT_KEY_CHARGE, ZHIBO_TYPE_NAME, ZHIBO_CROWD_BUSINESSTYPES, ITEM_CROWD_BUSINESSTYPES, NO_MODIFY_VALIDDATE_BUSINESSTYPES, // isIsv: user.isIsv, timeStamp, crowdVersionTypes, EMPTY_SYMBOL, specialExpandBusinessTypes, listType, sceneMap, DONGFENG_ID, listTypeMap, isCustom: this.options.isCustom, selectedCrowdId: this._selectedCrowd && this._selectedCrowd.crowdId, isSelect: this.options.isSelect, // isXiaoer: user.isXiaoer, // isDmp: user.isDmp, // expandTypes, xiaoerOperType: all.xiaoerOperType, groups, status, YOUKU_ADM_IDS, computeBatchSyncChecked(params) { const { batchSyncAccounts } = me.updater.get() let { channel: { id } = { id: '' }, account: { targetId } = { targetId: '' } } = params targetId = targetId.toString() for (const item of batchSyncAccounts) { const { appId, ext: { agentId } = { agentId: '' }, targets } = item if (appId == id) { if (id == DONGFENG_ID && user.isXiaoer) { // 东风渠道特殊处理 // agentId 可能是string 或者 array if ( (typeof agentId === 'string' && agentId === targetId) || ($.isArray(agentId) && agentId.includes(targetId)) ) { return 'checked' } } else { // targets 可能是string 或者 array if ( (typeof targets === 'string' && targets === targetId) || ($.isArray(targets) && targets.includes(targetId)) ) { return 'checked' } } } } } }) const crowds = await this.getCrowds() this.addTagListToCrowds(crowds) const list = crowds.list const pager = crowds.pager const checked = this.updater.get('checked') || [] $.extend(true, pager, loc.params) me.updater.set({ list, pager, isShowMove: false, isShowBatchSync: false, batchSyncIndex: 0, batchSyncAccounts: [], // checked // 选中的人群 }) me.updater.digest({ isCheckAll: me.getIsCheckAll() }) // 地址栏标识要弹出一键投放浮层 if (loc.get('putInCrowdId')) { Magix.Router.to({ putInCrowdId: '' }) const crowd = await this.getCrowd(loc.get('putInCrowdId')) this.oneKeyPutIn(crowd) } }, // 从人群列表的selectTagOptionSet获取所有标签列表,打平附加到人群列表的allSet里 addTagListToCrowds(crowds) { for (const crowd of crowds.list) { crowd.allSet = this.getAllSet(crowd) } }, getAllSet(crowd) { const allSet = [] if (crowd.selectTagOptionSet) { Helper.recurSelectTagOptionSet( [crowd.selectTagOptionSet], (selects, set) => { allSet.push(set) } ) } return allSet }, // 线下数据圈人浮层 'createLbs'(e) { this.mxDialog( '@./create-lbs-modes', {}, { width: 400 } ) }, getIsCheckAll() { const list = this.updater.get('list') || [] const checked = this.updater.get('checked') || [] let isAll = true for (const item of list) { if (!checked.includes(item.crowdId)) { isAll = false break } } return isAll }, // 获取人群分组 async getGroups() { try { const models = [ { name: 'api_crowd_group_get' } ] const [model] = await this.fetch(models) const data = model.get('data.groups', []) data.unshift({ groupName: '全部营销人群', id: '' }) return data } catch (error) { this._alert('错误提示', error.msg) } }, // 获取单个人群信息 async getCrowd(crowdId) { try { const models = [ { name: 'api_crowd_$id_get', pathParams: [crowdId] } ] const [model] = await this.fetch(models) const data = model.get('data.crowd', {}) return data } catch (error) { this._alert('错误提示', error.msg || error.message || error) } }, // 获取人群列表 async getCrowds() { const loc = Magix.Router.parse() const params = $.extend(true, {}, loc.params) params.pageSize = params.pageSize || 20 const groups = this.updater.get('groups') || [] const status = this.updater.get('status') || [] const list = this.updater.get('list') || [] const pager = this.updater.get('pager') || {} const checked = this.updater.get('checked') || [] const user = this.updater.get('user') const listType = this.updater.get('listType') const { all } = this.updater.get() this.updater.digest({ checked, list, pager, groups, status, loading: true }) // 合作方人群listType=2 // 我的人群listType=1 params.listType = listType // LBS线下圈楼里选择人群,固定参数 if (this.updater.get('isSelect')) { params.idType = 1 // 筛选非LBS人群 params.status = 3 // 有效人群 } try { const models = [ { name: 'api_crowd__get', params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) // 有策略中心权限,并且人群是数据银行的,屏蔽渠道、删除、授权代投按钮等,显示跳转策略中心链接按钮 for (const item of data.list) { if ( (item.businessType == 14 || item.businessType == 34) && user.permissions.includes('STRATEGY_CENTER') ) { item.isCelue = true } // 121: 场景圈人 if (item.businessType === all.BUSINESS_TYPE_SCENE_CROWD) { item.isSceneCrowd = true } if (!item.apps || !item.apps.length) { item._appStatus = '0' // 未同步 } else { // 只要有一个渠道是同步中的(status=1||3),就认为该人群是同步中 // 全部渠道同步成功的,才同步成功 let isChannelSyncing = false if (item.apps && item.apps.length) { for (const app of item.apps) { if (app.status == 1 || app.status == 3) { isChannelSyncing = true break } } } item._appStatus = (isChannelSyncing && '1') || '2' } for (const key in item.extra) { const value = item.extra[key] if (/^\s*[{[]/.test(value)) { try { item.extra[key] = JSON.parse(value) } catch (error) { console.error('JSON.parse失败:', value, item) } } } // 缓存crowd信息 if (!this._crowdsMap[item.crowdId]) { this._crowdsMap[item.crowdId] = item } } this.updater.digest({ loading: false }) return data } catch (error) { this.updater.digest({ loading: false }) this._alert('错误提示', error.msg || error.message) } }, // 获取标签信息,附加到人群里 async getTag(crowd) { const tags = [] const allSet = this.getAllSet(crowd) for (const set of allSet) { if (set.selects[0] && !set.selects[0].tagInfo) { tags.push(set.selects[0]) } } if (tags.length) { try { const models = [] for (const tag of tags) { models.push({ name: 'api_tag_$id_get', pathParams: [tag.tagId] }) } const respModels = await this.fetch(models) respModels.forEach((item, i) => { const tag = item.get('data.tag') tags[i].tagInfo = tag }) } catch (error) { this._alert('错误提示', error.msg) } } }, // 修改标签选项 async 'editTag'(e) { const list = this.updater.get('list') const tag = e.params.tag const me = this const crowd = e.params.crowd this.mxDialog( '@./tag-select', { tagId: tag.selects[0] && tag.selects[0].tagId, tagSelected: tag, async callback(_tag) { for (const group of _tag.optionGroups) { for (const select of tag.selects) { if (group.id == select.optionGroupId) { select.names = group.selected.names.join(',') select.values = Array.isArray(group.selected.values) ? group.selected.values.join(',') : group.selected.values } } } me.updater.digest({ loading: true }) try { const models = [ { name: 'api_crowd_$id_put', pathParams: [crowd.crowdId], isJson: true, params: crowd } ] const [model] = await me.fetch(models) me.render() } catch (error) { me.updater.digest({ loading: false }) me.alert('错误提示', error.msg) } } }, { width: 800, top: 100 } ) }, // 搜索品牌 async 'showBrands'(e) { // 输入框输入关键词时触发show // 当前输入框输入的值 const keyword = e.keyword const instance = Magix.Vframe.get(this.id + '_brandSearch') instance.invoke('showLoading') const [model] = await this.fetch({ name: 'api_deliver_dongfeng_brand_get', params: { keyword } }) const list = model.get('data', []) this._brands = list instance.invoke('update', [list]) instance.invoke('hideLoading') }, // 选择品牌 'selectBrand'(e) { const channels = this.updater.get('channels') let dongfengChannel for (const channel of channels) { if (channel.id == DONGFENG_ID) { dongfengChannel = channel } } for (const brand of this._brands) { if (brand.id == e.selected) { dongfengChannel.accounts = [] for (const agent of brand.agentList) { dongfengChannel.accounts.push({ targetId: agent.id, nickname: agent.name }) } } } if (!e.selected) { delete dongfengChannel.selected delete dongfengChannel.selectedItem delete dongfengChannel.accounts } this.updater.digest({ channels }) }, // 移除标签 // async 'removeTag' (e) { // const mainSet = e.params.mainSet // const excludeSet = e.params.excludeSet // const orSet = e.params.orSet // const index = e.params.index // const crowd = e.params.crowd // const setType = e.params.setType // const me = this // this.confirm({ // title: '提示', // content: '确定要删除标签吗?', // mask: true, // async enterCallback () { // if (mainSet.length === 1 && excludeSet.length === 0 || excludeSet.length === 1 && mainSet.length === 0) { // return me.alert('提示', '至少保留一个标签') // } // switch (setType) { // case 1: // mainSet.splice(index, 1) // break // case 2: // orSet.splice(index, 1) // break // case 3: // excludeSet.splice(index, 1) // break // } // me.updater.digest({ // loading: true // }) // try { // const models = [{ // name: 'api_crowd_$id_put', // pathParams: [crowd.crowdId], // isJson: true, // params: crowd // }] // const [model] = await me.fetch(models) // me.render() // } catch (error) { // me.updater.digest({ // loading: false // }) // me.alert('错误提示', error.msg) // } // } // }) // }, async searchAccount(e) { const channel = e.params.channel const channels = this.updater.get('channels') if (!channel._nickname.trim()) { return } channel.selected = channel.selected || [] channel.accounts = [] this.updater.digest({ loadingAccounts: true, channels }) try { const models = [ { name: 'api_user_find_get', params: { nickname: channel._nickname, pageSize: 150 } } ] const [model] = await this.fetch(models) const users = model.get('data.users', []) for (const user of users) { user.targetId = user.memberId } channel.accounts = users this.updater.digest({ channels }) } catch (error) { this._alert('错误提示', error.msg || error.message) } this.updater.digest({ loadingAccounts: false }) }, 'searchAccount'(e) { if (e.keyCode === 13) { this.searchAccount(e) } }, 'searchAccount'(e) { this.searchAccount(e) }, async 'batchSync'(e) { const isShowBatchSync = this.updater.get('isShowBatchSync') const checked = this.updater.get('checked') if (!checked || !checked.length) { return this._alert('提示', '请至少选择一个人群') } if (!isShowBatchSync) { this.updater.digest({ isShowBatchSync: true, getChannelsLoading: true }) const channels = await this.getChannels() this.updater.digest({ channels, getChannelsLoading: false }) } else { this.updater.digest({ isShowBatchSync: false }) } }, async getChannels(e) { const { checked, user } = this.updater.get() const crowdId = checked.join(',') try { const models = [ { name: 'api_deliverapp_deliverapplist_get', params: { crowdId } } ] const [model] = await this.fetch(models) const list = model.get('data.list', []) if (!user.isXiaoer) { // 商家版 const _models = [] for (const item of list) { _models.push({ name: 'api_crowd_appUser__get', params: { crowdId, appId: item.id, memberId: user.loginUser.userId } }) } const respModels = await this.fetch(_models) respModels.forEach((model, i) => { list[i].accounts = model.get('data.list', []) }) } else { // 小二版 for (const channel of list) { if (YOUKU_ADM_IDS.includes(channel.id)) { channel.accounts = [ { nickname: '优酷ADM', targetId: 117810562 } ] } } } return list } catch (error) { this._alert('错误提示', error.msg) } }, 'moveTo'(e) { const isShowMove = this.updater.get('isShowMove') this.updater.digest({ isShowMove: !isShowMove }) }, 'cancelMove'(e) { this.updater.digest({ isShowMove: false }) }, 'batchSyncSwitch'(e) { const index = e.params.index this.updater.digest({ batchSyncIndex: index }) }, // api_crowd_multi_app_post async 'confirmMove'(e) { const moveToGroup = this.updater.get('moveToGroup') const checked = this.updater.get('checked') if (moveToGroup === undefined) { return this._alert('提示', '请选择一个人群分组') } if (!checked || !checked.length) { return this._alert('提示', '请至少选择一个人群') } try { const models = [ { name: 'api_crowd_group_$id_put', params: { crowdIds: checked.join(','), groupId: moveToGroup } } ] const [model] = await this.fetch(models) this.updater.digest({ isShowMove: false }) this.render() // let data = model.get('data') // return data } catch (error) { this._alert('错误提示', error.msg) } }, async 'confirmSync'(e) { const checked = this.updater.get('checked') const batchSyncAccounts = this.updater.get('batchSyncAccounts') if (!batchSyncAccounts.length) { return this._alert('提示', '请至少勾选一个渠道') } try { const models = [ { name: 'api_crowd_multi_app_post', params: { crowdIds: checked.join(','), apps: JSON.stringify(batchSyncAccounts) } } ] const [model] = await this.fetch(models) this.updater.digest({ isShowBatchSync: false }) this.render() // let data = model.get('data') // return data } catch (error) { this._alert('错误提示', error.msg) } }, 'cancelSync'(e) { this.updater.digest({ isShowBatchSync: false }) }, // setSelectedCrowd(crowdId) { const crowds = this.updater.get('list') for (const crowd of crowds) { if (crowd.crowdId == crowdId) { this._selectedCrowd = crowd break } } }, // 选择人群 'selectCrowd'(e) { this.setSelectedCrowd(this.updater.get('selectedCrowdId')) }, 'selectAccount'(e) { const { all, checked, batchSyncAccounts } = this.updater.get() const account = e.params.account const channel = e.params.channel if (e.target.checked) { // all.dongfengTargetId // 其他渠道 let match batchSyncAccounts.forEach((item, i) => { if (channel.id == item.appId) { match = true // 东风渠道特殊处理, if (channel.id == DONGFENG_ID) { item.ext = { brandId: channel.selectedItem.value, agentId: account.targetId.toString() } } else { const targets = item.targets.split(',') targets.push(account.targetId) item.targets = targets.join(',') } } }) if (!match) { const _account = { crowdId: checked.join(','), appId: channel.id, targets: '' } if (channel.id == DONGFENG_ID) { _account.targets = all.dongfengTargetId _account.ext = { brandId: channel.selectedItem.value, agentId: account.targetId.toString() } } else { _account.targets = [account.targetId].join(',') } batchSyncAccounts.push(_account) } } else { batchSyncAccounts.forEach((item, i) => { if (channel.id == item.appId) { const targets = item.targets.split(',') let matchIndex targets.forEach((target, _i) => { if (target == account.targetId) { matchIndex = _i } }) matchIndex !== undefined && targets.splice(matchIndex, 1) if (targets.length === 0) { batchSyncAccounts.splice(i, 1) } } }) } this.updater.digest({ batchSyncAccounts }) }, // 同步给小二版 async 'syncx2'(e) { const crowdIds = e.params.id try { const models = [ { name: 'api_crowd_sync_x2_post', params: { crowdIds } } ] const [model] = await this.fetch(models) this._alert('提示', '恭喜,人群授权成功', () => { this.render() }) } catch (error) { this._alert('错误提示', error.msg || error.message || error) } }, // 取消同步给小二版 async 'cancelSyncx2'(e) { const crowdIds = e.params.id try { const models = [ { name: 'api_crowd_sync_x2_delete', urlParams: { crowdIds } } ] const [model] = await this.fetch(models) this._alert('提示', '人群取消授权成功', () => { this.render() }) } catch (error) { this._alert('错误提示', error.msg || error.message || error) } }, 'selectOne'(e) { const checked = this.updater.get('checked') || [] if (e.target.checked) { checked.push(e.params.crowdId) } else { checked.forEach((item, i) => { if (item == e.params.crowdId) { checked.splice(i, 1) } }) } this.updater.set({ checked }) this.updater.digest({ isCheckAll: this.getIsCheckAll() }) }, 'selectAll'(e) { const list = this.updater.get('list') const checked = this.updater.get('checked') || [] if (e.target.checked) { for (const item of list) { if (!checked.includes(item.crowdId)) { checked.push(item.crowdId) } } } else { for (const item of list) { const existIndex = checked.indexOf(item.crowdId) if (existIndex > -1) { checked.splice(existIndex, 1) } } } this.updater.set({ checked }) this.updater.digest({ isCheckAll: this.getIsCheckAll() }) }, 'crowdManage'(e) { const me = this const d = this.mxDialog( '@./crowd-manage', { id: e.params.id, apps: e.params.apps }, { width: 350, top: 100 } ) d.afterClose(() => { me.render() }) }, 'batchManage'(e) { const showSelect = this.updater.get('showSelect') this.updater.digest({ showSelect: !showSelect }) }, // 'addCrowd'(e) { this.options.crowdCallback({ crowdId: e.params.crowdId, crowdName: e.params.crowdName }) }, async 'showSub'(e) { const list = this.updater.get('list') const crowd = e.params.crowd await this.getTag(crowd) this.updater.digest({ list }) }, copySceneCrowd(crowdId) { Magix.Router.to('/crowds-new/scene-crowds/create', { crowdId, isCopy: 'true', stepIndex: 2 }) }, async 'copy'(e) { const { all } = this.updater.get() const { crowd } = e.params const { businessType, crowdId, extra } = crowd if (crowd.isSceneCrowd) { return this.copySceneCrowd(crowdId) } // 74是人群组合工厂,需要判断下是否超出可创建人群的上限 const combineCrowdBusinessType = 74 if (businessType == combineCrowdBusinessType) { const models = [ { name: 'api_crowd__get', params: { pageSize: 30, businessType: combineCrowdBusinessType } } ] const [model] = await this.fetch(models) const crowds = model.get('data.list', []) if (crowds.length >= all.combineCrowdsLimit) { return this.mxDialog( '@./combine-crowds-popup', { isCopy: true, id: crowdId, crowds }, { top: 100, width: 600 } ) } } let path = businessTypePathMap[businessType] || tagMarketPath if (extra && extra.DMP_PLUS == '1') { path = '/crowds-new/create' } // 小二版里的圈楼人群有自己的修改页面 if (businessType == 64) { path = businessTypePathMap[businessType] } Magix.Router.to(path, { id: crowdId, isCopy: true }) }, 'channel'(e) { const me = this const d = this.mxDialog( '@./channels', { id: e.params.id, apps: e.params.apps, coverage: e.params.coverage }, { width: 920, top: 100 } ) d.afterClose(() => { me.render() }) }, // 批量授权小二版人群 'batchSyncx2'(e) { const checked = this.updater.get('checked') const me = this if (!checked || !checked.length) { return this._alert('提示', '请至少选择一个人群') } this._confirm({ title: '提示', mask: true, content: '确定要批量授权这些人群吗?', async enterCallback() { try { const models = [ { name: 'api_crowd_sync_x2_post', params: { crowdIds: checked.join(',') } } ] await me.fetch(models) me.render() } catch (error) { me.alert('错误提示', error.msg) } } }) }, 'batchRemove'(e) { const { checked } = this.updater.get() if (!checked || !checked.length) { return this._alert('提示', '请至少选择一个人群') } this._confirm({ title: '提示', mask: true, content: '确定要批量删除吗?', enterCallback: async () => { try { const models = [ { name: 'api_crowd_crowds__delete', pathParams: [checked.join(',')] } ] await this.fetch(models) this.updater.digest({ checked: [] }) this.render(new Date().getTime()) } catch (error) { this._alert('错误提示', error.msg) } } }) }, // 轮询查询人群是否dump完毕,dump完毕的人群才能计算相似度 async getStatusPolling(crowdId) { // const me = this return new Promise(async resolve => { async function polling() { try { const params = { crowdId, bizId: 2 } const models = [ { name: 'api_crowd_accelerate_task_post', params, isJson: true } ] const [model] = await this.fetch(models) const status = model.get('data') // status=1,数据还在准备中 // status=2,数据准备完毕 if (this.isSimilarConfirm) { resolve(true) } else if (status == 2) { resolve(undefined) } else { setTimeout(async () => { await polling() }, 1000) } } catch (error) { this._alert('错误提示', error.msg) resolve(false) } } await polling.bind(this)() }) }, // 计算两个人群的相似度 // async computeSimilar (checked) { // try { // const models = [{ // name: 'api_analysis_crowd_similarity_post', // params: { // crowdIds: checked // }, // isJson: true // }] // const [model] = await this.fetch(models) // const similarity = model.get('data.similarity') // return similarity // } catch (error) { // this._alert('错误提示', error.msg || error.message) // } // }, // // 查看两个人群的相似度 // async 'similar' (e) { // const me = this // const { Accounting, checked } = this.updater.get() // if (checked.length != 2) { // return // } // me.isSimilarConfirm = false // const dialog = this._alert('提示', '人群相似度计算中,请稍候...(大约耗时2分钟)', () => { // me.isSimilarConfirm = true // }) // const [isConfirm1, isConfirm2] = await Promise.all([this.getStatusPolling(checked[0]), this.getStatusPolling(checked[1])]) // if (isConfirm1 === false || isConfirm2 === false) { // dialog.close() // } else if (isConfirm1 === undefined && isConfirm2 === undefined) { // const similarCount = await this.computeSimilar(checked) // dialog.close() // dialog.afterClose(() => { // me._alert('提示', `人群相似度计算完毕,相似度为${Accounting.formatNumber(similarCount * 100, 2)}%`) // }) // } // }, // 前往修改场景圈人页面 editSceneCrowd(crowdId) { Magix.Router.to('/crowds-new/scene-crowds/create', { crowdId, stepIndex: 2 }) }, async 'edit'(e) { const { user } = this.updater.get() const { crowd } = e.params const { businessType, crowdId, apps, extra } = crowd const syncApps = [] if (crowd.isSceneCrowd) { return this.editSceneCrowd(crowdId) } // 用户降级导致原逻辑圈人的人群不可用 if ( !user.permissions.includes('CROWD_COMBINE') && crowd.extra.tagCombination ) { return this._alert( '提示', '掌柜您好,由于您达摩盘权益等级降级,导致部分原权益等级功能暂时无法使用,请再接再厉~' ) } for (const app of apps) { if (app.status == 1 || app.status == 2) { syncApps.push(app) } } if (syncApps.length) { this._confirm({ mask: true, title: '营销人群修改', content: `该营销人群已被 ${syncApps .map(app => { return app.appName }) .join( '、' )} 这些渠道应用,修改后会对投放渠道造成影响!您确认要修改该营销人群?`, enterCallback() { goto() } }) } else { goto() } function goto() { let path = businessTypePathMap[businessType] || tagMarketPath // 新版圈人 if (crowd.crowdNew == '1' || extra.DMP_PLUS == '1') { path = '/crowds-new/create' } // 小二版里的圈楼人群有自己的修改页面 if (businessType == 64) { path = businessTypePathMap[businessType] } const routeParams = { id: crowdId } Magix.Router.to(path, routeParams) } }, // 根据接口判断人群能否修改 async crowdCanEdit(crowdId) { try { const models = [ { name: 'api_crowd_$id_edit_check_get', pathParams: [crowdId, 'edit', 'check'] } ] const [model] = await this.fetch(models) return true } catch (error) { this._alert('错误提示', error.msg || error.message || error) return false } }, // 添加追踪 async 'trace'(e) { try { const all = this.updater.get('all') const user = this.updater.get('user') const params = { crowdIds: e.params.id } // 1:商家版新潜老,2:小二版aipl if (user.loginUser.operType == all.xiaoerOperType) { params.trackType = '2' } const models = [ { name: 'api_crowd_track_put', params } ] await this.fetch(models) this._alert('提示', '添加人群追踪成功,请至人群追踪列表查看', () => { this.render() }) } catch (error) { this._alert('错误提示', error.msg || error.message) } }, // 批量追踪 'batchTrace'(e) { const checked = this.updater.get('checked') const me = this if (!checked || !checked.length) { return this._alert('提示', '请至少选择一个人群') } const all = this.updater.get('all') const user = this.updater.get('user') const params = { crowdIds: checked.join(',') } // 1:商家版新潜老,2:小二版aipl if (user.loginUser.operType == all.xiaoerOperType) { params.trackType = '2' } this._confirm({ title: '提示', mask: true, content: '确定要批量追踪这些人群吗?', async enterCallback() { try { const models = [ { name: 'api_crowd_track_put', params } ] await me.fetch(models) me.render() } catch (error) { me._alert('错误提示', error.msg) } } }) }, 'deleted'(e) { const id = e.params.id const me = this const apps = e.params.apps const syncApps = [] for (const app of apps) { if (app.status == 1 || app.status == 2) { syncApps.push(app) } } if (syncApps.length) { this._confirm({ title: '营销人群删除', content: `该营销人群已被 ${syncApps .map(app => { return app.appName }) .join( ',' )} 这些渠道应用,删除后会对投放渠道造成影响!您确认要删除该营销人群?`, enterCallback() { goto() } }) } else { this._confirm({ title: '营销人群删除', content: `确定要删除 『${e.params.crowdName}』 吗?`, enterCallback() { goto() } }) } async function goto() { try { const models = [ { name: 'api_crowd_$id_delete', pathParams: [id] } ] const [model] = await me.fetch(models) const { checked } = me.updater.get() checked.find((item, i) => { if (item === id) { checked.splice(i, 1) return true } }) me.render(new Date().getTime()) } catch (error) { me._alert('不可删除', error.msg) } } }, 'sort'(e) { let { sortType, sortKey } = this.updater.get() const { key } = e.params if (sortKey !== key) { sortType = '2' } else if (!sortType) { sortType = '2' } else if (sortType === '2') { sortType = '1' } else { sortType = '' sortKey = '' } Magix.Router.to({ sortType, sortKey }) }, 'search'(e) { if (e.keyCode === 13) { Magix.Router.to({ crowdName: e.target.value.trim(), currentPage: 1 }) } }, 'changeStatus'(e) { Magix.Router.to({ status: e.value, currentPage: 1 }) }, 'changeVersion'(e) { Magix.Router.to({ crowdNew: e.value, currentPage: 1 }) }, 'changeGroup'(e) { Magix.Router.to({ groupId: e.value, currentPage: 1 }) }, 'changeListType'(e) { Magix.Router.to({ listType: e.value, currentPage: 1 }) }, 'changePager'(e) { Magix.Router.to({ pageSize: e.size, currentPage: e.page }) }, 'showCreateCrowds'(e) { const viewPath = 'dmp-new/views/partials/create' const viewOpitons = {} const dialogOptions = { width: 1100, mask: true, top: 100 } this.mxDialog(viewPath, viewOpitons, dialogOptions) }, // 展示单品人群的迭代状态 'showItemUpdate'(e) { const viewPath = '@./scenes/crowd-update-status' const viewOptions = { crowdId: e.params.crowdId } const dialogOptions = { width: 840, header: { title: '人群迭代状态' }, footer: { cancel: false, enter: false } } this.mxModal(viewPath, viewOptions, dialogOptions) }, // 修改单品洞察人群 'modifyItemCrowd'(e) { const { crowd, isModifyValidate } = e.params const viewPath = '@./scenes/modify' const viewOptions = { crowd, isModifyValidate, callback: () => { this.render() } } const dialogOptions = { top: 100 } this.mxDialog(viewPath, viewOptions, dialogOptions) }, // abtest 老报表 'showReportsOld'(e) { const { id, crowdName } = e.params const viewPath = '@../reports/crowds/detail' const viewOptions = { id, crowdName, noChannels: true } const dialogOptions = { width: 1300, header: { title: `人群报表:${crowdName}` }, footer: { cancel: false, enterText: '关闭' } } this.mxModal(viewPath, viewOptions, dialogOptions) }, // abtest 新报表 async 'showReports'(e) { const { item: crowd } = e.params const { user } = this.updater.get() if ( crowd.charge === 0 && user.permissions.includes('DMP_FUNCTION_INSIGHT_PROFILE_ANALYSIS') ) { this.showReportsDiagnose(e) } else { this.showReports(e) } }, // 没有数据前显示老报表 async showReports(e) { const { id, crowdName, item } = e.params const { list } = this.updater.get() const viewPath = '@../reports/crowds/detail-new' const viewOptions = { id, crowdName, noChannels: true } const dialogOptions = { width: 1300, header: { title: `人群报表:${crowdName}` }, footer: { cancel: false, enterText: '关闭' } } this.mxModal(viewPath, viewOptions, dialogOptions) if ( item.extra.isClickOptimization === 'false' && (await this.reportClick(id)) ) { item.extra.isClickOptimization = 'true' this.updater.digest({ list }) } }, async getCates() { const cates = await Helper.getCates(this) return cates.filter(cate => cate.pValue === '') }, // 有数据的显示投前诊断页面 async showReportsDiagnose(e) { const { id, crowdName, item } = e.params const { list, all } = this.updater.get() // 先 dump 下人群 const isConfirm = await this.getCrowdDumpStatus(id) if (isConfirm !== undefined) { return } const crowd = await this.getCrowd(id) const cates = await this.getCates() const cateId = await Helper.getMainCate(this, cates) const delivers = await Helper.getChannels(this) // 小二推送的人群没有 crowd.selectTagOptionSet,只要留crowdId const selectTagOptionSet = $.extend(true, {}, all.selectTagOptionSet_412) selectTagOptionSet.id = id selectTagOptionSet.name = crowdName const analysisObj = { operator: 1, selectTagOptionSet: [ crowd.selectTagOptionSet || selectTagOptionSet, { selectTagOptionSet: [] } ] } const viewPath = 'dmp-new/views/pages/insight-new/before-putin-diagnose/index' const viewOptions = { delivers, cates, crowdId: id, crowdName, noChannels: true, crowd, config: { analysisObj, cateIdPpcCtr: cateId, deliverType: delivers[0].value } } const dialogOptions = { width: 1300, header: { title: `人群报表:${crowdName}` }, footer: { cancel: false, enter: false } } this.mxModal(viewPath, viewOptions, dialogOptions) if ( item.extra.isClickOptimization === 'false' && (await this.reportClick(id)) ) { item.extra.isClickOptimization = 'true' this.updater.digest({ list }) } }, async reportClick(crowdId) { try { const params = { dataKey: 'isClickOptimization', dataValue: 'true', crowdId } const models = [ { name: 'api_crowdExtra_post', isJson: true, params } ] await this.fetch(models) return true } catch (error) { console.error(error) return false } }, // 小二版里的同步达摩盘按钮 'syncDmp'(e) { const viewPath = '@./sync-dmp' const viewOptions = { crowd: e.params.crowd, callback: () => { this.render() } } const dialogOptions = { top: 100, width: 700 } this.mxDialog(viewPath, viewOptions, dialogOptions) }, // 小二版人群分享 'crowdShare'(e) { const viewPath = '@./crowd-share' const viewOptions = { crowdsMap: this._crowdsMap, crowd: e.params.crowd, callback: () => { this.render() } } const dialogOptions = { top: 100, width: 700 } this.mxDialog(viewPath, viewOptions, dialogOptions) }, // 批量人群分享 'crowdShareBatch'(e) { const { checked } = this.updater.get() const batchCrowds = checked.filter(crowdId => { const currCrowd = this._crowdsMap[crowdId] return currCrowd.extra.isEnableShare === 'true' }) const noBatchCrowds = checked.filter(crowdId => { const currCrowd = this._crowdsMap[crowdId] return currCrowd.extra.isEnableShare !== 'true' }) if (!checked.length) { return this._alert('提示', '请至少选择一个人群') } if (!batchCrowds.length) { return this._alert('提示', '您选择的人群无法分享,请重新选择') } const viewPath = '@./crowd-share' const viewOptions = { crowdsMap: this._crowdsMap, batchCrowds, noBatchCrowds, callback: () => { this.render() } } const dialogOptions = { top: 100, width: 700 } this.mxDialog(viewPath, viewOptions, dialogOptions) }, // 打开筛选条件浮层 'filter'(e) { const loc = Magix.Router.parse() const { strExtraCrowdQueryConditions, providerNames, deliverAppId } = loc.params const { listType } = this.updater.get() const viewName = '@./filter-settings' const viewOptions = { listType, strExtraCrowdQueryConditions, providerNames, deliverAppId, callback: filters => { const { extraCrowdQueryConditions, providerNames: _providerNames, deliverAppId } = filters const routerParams = { strExtraCrowdQueryConditions: (extraCrowdQueryConditions && extraCrowdQueryConditions.join(',')) || extraCrowdQueryConditions, providerNames: (_providerNames && _providerNames.join(',')) || _providerNames, deliverAppId, currentPage: 1 } Magix.Router.to(routerParams) } } const dialogOptions = { width: 560, top: 100 } this.mxDialog(viewName, viewOptions, dialogOptions) }, // 导出odps 'exportOdps'(e) { const { crowdId, crowdName } = e.params this.mxDialog( '@../../../xsite-proxy', { xview: 'dmp-xiaoer/views/pages/crowds-new/popup/export-odps', params: { crowdId, crowdName } }, { width: 500 } ) // d.afterClose(() => { // this.render() // }) }, // 开启智能迭代 'startIterate'(e) { const { crowd } = e.params const viewPath = '@./ai-iteration/iteration-direction' const viewOptions = { crowd, callback: () => { this.render() } } const dialogOptions = { width: 660, top: 100 } this.mxDialog(viewPath, viewOptions, dialogOptions) // this._confirm({ // top: 100, // title: '提示', // content: '您确定开启智能迭代吗?(智能迭代后,您创建的人群将被作为种子人群,在该人群获得1000展现量后,系统会通过算法模型引入优质流量,对人群进行持续调整,以提升人群的转换效果。您可在“智能迭代人群”列表中查看人群迭代后的效果详情。)', // enterCallback: async () => { // try { // const { crowd } = e.params // const models = [{ // name: 'api_crowd_iter_$id_start_post', // pathParams: [crowd.crowdId, 'start'] // }] // await this.fetch(models) // this.render() // } catch (error) { // this._alert('错误提示', error.msg || error.message || error) // } // } // }) }, // 一键投放 'oneKeyPutIn'(e) { const { crowd } = e.params this.oneKeyPutIn(crowd) }, // 添加DEEPLINK细分市场分析 'addDeeplinkSubdivide'(e) { const { crowdId } = e.params this._confirm( { title: '添加DEEPLINK细分市场', content: '您确定将该人群加入细分市场分析资产渗透吗吗?(添加当天开始累计市场资产,持续观测市场渗透机会,最长累计90天)', enterCallback: async () => { try { await this.addDeeplinkSubdivide(crowdId) this.render() } catch (error) { this._alert('提示', error.msg || error.message, () => { Magix.Router.to('/deeplink/subdivide/index', { showMoreCrowds: true }) }) } } }, { type: 'highlight' } ) }, async addDeeplinkSubdivide(crowdIds) { const params = { crowdIds } const models = [ { name: 'api_asset_deeplink_market_crowd_post', isJson: true, params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data }, oneKeyPutIn(crowd) { const viewPath = '@./one-key-put-in/index' const viewOptions = { crowd, callback: () => { this.render() } } const dialogOptions = { spm: `gostr=/alimama.99.dmp;locaid=donekeyputin_${crowd.crowdId}`, width: 1100, header: { title: '一键投放', tip: `当前人群:${crowd.crowdName}` } } this.mxModal(viewPath, viewOptions, dialogOptions) }, check() { const me = this return new Promise(resolve => { const crowdId = me.updater.get('selectedCrowdId') const ok = !!crowdId resolve({ ok, // true or false,是否校验通过,false的时候不关闭按钮 msg: '请选择一个人群', data: { crowdId, crowdName: this._selectedCrowd && this._selectedCrowd.crowdName } }) }) }, 'dialogCreateCrowd'(e) { const viewPath = 'dmp-new/xsite-proxy' const selectTagOptionSet = { operator: 4, selectTagOptionSet: [ { operator: 1, selects: [], selectTagOptionSet: [ { operator: 1, selects: [], selectTagOptionSet: [ { selects: [ { tagName: '教育程度', tagId: 711, optionGroupId: 12162, values: '12315', names: '呵呵' }, { tagName: '教育程度', tagId: 711, optionGroupId: 12163, values: '123915,105525', names: '赖涛,傅艳' }, { tagName: '教育程度', tagId: 711, optionGroupId: 12164, values: '2', names: '本科生' }, { tagName: '教育程度', tagId: 711, optionGroupId: 12167, values: '123915', names: '赖涛' }, { tagName: '教育程度', tagId: 711, optionGroupId: 12168, values: '123915', names: '赖涛' }, { tagName: '教育程度', tagId: 711, optionGroupId: 12165, values: '30', names: '最近30天' }, { tagName: '教育程度', tagId: 711, optionGroupId: 12166, values: '1', names: '男' } ], tagFrom: null }, { selects: [ { tagId: 147278, optionGroupId: 30287, values: 1356374, names: '华璋测试_田平' } ], tagFrom: null }, { selects: [ { tagId: 174245, optionGroupId: 53502, values: '1000123', names: 'DEEPLINK人群' } ], tagFrom: null } ] }, { operator: 2, selects: [], selectTagOptionSet: [] } ] }, { operator: 2, selects: [], selectTagOptionSet: [] } ], selects: [], _isTagRecommend: false } const viewOptions = { xview: 'dmp-new/views/pages/crowds-new/create', params: { // crowdId: 123123, selectTagOptionSet: JSON.stringify(selectTagOptionSet), createCallback: crowd => { debugger } } } const dialogOptions = { footer: { enter: false, cancel: false }, width: $(window).width() } this.mxModal(viewPath, viewOptions, dialogOptions) } })