import Magix from 'magix' import View from 'dmp-new/view' Magix.applyStyle('@./create-crowd-item.less') const SCENE_TYPE = 1 const ITEM_BEHAVIORS = [ { text: '收藏加购偏好', value: '1' }, { text: '购买偏好', value: '2' }, { text: '浏览偏好', value: '3' } ] export default View.extend({ tmpl: '@create-crowd-item.html', init(options) { this.options = options }, async render() { const loc = Magix.Router.parse() const { competeStatusId, report, taskId, statusId, items, transferType, top20, brandsMap, isInflow, competeBrandId } = this.options const { Dayjs } = this.updater.get() 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 itemIdBehavior = ITEM_BEHAVIORS[0].value this.updater.digest({ itemId: [], items, statusId, competeStatusId, ITEM_BEHAVIORS, itemIdBehavior, report, taskId, validDate, minDate, maxDate, transferType, top20, brandsMap, isInflow, competeBrandId }) this.refreshCoverage() }, async refreshCoverage() { 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, statusId, competeStatusId, transferType, itemIdBehavior, itemId } = this.updater.get() if (!itemId.length) { return } const params = { sceneType: SCENE_TYPE, taskId, competeBrandId, transferType, status: [statusId], competeStatus: [competeStatusId], itemIdBehavior, itemId } 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, statusId, competeStatusId, transferType, crowdName, validDate, itemIdBehavior, itemId } = this.updater.get() const params = { sceneType: SCENE_TYPE, taskId, competeBrandId, transferType, status: [statusId], competeStatus: [competeStatusId], crowdName, validDate, itemIdBehavior, itemId } 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, statusId, competeStatusId, transferType, itemIdBehavior, itemId } = this.updater.get() const params = { sceneType: SCENE_TYPE, taskId, competeBrandId, transferType, status: [statusId], competeStatus: [competeStatusId], itemIdBehavior, itemId } 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() } })