import Magix from 'magix' import * as View from '../../../../view' import * as Helper from 'dmp-new/views/mixins/helper' import CreateCrowd from './zhibo/crowd-mixin' Magix.applyStyle('@./create-item-crowd.less') Magix.applyStyle('@../create.less') const EMPTY_SYMBOL = '--' // const canIterationIds = ['1', '2', '3', '6', '7', '8'] const expandApi = 'api_scenario_cluster_getExtensionTag_get' export default View.extend({ tmpl: '@create-item-crowd.html', mixins: [CreateCrowd], init (options) { const me = this this.options = options }, async render () { const kmeansTaskName = this.options.kmeansTaskName const kmeansTaskId = this.options.kmeansTaskId const kmeansCnt = this.options.kmeansCnt const subClusterIdxList = this.options.subClusterIdxList.split(',') || [] const taskDetail = await this.getTaskDetail(kmeansTaskId) const subjectTypes = [{ text: '日常拉新', value: '1' }, { text: '大促推广', value: '2' // hot: true }] const selectedSubject = subjectTypes[0].value this.updater.digest({ predictApi: 'api_scenario_cluster_predict_post', selectedSubject, subjectTypes, checkCrowdSelected: (id) => { const { subClusterIdxList } = this.updater.get() let isMatch = false for (const _id of subClusterIdxList) { if (_id == id) { isMatch = true } } return isMatch }, dailyUpdate: true, coverage: EMPTY_SYMBOL, EMPTY_SYMBOL, // canIterationIds, coverageLoading: false, // 原始预估loading subClusterIdxList, taskDetail, kmeansTaskName, kmeansTaskId, kmeansCnt }) // 人群扩展方向 await this.renderExpands(selectedSubject, expandApi, { kmeansTaskId }) this.setBaseCandidateCrowds() this.refreshCoverage() }, async 'changeSubjectType' (e) { const { selectedSubject, kmeansTaskId } = this.updater.get() // 人群扩展方向 await this.renderExpands(selectedSubject, expandApi, { kmeansTaskId }) // this.setBaseCandidateCrowds() this.refreshCoverage() }, // 获取base人群设置 getBaseSelectTagOptionSets () { const { all, taskDetail, subClusterIdxList } = this.updater.get() const selectTagOptionSet_412 = $.extend(true, {}, all.selectTagOptionSet_412) const selectTagOptionSets = [] for (const crowd of taskDetail.crowdList) { for (const id of subClusterIdxList) { if (crowd.subClusterIdx == id) { selectTagOptionSets.push(crowd.selectTagOptionSet) } } } // selectTagOptionSet取并集 for (const set of selectTagOptionSets) { selectTagOptionSet_412.selectTagOptionSet[0].selectTagOptionSet[1].selectTagOptionSet.push(set.selectTagOptionSet[0]) } return selectTagOptionSet_412 }, // 给子view调用的获取coverage的入参params getParams () { const kmeansTaskId = this.options.kmeansTaskId const { selectedExpandTag, subClusterIdxList } = this.updater.get() const _base = this.getBaseSelectTagOptionSets() if (!selectedExpandTag || !subClusterIdxList || !subClusterIdxList.length || !this._candidate || !_base) { return false } const params = { kmeansTaskId, extensionTag: selectedExpandTag, subClusterIdxList, base: _base, candidate: this._candidate } return params }, async 'changeTag' (e) { this.refreshCoverage() }, async refreshCoverage () { // const { selectedExpandTag } = this.updater.get() const crowdSetVf = await this.waitVframeCreated(Magix.Vframe.get(`${this.id}_crowdSet`)) await crowdSetVf.invoke('getCoverage') // if (!canIterationIds.includes(selectedExpandTag)) { // this.updater.digest({ // dailyUpdate: false // }) // } }, // 获取基础人群 和 扩展方向人群 setBaseCandidateCrowds () { const { selectedExpandTag, expandTags } = this.updater.get() let candidate = expandTags.find(crowd => crowd.type == selectedExpandTag).tagList[0] // 检查人群扩展方向里的selectTagOptionSet 里的 values有没有为空 // values 有为空的代表该标签需要用户设置才能用 if (this.checkValues(candidate)) { candidate = undefined } this._candidate = candidate }, async getTaskDetail (kmeansTaskId) { try { const loc = Magix.Router.parse() const params = { kmeansTaskId, kmeansCnt: this.options.kmeansCnt } const models = [{ name: 'api_scenario_cluster_view_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 }) } }, async 'create' (e) { if (!this.isValid()) { return } const crowdSetVf = await this.waitVframeCreated(Magix.Vframe.get(`${this.id}_crowdSet`)) const { coverageLoading, targetCrowdNum } = crowdSetVf.$v.updater.get() const { kmeansTaskId, kmeansCnt, subClusterIdxList, taskDetail, selectedExpandTag, dailyUpdate } = this.updater.get() if (coverageLoading) { return this.alert('提示', '系统预估实际可覆盖人群中,请等待系统计算完,再选择预期创建人群量。', null, { mask: true }) } if (!subClusterIdxList.length) { return this.alert('提示', '请至少选择一个分层人群', null, { mask: true }) } const subClusterNameList = [] subClusterIdxList.forEach((id, i) => { for (const crowd of taskDetail.crowdList) { if (crowd.subClusterIdx == id) { subClusterNameList[i] = crowd.rate1 } } }) const _base = this.getBaseSelectTagOptionSets() const viewPath = '@./create-crowd' const viewOptions = { callback: () => { // this.options.dialog.close() }, hasSyncChannel: true, // 可以直接同步渠道 api: 'api_scenario_cluster_expand_post', params: { dailyUpdate: dailyUpdate ? '1' : '0', targetCrowdNum, extensionTag: selectedExpandTag, kmeansCnt, kmeansTaskId, subClusterIdxList, subClusterNameList, base: _base, candidate: this._candidate } } const dialogOptions = { width: 380, top: 100 } this.mxDialog(viewPath, viewOptions, dialogOptions) }, 'cancel' (e) { this.options.dialog.close() } })