import Magix from 'magix' import View from 'dmp-new/view' Magix.applyStyle('@./create-crowd-level.less') const SCENE_TYPE = 2 export default View.extend({ tmpl: '@create-crowd-level.html', init(options) { this.options = options }, async render() { const loc = Magix.Router.parse() const { top20 } = this.options const { report, taskId, transferType, brandsMap, isInflow, competeBrandId = top20[0].brandId, statusIds, statusId } = this.options const { Dayjs } = this.updater.get() const FLOW_STATUS = [ // { // text: '竞争品牌资产相似人群', // value: '3' // } ] if (isInflow) { FLOW_STATUS.unshift({ text: '竞争品牌流入本品牌资产', value: '1' }) } else { FLOW_STATUS.unshift({ text: '本品牌流出到竞争品牌资产', value: '2' }) } const minDate = Dayjs().format('YYYY-MM-DD') const defaultDate = Dayjs().add(29, 'days').format('YYYY-MM-DD') const maxDate = Dayjs().add(1, 'years').format('YYYY-MM-DD') const validDate = defaultDate // const competeStatus = statusIds[0].id const competeStatus = [] this.updater.digest({ report, taskId, status: statusId ? [statusId] : [], competeStatus, validDate, minDate, maxDate, transferType, top20, brandsMap, isInflow, competeBrandId, statusIds, FLOW_STATUS // flowStatus }) this.refreshCoverage() }, async refreshCoverage() { const { status, competeStatus, transferType } = this.updater.get() // 分层必选逻辑 if ( (transferType === '3' && !competeStatus.length) || (transferType !== '3' && (!status.length || !competeStatus.length)) ) { return this.updater.digest({ coverage: undefined }) } this.updater.digest({ coverageLoading: true, coverage: undefined }) try { const coverage = await this.getCoverage() this.updater.digest({ coverage }) } catch (error) {} this.updater.digest({ coverageLoading: false }) }, async getCoverage() { const { taskId } = this.options const { competeBrandId, status, competeStatus, transferType } = this.updater.get() const params = { sceneType: SCENE_TYPE, taskId, competeBrandId, transferType, status, competeStatus } const models = [ { name: 'api_deeplink_compete_crowd_coverage_post', isJson: true, params } ] const [model] = await this.fetch(models) const data = model.get('data.coverage') return data }, 'changeFilter'(e) { this.refreshCoverage() }, // 创建人群 async 'create'(e) { if (!this.isValid()) { return } this.updater.digest({ loading: true }) try { await this.createCrowd() this._alert( { title: '提示', content: '恭喜,人群创建成功!', enterCallback: () => { this.options.dialog.close() } }, { type: 'pass' } ) } catch (error) { this._alert( { title: '提示', content: error.msg ?? error.message }, { type: 'error' } ) } this.updater.digest({ loading: false }) }, async createCrowd() { const { taskId } = this.options const { competeBrandId, status, competeStatus, transferType, crowdName, validDate } = this.updater.get() const params = { sceneType: SCENE_TYPE, taskId, competeBrandId, transferType, status, competeStatus, crowdName, validDate } const models = [ { name: 'api_deeplink_compete_crowd_create_post', isJson: true, params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data }, // 自定义圈人 async 'customCreate'(e) { this.updater.digest({ loading: true }) try { const { crowdName = '', validDate = '' } = this.updater.get() const { selectTagOptionSet, extra = {} } = await this.dumpCrowd() const paramsObj = { selectTagOptionSet: JSON.stringify(selectTagOptionSet), crowdName, validDate // [`$deeplink_assets_custom_${createType}`]: dataValue } // 创建人群的额外埋点信息,由后端返回,拼格式为 $xxxx=xxx if (extra) { for (const key in extra) { paramsObj[`$${key}`] = extra[key] } } const paramsArr = [] for (const key in paramsObj) { const value = paramsObj[key] paramsArr.push(`${key}=${value}`) } const paramsStr = paramsArr.join('&') // 埋点 extra 传参 // 同不圈人入口埋点 value 值 Magix.Router.to(`/crowds-new/create?${paramsStr}`) } catch (error) { this._alert( { title: '提示', content: error.msg ?? error.message }, { type: 'error' } ) } this.updater.digest({ loading: false }) }, async dumpCrowd() { const { taskId } = this.options const { competeBrandId, status, competeStatus, transferType } = this.updater.get() const params = { sceneType: SCENE_TYPE, taskId, competeBrandId, transferType, status, competeStatus } const models = [ { name: 'api_deeplink_compete_crowd_dump_post', isJson: true, params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data }, // 取消 'cancel'(e) { this.options.dialog.close() } })