import Magix from 'magix' import View from 'dmp-new/view' import CONSTANT from '../constant' import Helper from '../helper' Magix.applyStyle('@./create-flow-crowd.less') export default View.extend({ tmpl: '@create-flow-crowd.html', mixins: [Helper], init(options) { this.options = options }, async render() { const { Dayjs } = this.updater.get() const { brandIds, brandsMap, startTime, endTime } = this.options const minDate = Dayjs().format('YYYY-MM-DD') const statusIds = this.getStatusIds() const validDate = Dayjs().add(1, 'months').format('YYYY-MM-DD') const showBrandNames = brandIds .map(id => brandsMap[id]?.brandName) .join(',') this.updater.digest({ crowdName: '', validDate, minDate, statusIds, showBrandNames, startTime, endTime, getOtherStatus: status => { const { statusIds } = this.updater.get() let startIndex if (status.value === 'z') { // 新增的特殊处理 startIndex = 1 } else { statusIds.forEach((_status, _i) => { if (status.value === _status.value) { startIndex = _i } }) } return statusIds.slice(startIndex) } }) }, // 流转路径数据 getStatusIds() { const statusIds = $.extend(true, [], CONSTANT.statusList) statusIds.find((item, i) => { if (item.key === 'z') { // z: 新增人群 const [_item] = statusIds.splice(i, 1) statusIds.unshift(_item) return true } return false }) return statusIds.map(item => { return { text: item.statusName, value: item.key, endStatus: [] } }) }, // 创建人群的入参 getParams() { const { query, bp } = this.options const { validDate, crowdName } = this.updater.get() const dumpQueries = this.getDumpQueries() const params = { query, bp, moduleId: CONSTANT.FLOW_MODULE_ID, validDate, crowdName, dumpQueries } return { params } }, // 创建人群时获取选中的人群流转 getDumpQueries() { const { statusIds, all } = this.updater.get() const dumpQueries = [] for (const item of statusIds) { if (item.endStatus.length) { for (const endStatus of item.endStatus) { dumpQueries.push({ rptTitle: 'rpt1', headers: { [all.DEEPLINK_START_STATUS_TEXT]: item.value, [all.DEEPLINK_FINAL_STATUS_TEXT]: endStatus }, targets: 'uv' }) } } } return dumpQueries }, // 直接创建人群 async 'createCrowd'(e) { if (!this.isValid()) { return } try { const { params } = this.getParams() if (!params.dumpQueries.length) { return this._alert('提示', '请至少选择一个流转路径') } this.updater.digest({ createLoading: true }) const models = [ { name: 'api_quickcase_dumpModuleCrowd_post', isJson: true, params } ] await this.fetch(models) this._alert('提示', '恭喜,人群创建成功', () => { this.options.dialog.close() }) } catch (error) { this._alert('错误提示', error.msg || error.message || error) } this.updater.digest({ createLoading: false }) }, 'cancel'(e) { this.options.dialog.close() } })