import Magix from 'magix' import View from 'dmp-new/view' Magix.applyStyle('@./create.less') export default View.extend({ tmpl: '@create.html', init(options) { this.options = options const me = this function timingClear() { me.timingClear() } function timingBegin() { me.timingBegin() } // 窗口失焦时用户的操作计时作废 window.addEventListener('blur', timingClear) // 聚集时重新操作计时 window.addEventListener('focus', timingBegin) this.on('destroy', e => { window.removeEventListener('blur', timingClear) window.removeEventListener('focus', timingBegin) }) }, // 用户操作计时开始 timingBegin() { this.__durationStart = new Date().getTime() // 记录用户开始创建人群的时间 }, // 用户操作计时清除(页面失焦时) timingClear() { this.__durationStart = undefined }, async render() { const { crowdId, isCopy: _isCopy } = Magix.Router.parse().params const isCopy = _isCopy === 'true' const isEdit = crowdId !== undefined && !isCopy // 用户操作计时开始 this.timingBegin() let crowd if (isEdit || isCopy) { crowd = await this.getCrowd(crowdId) } let stepInfos = [ { label: '选择营销场景', locked: isEdit, subs: [ // 0 { label: '选择营销场景', view: '@./subs/market-scenes', data: { changeScene: remains => { const { stepInfos } = this.updater.get() // 第一步数据保存 Object.assign(stepInfos[0].subs[0].data, remains) // 创建人群步骤数据保存 Object.assign(stepInfos[1].subs[0].data, remains) } } } ], nextTip: '下一步' }, { label: `${isEdit ? '修改' : '新建'}人群`, subs: [ // 1 { titleHide: true, // 不显示标题 view: '@./subs/crowd-set', data: { crowd, isEdit, isCopy, // 点击返回需要将当前选择的场景同步到上一步中 prevFn: ({ sceneType, subSceneType }) => { const { stepInfos } = this.updater.get() Object.assign(stepInfos[0].subs[0].data, { sceneType, subSceneType }) } } } ], prevTip: '上一步', nextTip: '下一步', nextFn: async remains => { const { stepInfos } = this.updater.get() // 创建人群步骤数据保存 Object.assign(stepInfos[1].subs[0].data, remains) // 填写人群信息步骤数据保存 Object.assign(stepInfos[2].subs[0].data, remains) } }, { label: '填写人群信息', subs: [ // 2 { title: '填写人群信息', view: '@./subs/create-crowd', data: { crowd, isEdit, isCopy // view: this } } ], prevTip: '上一步', nextTip: `${isEdit ? '修改' : '创建'}人群`, nextFn: async remains => { const { stepInfos } = this.updater.get() Object.assign(stepInfos[2].subs[0].data, remains) for (const step of stepInfos) { step.locked = true } } }, { label: `${isEdit ? '修改' : '创建'}完成`, subs: [ // 3 { label: `${isEdit ? '修改' : '创建'}完成`, view: '@./subs/completed', data: { isEdit } } ] } ] this.updater.digest({ stepInfos, alreadyStep: 1 }) }, // 修改时获取人群详情 async getCrowd(crowdId) { try { const models = [ { name: 'api_crowd_$id_get', pathParams: [crowdId] } ] const [model] = await this.fetch(models) const data = model.get('data.crowd', {}) return data } catch (error) { console.error(error) } }, 'getDuration'(e) { let srcEvent = e.originalEvent || e srcEvent.setDuration(this.__durationStart) } })