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 += `
${tagSet.tagName}:${tagSet.optionNames.join( '、' )}
` } crowd._tagSets = _tagSets crowd._tagSetString = _tagSetString } } }, 'selectAll'(e) { const { crowds, selected, hideSelected } = this.updater.get() if (e.target.checked) { for (const crowd of crowds) { if (!selected.includes(crowd.crowdId)) { selected.push(crowd.crowdId) } } } else { for (const crowd of crowds) { const _index = selected.indexOf(crowd.crowdId) if (_index !== -1) { selected.splice(_index, 1) } } } this.updater.digest({ selected }) // 更新下crowdsCount this.updateCrowdsCount() }, // 更新下crowdsCount updateCrowdsCount() { const { selected, hideSelected } = this.updater.get() const parent = this.owner.parent() const count = hideSelected.length + selected.length parent.invoke('setCrowdsCount', [count]) }, async 'selectOne'(e) { // let { crowd } = e.params // let { selectTagOptionSetDTO } = crowd // let count = 0 // Helper.recurSelectTagOptionSet([selectTagOptionSetDTO], selects => { // for (const select of selects) { // if (select.values === '${shopId}' || select.adapterType == 1) { // select.values = shopId.toString() // } // if (select.values === '${mainCateId}' || select.adapterType == 2) { // select.values = mainCateId.toString() // } // delete select.adapterType // } // count++ // }, 'selectTagOptionSetDTO') // selectTagOptionSetDTO._selectedTagCounts = count // this.updater.set({ // selectTagOptionSetDTO, // selectedCrowd: crowd // }) // //父view里更新下覆盖数 // let pv = this.owner.parent().$v // await pv.getCoverage() // let { scaleType } = pv.updater.get() // if (scaleType == 2) { // pv.getCoverageAdjust() // } const { crowdId } = e.params const { selected } = this.updater.get() if (e.target.checked) { selected.push(crowdId) } else { for (let i = 0; i < selected.length; i++) { if (crowdId == selected[i]) { selected.splice(i, 1) break } } } this.updater.digest({ selected }) // 更新下crowdsCount this.updateCrowdsCount() }, 'changePage'(e) { // const { params } = this.updater.get() // params.page = e.page this.render() }, 'changeSource'(e) { const { params } = this.updater.get() params.page = 1 this.render() }, 'changeDmpSource'(e) { const { params } = this.updater.get() params.listType = e.value params.page = 1 this.render() }, 'search'(e) { const { params } = this.updater.get() params.page = 1 this.render() }, 'editCrowd'(e) { const textContent = '修改人群后,该人群已应用计划投放人群会对应修改' this.confirm({ width: 300, title: '确定修改吗?', content: textContent, enterCallback: async () => { const { crowdId } = e.params const viewOptions = { bizCode: this.options.bizCode, crowdId, noConvert: true, callback: data => { this.render() } } const viewPath = '@./custom-crowd' const width = document.querySelector('body').offsetWidth - 188 this.mxModal(viewPath, viewOptions, { width, header: { title: '编辑自定义人群' }, footer: { enter: false, cancel: false } }) }, mask: true }) }, 'trHover'(e) { const { crowds } = this.updater.get() const { crowd } = e.params crowd.isShowOperator = true this.updater.digest({ crowds }) }, 'trOut'(e) { const { crowds } = this.updater.get() const { crowd } = e.params crowd.isShowOperator = false this.updater.digest({ crowds }) }, 'copyCrowd'(e) { const { crowdId } = e.params const viewOptions = { bizCode: this.options.bizCode, crowdId, isCopy: true, noConvert: true, callback: data => { this.render() } } const viewPath = '@./custom-crowd' const width = document.querySelector('body').offsetWidth - 188 this.mxModal(viewPath, viewOptions, { width, header: { title: '复制自定义人群' }, footer: { enter: false, cancel: false } }) }, async 'removeCrowd'(e) { const { crowdId } = e.params // const planList = [{}] const { bizCode } = this.updater.get() // const textContent = `人群已被X个计划应用,移除后会影响以下计划的人群投放,确定要移除吗?
${planList.map(plan => { // return '
超级推荐: 计划名称1、计划名称2
' // }).join('')}
` const textContent = '人群不再保存到列表里,已应用该人群的计划仍可正常投放,不受影响' this.confirm({ width: 300, title: '确定移除吗?', content: textContent, enterCallback: async () => { try { const models = [ { name: 'dmp-advgateway_api_dmp_crowd_delete_post', params: { bizCode, crowdId } } ] await this.fetch(models) // 同步下已选择的人群,删减 const { selected } = this.updater.get() for (let i = 0; i < selected.length; i++) { if (selected[i] == crowdId) { selected.splice(i, 1) break } } const { params } = this.updater.get() params.page = 1 this.render() // 更新下crowdsCount this.updateCrowdsCount() } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, mask: true }) } })