import Magix from 'magix' import * as View from '../../../view' import * as Helper from 'dmp-new/views/mixins/helper' Magix.applyStyle('@./create-crowd.less') const DMP_LIST_TYPES = [ { text: '我创建的人群列表', value: '1' }, { text: '合作方人群列表', value: '2' }, { text: '数据银行', value: '3' }, { text: '策略中心自建', value: '4' }, { text: '达摩盘', value: '5' } ] export default View.extend({ tmpl: '@common-crowds.html', async init(options) { this.options = options const { permissions, dictConfig, crowdIds } = options const selected = [] // 常用选中人群 const hideSelected = [] // 隐藏选中人群 - 新建人群时没有勾选保存为常用人群的人群 // 从已选择的人群里挑出常用人群,放进selected里,做选中状态 if (crowdIds && crowdIds.length) { const crowds = await this.getSelectedCrowds(crowdIds) for (const crowd of crowds) { // 82:为隐藏人群,83为常用人群 // 除了隐藏人群,其他人群都归入可选择的selected if (crowd.businessType == 82) { hideSelected.push(crowd.crowdId) } else { selected.push(crowd.crowdId) } } } this.updater.set({ DMP_LIST_TYPES, singleSelected: '', permissions, hideSelected, // 已选择的隐藏人群 selected, // 已选择的常用人群 dictConfig }) }, async render() { if (!this.updater.get('params')) { this.updater.set({ params: {} }) } const crossConfigsMap = Magix.toMap(window.crossConfigs, 'projectName') const dmpConfig = crossConfigsMap['dmp-new'] || {} const { bizCode, crowdIds, currentApp } = this.options const { params } = this.updater.get() const { sourceList, sourceMap } = this.getSourceList() params.appIdList = params.appIdList ?? sourceList[0].value params.crowdName = params.crowdName ?? '' params.listType = params.listType ?? '' params.page = params.page ?? 1 this.updater.set({ dmpConfig, // maxCount: 8, bizCode, crowdsLoading: true, sourceList, sourceMap }) // 当前bp的appId const currentAppId = currentApp && currentApp.value && currentApp.value.replace(/[\[\]]/g, '') this.updater.digest({ currentAppId }) const crowdsData = await this.getCrowds() this.updater.set({ crowdsLoading: false }) // 标识已经选过的人群 if (crowdIds && crowdIds.length) { for (const crowdId of crowdIds) { for (const crowd of crowdsData.list) { if (crowd.crowdId == crowdId) { crowd._isUsed = true // } } } } params.page = crowdsData.pager.currentPage params.total = crowdsData.pager.total params.pageSize = crowdsData.pager.pageSize this.updater.digest({ checkAll: () => { const { selected, crowds } = this.updater.get() let isAll = true for (const crowd of crowds) { if (!selected.includes(crowd.crowdId)) { isAll = false break } } return isAll ? 'checked' : '' }, params, crowds: crowdsData.list }) }, // getSourceList() { const { onlyDmpSource, dictConfig } = this.options const { permissions } = this.updater.get() let _sourceList = $.extend(true, [], Magix.config('dmpBpCrowdSourceList')) const sourceMap = {} for (const source of _sourceList) { // [45] 去掉中括号 const key = source.value && source.value.replace(/[\[\]]/g, '') sourceMap[key] = source } const sourceList = dictConfig.dmpBaseOptionalSelectAppList.map(item => { return { text: item.displayName, value: JSON.stringify(item.appIdList) } }) // const allSource = _sourceList[0] // 所有来源 // // 基础版来源,所有来源去掉达摩盘=0即为基础版来源 // const baseSource = { // text: '基础版', // value: allSource.value.replace('[0,', '[') // } // const dmpSource = _sourceList[1] // 达摩盘来源 // let sourceList = [allSource, baseSource] // // 没有达摩盘权限的去掉达摩盘筛选 // if (permissions.includes('dmpPlatform')) { // sourceList.splice(1, 0, dmpSource) // } else if ( // !permissions.includes('dmpBizBase') || // permissions.includes('dmpOptionalCrowd') || // onlyDmpSource // ) { // // dmpOptionalCrowd 超级直播才有的权限,只有达摩盘渠道人群 // sourceList = [dmpSource] // } return { sourceMap, sourceList } }, // 获取已选择的人群的businessType,来区分是隐藏还是常用人群 async getSelectedCrowds(crowdIds) { try { const params = { crowdIdList: crowdIds, withCrowdXTag: false, bizCode: this.options.bizCode } const models = [ { name: 'dmp-advgateway_api_dmp_crowd_list_get', params } ] const [model] = await this.fetch(models) const list = model.get('data.result', []) return list.map(item => { return { crowdId: item.crowdId, businessType: item.businessType } }) } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, async getCrowds() { const { params, bizCode } = this.updater.get() const deliverAppId = this.options.currentApp?.deliverAppId const _params = { // 默认参数 page: 1, pageSize: 10, bizCode, deliverAppId } $.extend(_params, params) delete _params.total // 删除掉空的Key for (const key of Object.keys(_params)) { if (_params[key] == null || _params[key] === '') { delete _params[key] } } try { const models = [ { name: 'dmp-advgateway_api_dmp_crowd_list_get', params: _params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) data.list = data.result || [] // data.list[2] = $.extend(true, {}, data.list[1]) data.pager = { currentPage: _params.page, total: data.pager.total, pageSize: _params.pageSize } // 汇总人群下所有标签的选择信息 this.sumTagSets(data) return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, // 汇总人群下所有标签的选择信息 sumTagSets(data) { const list = data.list || [] for (const crowd of list) { if (crowd.selectTagOptionSetDTO) { const _tagSets = [] Helper.recurSelectTagOptionSet( [crowd.selectTagOptionSetDTO], selects => { const tagSet = { tagName: selects[0].tagName, optionNames: [] } for (const select of selects) { tagSet.optionNames.push(select.names) } _tagSets.push(tagSet) }, 'selectTagOptionSetDTO' ) let _tagSetString = '人群描述' for (const tagSet of _tagSets) { _tagSetString += `