import Magix from 'magix' import * as View from '../../../view' import Mixins from './mixins' Magix.applyStyle('@./custom-crowd.less') const EMPTY_COVERAGE = '--' const HINT_MAP = { 0: { text: '过窄', color: 'error' }, 1: { text: '适中', color: 'pass' }, 2: { text: '宽泛', color: 'warn' } } export default View.extend({ mixins: [Mixins], tmpl: '@custom-crowd.html', init(options) { options.isEdit = options.crowdId && !options.isCopy this.options = options const me = this function adjustScroll() { const scrollHeight = me.computeHeight() me.updater.digest({ scrollHeight }) } window.addEventListener('resize', adjustScroll) this.on('destroy', e => { window.removeEventListener('resize', adjustScroll) }) this.on('domready', e => { const scrollHeight = me.computeHeight() me.updater.digest({ scrollHeight }) }) }, async render() { // bp的bizCode ,deliverId什么的配置在alp上 const [, dictConfig] = await Promise.all([ this.getSourceList(), this.getDictConfig() ]) const { crowdLimit, crowdLimitMore } = await this.getCrowdLimitFromAlp() const { Moment, all } = this.updater.get() const { isEdit, isCopy, bizCode, crowdId, crowdIds = [], onlyDmpSource, maxCount: _maxCount, hotCrowdsParams = {} // 平台精选的入参 } = this.options // 平台精选的bizCode沿用基础圈人的 Object.assign(hotCrowdsParams, { bizCode }) // 当前渠道app const currentApp = this.getCodeByWebBizCode(bizCode) // 权限文档:https://yuque.antfin-inc.com/docs/share/7e9158c1-a534-49cb-b325-dd63b57ba471?# const permissions = await this.getPermissions() this.updater.set({ dictConfig, hotCrowdsParams, permissions }) // 获取可用的tab const { tabs, tabObj } = await this.getTabs() const selectedTab = tabs[0]?.value // 人群放大 const scaleTypes = [ { text: '默认', value: 1, disable: false, tips: '' }, { text: '智能扩展', value: 2, disable: true, tips: '人群规模量级在500W以下可以支持【智能扩展】,系统在全网为您智能扩展与种子人群相似的人群,全新算法拉新利器,智能获取优质扩展流量,助力商家提升拉新人群圈选效率!' } ] let scaleType = scaleTypes[0].value // 默认无放大 // let showExpand = false //是否扩量 let lookalikeMultiple = 3 // 默认扩量倍数 let crowd if (isEdit || isCopy) { crowd = await this.getCrowd(crowdId) // 当前appId与人群appId不一致时,不可编辑 const currentAppId = currentApp.value && currentApp.value.replace(/[\[\]]/g, '') // businessType 87 为营销沉淀人群创建的(人群模板),不可编辑 if (currentAppId != crowd.dmpAppId || crowd.businessType == 87) { return this.updater.digest({ noEdit: true }) } if (isCopy) { crowd.crowdName += '_副本' } // 16代表有放大 if (crowd.lookalikeAlgoType == 16) { lookalikeMultiple = crowd.lookalikeMultiple // showExpand = true scaleTypes[1].disable = false scaleType = 2 } } // 类目信息 const { shopMainCate = [], shopId } = await this.getExtendInfo() const cates = shopMainCate const crowdName = (crowd && crowd.crowdName) || `自定义人群${Moment().format('MMDDHHmmss')}` // 权限控制是否默认创建为常用人群,并且不可取消 const commonCrowdKey = 'dmpCrowdFixed' // 权限Key const isCommonCrowd = permissions.includes(commonCrowdKey) // let relateRecommendIds = [] // 埋点需要的关联推荐标签的id let combineRecommendIds = [] // 埋点需要的组合推荐的id if (crowd && crowd.extra) { relateRecommendIds = (crowd.extra.relateRecommendIds && crowd.extra.relateRecommendIds.split(',')) || relateRecommendIds combineRecommendIds = (crowd.extra.combineRecommendIds && crowd.extra.combineRecommendIds.split(',')) || combineRecommendIds } // 从alp配置可以添加的人群限制个数,包含普通的限制 和 比较多的限制 // alp接口:https://alp.alibaba-inc.com/index-plus/page/studio?id=3834132 const maxCount = _maxCount || (permissions.includes('dmpCrowdNum16') ? crowdLimitMore : crowdLimit) // this.updater.digest({ tabObj, onlyDmpSource, HINT_MAP, relateRecommendIds, combineRecommendIds, commonCrowdKey, isCommonCrowd, shopId, scaleTypes, scaleType, industryCompetitionPredicts: [], // 人群竞争分析 selectedCate: cates[0] && cates[0].cateId, cates, crowdsCount: (crowdIds && crowdIds.length) || 0, maxCount, currentApp, bizCode, EMPTY_COVERAGE, crowdName, crowd, crowdIds, isEdit, isCopy, tabs, selectedTab, dailyReachUV: EMPTY_COVERAGE, coverage: EMPTY_COVERAGE, // 覆盖数 ctrIndex: EMPTY_COVERAGE, // 类目CTR ppcIndex: EMPTY_COVERAGE, // 类目PPC // showExpand, lookalikeMultiple, permissions }) // setTimeout(e => { const scrollHeight = this.computeHeight() this.updater.digest({ scrollHeight }) }, 100) }, // 获取可用的tab async getTabs() { const { isEdit, isCopy, noTabs = [], // 指定不要的tab hasTabs = [] // 指定要的tab, hasTabs优先级大于 noTabs } = this.options const { permissions, all } = this.updater.get() // const tabObj = { tab1: { value: 1, text: '新建人群', tips: '标签组合方式:标签内多个选项之间为并集,标签之间为交集', path: '@./create-crowd' }, tab2: { value: 2, text: '已保存人群', tips: '新建人群已保存的人群,以及在达摩盘平台创建并同步至本业务线的人群。支持编辑、复制和移除', path: '@./common-crowds' }, tab3: { value: 3, text: '营销沉淀人群', path: '@./subside-crowds' }, tab4: { value: 4, text: '平台精选', path: '@./hot-crowds/crowds' } } const tabMarks = await this.getTabMarks() const festivelImgTag = `${all.festivalText}` for (let i = 1; i < 4; i++) { if (tabMarks[i] === 'festival') { tabObj[`tab${i}`].tagContent = festivelImgTag } else { tabObj[`tab${i}`].tag = tabMarks[i] } } // hasTabs 优先级大于 noTabs const tabs = [] // 平台精选 if (hasTabs.length) { if (hasTabs.includes(tabObj.tab4.value) && !isEdit && !isCopy) { tabs.push(tabObj.tab4) } } // 新建人群权限 if (hasTabs.length) { if (hasTabs.includes(tabObj.tab1.value)) { tabs.push(tabObj.tab1) } } else if ( permissions.includes('dmpAddCrowd') && !noTabs.includes(tabObj.tab1.value) ) { tabs.push(tabObj.tab1) } // 已保存人群权限 if (hasTabs.length) { if (hasTabs.includes(tabObj.tab2.value) && !isEdit && !isCopy) { tabs.push(tabObj.tab2) } } else if ( permissions.includes('dmpExistCrowd') && !noTabs.includes(tabObj.tab2.value) && !isEdit && !isCopy ) { tabs.push(tabObj.tab2) } // 营销人群沉淀权限 if (hasTabs.length) { if (hasTabs.includes(tabObj.tab3.value) && !isEdit && !isCopy) { tabs.push(tabObj.tab3) } } else if ( permissions.includes('dmpCrowdMarket') && !noTabs.includes(tabObj.tab3.value) && !isEdit && !isCopy ) { tabs.push(tabObj.tab3) } return { tabs, tabObj } }, // 从alp配置可以添加的人群限制个数,包含普通的限制 和 比较多的限制 // alp接口:https://alp.alibaba-inc.com/index-plus/page/studio?id=3834132 async getCrowdLimitFromAlp() { try { const models = [ { name: 'alp_dmp_json_20210722_200809_73_get' } ] const [model] = await this.fetch(models) const { crowdLimit, crowdLimitMore } = model.get('data', {}) return { crowdLimit: parseInt(crowdLimit, 10), crowdLimitMore: parseInt(crowdLimitMore, 10) } } catch (error) { this.alert('错误提示', error.msg || error.message || error) } }, async getTabMarks() { try { const models = [ { name: 'alp_dmp_bp_crowd_tab_mark_get' } ] const [model] = await this.fetch(models) const tabMarks = model.get('data.tabMarks', {}) return tabMarks } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, // bp 的配置 async getDictConfig() { try { const { bizCode } = this.options const params = { bizCode } const models = [ { name: 'dmp-advgateway_api_dmp_dict_config_get', params } ] const [model] = await this.fetch(models) const data = model.get('data.result', {}) return data } catch (error) { console.error(error) } }, // bp的bizCode ,deliverId什么的配置在alp上 async getSourceList() { try { const models = [ { name: 'alp_dmp_bp_crowd_source_list_get' } ] const [model] = await this.fetch(models) const sourceList = model.get('data.sourceList', []) // 万相台特殊处理,新增个151 sourceList.push({ value: '[151]' }) // sourceList 第一条的values是其他所有values的汇总 if (sourceList.length > 1) { sourceList[0].value = `[${sourceList .slice(1) .map(item => /\[(.+)\]/.exec(item.value)[1]) .join(',')}]` } // Magix.config({ dmpBpCrowdSourceList: sourceList }) return sourceList } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, async getExtendInfo() { try { const { bizCode } = this.options const params = { bizCode, queryShopMainCate: '1', queryShopId: '1' } const models = [ { name: 'appone_api_dmp_tool_extradata_get', params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, // 计算人群竞争分析模块的可用高度,用来出滚动条 computeHeight() { const am = $(`#${this.id}analysisModule`) // let { selectedTab } = this.updater.get() if (!am.length) { return } const winHeight = $(window).height() const top = am.offset().top - $(window).scrollTop() return winHeight - top - 62 - 20 }, // 获取bp白名单权限,达摩盘权限 async getPermissions() { try { const { bizCode } = this.options const models = [ { name: 'appone_api_dmp_permission_get', params: { bizCode } } ] const [model] = await this.fetch(models) const data = model.get('data', []) // 缓存全局 Magix.config({ bpCustomCrowdPermissions: data }) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, // setCrowdsCount(crowdsCount) { this.updater.digest({ crowdsCount }) }, // 获取人群详情 async getCrowd(crowdId) { const { bizCode } = this.options try { const models = [ { name: 'dmp-advgateway_api_dmp_crowd_get_get', params: { bizCode, crowdId } } ] const [model] = await this.fetch(models) const crowd = model.get('data.result', {}) return crowd } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, // 获取人群覆盖数 async getCoverage() { let { viewId, selectedTab, scaleType, scaleTypes, permissions } = this.updater.get() const crowdVframe = await this.waitVframeCreated( Magix.Vframe.get(`${viewId}_crowdView_${selectedTab}`) ) const { selectTagOptionSetDTO } = crowdVframe.$v.updater.get() const { bizCode } = this.options // 一个选择的标签都没有 if (!selectTagOptionSetDTO || !selectTagOptionSetDTO._selectedTagCounts) { this.updater.digest({ coverage: EMPTY_COVERAGE, dashboard: null }) } else { // 变化标签的选项 try { const params = { bizCode, selectTagOptionSetDTO } const models = [ { name: 'dmp-advgateway_api_dmp_analysis_coverage_post', // isJson: true, params } ] this.updater.digest({ coverageLoading: true }) const [model] = await this.fetch(models) const { coverage, level, hintDataSecurity, hintDataSecurityInfo, lookalikeSuggestion, adPredictOn } = model.get('data.result', {}) // if (lookalikeSuggestion) { // 有放大 // selectedTab不为2时(已保存人群),才有放大功能 // if (permissions.includes('dmpCrowdExt')) { scaleTypes[1].disable = false // } } else { // 无放大 scaleTypes[1].disable = true if (scaleType == 2) { scaleType = 1 } } this.updater.digest({ adPredictOn, scaleTypes, scaleType, // coverageOrigin: coverage, coverage, dashboard: level, hintDataSecurity, hintDataSecurityInfo, coverageLoading: false }) } catch (error) { this.updater.digest({ coverageLoading: false, dashboard: null, coverage: EMPTY_COVERAGE }) this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } this.getAdPredict(1) } }, // 获取放大人群覆盖数 async getCoverageAdjust() { const { viewId, selectedTab, scaleType, scaleTypes, lookalikeMultiple } = this.updater.get() const crowdVframe = await this.waitVframeCreated( Magix.Vframe.get(`${viewId}_crowdView_${selectedTab}`) ) const { selectTagOptionSetDTO } = crowdVframe.$v.updater.get() const { bizCode } = this.options // 一个选择的标签都没有 if (!selectTagOptionSetDTO || !selectTagOptionSetDTO._selectedTagCounts) { return this.updater.digest({ coverageAdjust: EMPTY_COVERAGE, dashboardAdjust: null }) } else { // 变化标签的选项 try { const params = { bizCode, selectTagOptionSetDTO } if (scaleType == 2) { // 有扩量 params.lookalikeMultiple = lookalikeMultiple params.lookalikeAlgoType = 16 } const models = [ { name: 'dmp-advgateway_api_dmp_analysis_coverage_post', // isJson: true, params } ] this.updater.digest({ coverageLoadingAdjust: true }) const [model] = await this.fetch(models) const { coverage, level, hintDataSecurity, hintDataSecurityInfo, adPredictOn } = model.get('data.result', {}) this.updater.digest({ adPredictOn, scaleTypes, coverageAdjust: coverage, dashboardAdjust: level, hintDataSecurityAdjust: hintDataSecurity, hintDataSecurityAdjustInfo: hintDataSecurityInfo, coverageLoadingAdjust: false }) } catch (error) { this.updater.digest({ coverageLoadingAdjust: false, dashboardAdjust: null, coverageAdjust: EMPTY_COVERAGE }) this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } this.getAdPredict(1) } }, 'changeCate'(e) { this.getAdPredict(1) }, async 'changeTab'(e) { const { selectedTab, scaleType, scaleTypes } = this.updater.get() // await this.getCoverage() if (selectedTab != 2) { // 非已保存人群tab下才有放大的功能 if (scaleType == 2) { this.getCoverageAdjust() } } else { // 切回 已保存人群 tab下时,如果之前有放大,则取消放大模块 // if (scaleTypes.length > 1) { // scaleTypes.pop() scaleTypes[1].disable = true this.updater.digest({ scaleType: 1, scaleTypes }) // } } // 平台精选组件宽度在未加载时会异常,需要手动 digest 下一个无用的值 if (selectedTab == 4) { const vf = await this.waitVframeCreated( Magix.Vframe.get(`${this.id}_crowdView_${selectedTab}`) ) vf.$v.updater.digest({ randomValue: Math.random() }) } }, // 获取广告预估、人群竞争分析 async getAdPredict(queryType) { const { viewId, selectedTab, scaleType, lookalikeMultiple, currentApp, selectedCate, adPredictOn, permissions } = this.updater.get() if (!permissions.includes('dmpCrowdAnalyze') || !selectedCate) { return } const crowdVframe = await this.waitVframeCreated( Magix.Vframe.get(`${viewId}_crowdView_${selectedTab}`) ) const { selectTagOptionSetDTO } = crowdVframe.$v.updater.get() const { bizCode } = this.options // 一个选择的标签都没有 if (!selectTagOptionSetDTO._selectedTagCounts || !adPredictOn) { return this.updater.digest({ hint: null, ctrIndex: EMPTY_COVERAGE, ppcIndex: EMPTY_COVERAGE, dailyReachUV: EMPTY_COVERAGE, industryCompetitionPredicts: [] }) } try { const params = { bizCode, selectTagOptionSetDTO, analysisSetting: {}, adPredictQuery: { queryType, deliverType: currentApp.deliverId, cateId: selectedCate } } // 有扩量 if (scaleType == 2) { params.analysisSetting.lookalikeMultiple = lookalikeMultiple params.analysisSetting.lookalikeAlgoType = 16 } this.updater.digest({ adPredictLoading: true }) const models = [ { name: 'appone_api_dmp_analysis_adpredict_post', params } ] const [model] = await this.fetch(models) const data = model.get('data.adPredict', {}) this.updater.digest({ hintDataSecurityPredict: data.hintDataSecurity, hintDataSecurityInfoPredict: data.hintDataSecurityInfo, hint: data.hint, adPredictLoading: false, ctrIndex: data.ctrIndex, ppcIndex: data.ppcIndex, dailyReachUV: data.dailyReachUV, industryCompetitionPredicts: data.industryCompetitionPredicts }) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) this.updater.digest({ adPredictLoading: false, ctrIndex: EMPTY_COVERAGE, ppcIndex: EMPTY_COVERAGE, dailyReachUV: EMPTY_COVERAGE, industryCompetitionPredicts: [] }) } }, // 开始分析广告预估效果、竞争分析 async 'analyseCompete'(e) { this.getAdPredict(1) }, // 开启扩量、改变扩量倍数 'changeExpandTimes'(e) { const { scaleType } = this.updater.get() if (scaleType == 1) { this.getCoverage() } else { this.getCoverageAdjust() } }, 'cancel'(e) { const { dialog, cancelCallback } = this.options if (dialog) { dialog.close() } else if (cancelCallback) { cancelCallback() } }, async 'confirm'(e) { const { selectedTab } = this.updater.get() if (selectedTab == 1) { await this.createCrowd() // 新建人群 } else if (selectedTab == 2) { await this.selectCrowds() // 选择已有人群 } else if (selectedTab == 3) { await this.createCrowdByTmpl() // 从模板创建人群 } else if (selectedTab == 4) { await this.createHotCrowds() // 精选平台人群 } }, // 新建人群tab: 1 async createCrowd(isInvoke) { // {{=viewId}}_crowdView_{{=view.value}} const { viewId, selectedTab, crowdName, isEdit, bizCode, isCommonCrowd } = this.updater.get() const crowdVframe = await this.waitVframeCreated( Magix.Vframe.get(`${viewId}_crowdView_${selectedTab}`) ) const { selectTagOptionSetDTO, source, tagGroups } = crowdVframe.$v.updater.get() // 如果有标签选择了自定义,但是分组选项没有选择完整,每个标签给出提示,并confirm提示 let hasNoCompleteTag for (const tag of tagGroups.tags) { // selectType=2 自定义,没有optionGroups表示该标签选了自定义但选项没填写完整 if (tag.selectType == '2' && !tag.optionGroups) { const vf = await this.waitVframeCreated( Magix.Vframe.get(`${crowdVframe.$v.id}_${tag.id}`) ) vf.invoke('showTips') hasNoCompleteTag = true } } if (!this.isValid()) { if (isInvoke) { throw new Error() } else { return } } if (!selectTagOptionSetDTO._selectedTagCounts) { const erroMsg = '请至少选择一个标签再提交' if (isInvoke) { throw new Error(erroMsg) } else { return this.alert('有未完成的内容', erroMsg, null, { mask: true }) } } // 提示 if (hasNoCompleteTag) { return this.confirm({ title: '确定提交吗', content: '有自定义设置未填写完整,将导致自定义不生效,提交后该项默认为“不限”。', enterCallback: () => { doCreateCrowd.bind(this)() } }) } else { doCreateCrowd.bind(this)() } async function doCreateCrowd() { const params = { bizCode, dmpCrowd: { crowdName, selectTagOptionSetDTO, extra: {} } } // 有推荐的标识加上 if (source) { params.dmpCrowd.extra.source = source } return await this._createCrowd( isInvoke, params, isEdit, isCommonCrowd ? 83 : 82, true ) // 83:保存为常用人群,82:一性次人群 } }, // 已保存人群: 2 async selectCrowds(isInvoke) { const { maxCount, viewId, selectedTab // scaleType, // bizCode, // lookalikeMultiple } = this.updater.get() const crowdVframe = await this.waitVframeCreated( Magix.Vframe.get(`${viewId}_crowdView_${selectedTab}`) ) const { selected, hideSelected, selectedCrowd, singleSelected } = crowdVframe.$v.updater.get() const { dialog, callback } = this.options // hideSelected 隐藏人群 // selected 已保存人群 // if (!selectedCrowd) { // return this.alert('提示', '请至少选择一个人群', null, { mask: true }) // } // 如果是放大的情况需要编辑下人群 // if (scaleType == 2) { // try { // let params = { // bizCode, // dmpCrowd: { // crowdName: selectedCrowd.crowdName, // crowdId: selectedCrowd.crowdId, // selectTagOptionSetDTO: selectedCrowd.selectTagOptionSetDTO, // lookalikeAlgoType: 16, // lookalikeMultiple // } // } // let models = [{ // name: 'appone_api_dmp_crowd_modify_post', // params // }] // let [model] = await this.fetch(models) // // let data = model.get('data') // // return data // } catch (error) { // return this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) // } // } function resolveError(message) { if (isInvoke) { throw new Error(message) } else { return this.alert('提示', message, null, { mask: true }) } } let msg if (!(selected.length + hideSelected.length)) { msg = '请至少选择一个人群' } else if (selected.length + hideSelected.length > maxCount) { msg = '已选人群包数量达到上限' } if (msg) { return resolveError.bind(this)(msg) } // if (!(selected.length + hideSelected.length)) { // const msg = '请至少选择一个人群' // if (isInvoke) { // throw new Error(msg) // } else { // return this.alert('提示', msg, null, { mask: true }) // } // } // if (selected.length + hideSelected.length > maxCount) { // const msg = '已选人群包数量达到上限' // if (isInvoke) { // throw new Error(msg) // } else { // return this.alert('提示', msg, null, { mask: true }) // } // } this.updater.digest({ saveLoading: true }) const allSelected = [...selected, ...hideSelected] try { const { bpCrowds, crowds, totalCrowds } = await this.getBpCrowds( allSelected ) if (bpCrowds.length > maxCount) { resolveError.bind(this)(`最多选择${maxCount}个人群`) } // else if (isInvoke) { return totalCrowds } else { if (dialog) { dialog.afterClose(() => { callback(totalCrowds) }) dialog.close() } else { callback(totalCrowds) } } } catch (error) { resolveError.bind(this)(error.msg || error.message) } this.updater.digest({ saveLoading: false }) }, // 从模板创建人群: 3 (营销沉淀人群) async createCrowdByTmpl(isInvoke) { const { viewId, selectedTab, bizCode, Moment } = this.updater.get() const crowdVframe = await this.waitVframeCreated( Magix.Vframe.get(`${viewId}_crowdView_${selectedTab}`) ) const selected = crowdVframe.invoke('getSelected') if (!selected) { const errMsg = '请至少选择一个人群模板' if (isInvoke) { throw new Error(errMsg) } else { return this.alert('提示', errMsg, null, { mask: true }) } } const selectTagOptionSetDTO = selected.crowdRule.selectTagOptionSetDTO const crowdName = `${selected.name}_${Moment().format('YYYYMMDDHHmmss')}` const params = { bizCode, dmpCrowd: { crowdName, selectTagOptionSetDTO } } return await this._createCrowd(isInvoke, params, false, 87) // 人群模板创建的新businessType }, // 精选平台人群: 4 async createHotCrowds(isInvoke) { const { dialog, callback, crowdIds, maxCount } = this.options const { selectedTab } = this.updater.get() const crowdVframe = await this.waitVframeCreated( Magix.Vframe.get(`${this.id}_crowdView_${selectedTab}`) ) function resolveError(message) { if (isInvoke) { throw new Error(message) } else { return this.alert('提示', message, null, { mask: true }) } } this.updater.digest({ saveLoading: true }) const apiPromises = [crowdVframe.invoke('createCrowds')] // 如果自定义圈人有传已有人群 crowdIds,则也调用下covert接口与精选平台的人群合并返回 if (crowdIds && crowdIds.length) { apiPromises.push(this.convertToBpCrowd(crowdIds)) } let [{ crowds, errMsg }, bpCrowds = []] = await Promise.all(apiPromises) const totalCrowds = [...crowds, ...bpCrowds] //自定义人群和精选平台人群合并 this.updater.digest({ saveLoading: false }) // 所选人群汇总超出 maxCount,给出错误提示 errMsg = errMsg ?? (bpCrowds.length > maxCount ? `最多选择${maxCount}个人群` : null) if (errMsg) { return resolveError.bind(this)(errMsg) // if (isInvoke) { // throw new Error(errMsg) // } else { // return this.alert('提示', errMsg, null, { mask: true }) // } } if (isInvoke) { return totalCrowds } else { if (dialog) { dialog.afterClose(() => { callback(totalCrowds) }) dialog.close() } else { callback(totalCrowds) } } }, // 创建人群 async _createCrowd(isInvoke, params, isEdit, businessType, isCreateCrowd) { function resolveError(message) { if (isInvoke) { throw new Error(message) } else { return this.alert('提示', message, null, { mask: true }) } } this.updater.digest({ saveLoading: true }) try { const { noConvert, crowdIds, dialog, callback } = this.options const { scaleType, lookalikeMultiple, relateRecommendIds, combineRecommendIds, maxCount } = this.updater.get() // 有扩量 if (scaleType == 2) { params.dmpCrowd.lookalikeMultiple = lookalikeMultiple params.dmpCrowd.lookalikeAlgoType = 16 } let crowdId if (isCreateCrowd) { params.dmpCrowd.extra.relateRecommendIds = relateRecommendIds.join(',') params.dmpCrowd.extra.combineRecommendIds = combineRecommendIds.join(',') } if (isEdit) { crowdId = this.options.crowdId params.dmpCrowd.crowdId = crowdId const models = [ { name: 'dmp-advgateway_api_dmp_crowd_modify_post', // isJson: true, params } ] await this.fetch(models) } else { params.dmpCrowd.businessType = businessType const models = [ { name: 'dmp-advgateway_api_dmp_crowd_create_post', // isJson: true, params } ] const [model] = await this.fetch(models) crowdId = model.get('data.result') } let _crowdIds = [crowdId] // 原先传进来的人群IDS保留 if (crowdIds) { _crowdIds = [..._crowdIds, ...crowdIds] } let { bpCrowds, crowds, totalCrowds } = await this.getBpCrowds(_crowdIds) if (bpCrowds.length > maxCount) { resolveError.bind(this)(`最多选择${maxCount}个人群`) } // else if (isInvoke) { return totalCrowds } else { if (dialog) { dialog.afterClose(() => { callback(totalCrowds) }) dialog.close() } else { callback(totalCrowds) } } } catch (error) { resolveError.bind(this)(error.msg || error.message) } this.updater.digest({ saveLoading: false }) }, // 达摩盘人群转换业务线人群 async getBpCrowds(crowdIds) { const { noConvert } = this.options let bpCrowds let crowds let totalCrowds if (!noConvert) { bpCrowds = await this.convertToBpCrowd(crowdIds) totalCrowds = bpCrowds // 如果有精选平台tab,则也调用下精选平台的convert接口返回人群与自定义人群合并返回 const { tabObj } = this.updater.get() const crowdVframe = await this.waitVframeCreated( Magix.Vframe.get(`${this.id}_crowdView_${tabObj.tab4.value}`) ) if (crowdVframe) { const { crowds: _crowds, errMsg } = await crowdVframe.invoke( 'createCrowds' ) crowds = _crowds if (!errMsg) { totalCrowds = [...bpCrowds, ...crowds] } } } return { bpCrowds, crowds, totalCrowds } }, // 达摩盘人群转换业务线人群接口 async convertToBpCrowd(crowdIds) { const { bizCode } = this.updater.get() const { convertParams } = this.options // convertParams const params = { bizCode, dmpCrowdIdList: crowdIds } Object.assign(params, convertParams) const models = [ { name: 'appone_api_dmp_crowd_convert_post', // isJson: true, params } ] const [model] = await this.fetch(models) const data = model.get('data.bizCrowdList', []) return data }, // invoke async getBizCrowds() { const { selectedTab } = this.updater.get() try { let crowds if (selectedTab == 1) { crowds = await this.createCrowd(true) // 新建人群 } else if (selectedTab == 2) { crowds = await this.selectCrowds(true) // 选择已有人群 } else if (selectedTab == 3) { crowds = await this.createCrowdByTmpl(true) // 从模板创建人群 } else if (selectedTab == 4) { crowds = await this.createHotCrowds(true) // 精选平台人群 } return { crowds } } catch (error) { return { errMsg: error.message, crowds: [] } } } })