import Magix from 'magix' import View from 'dmp-new/view' Magix.applyStyle('@./create-crowd.less') export default View.extend({ tmpl: '@create-crowd.html', init(options) { this.options = options }, async render() { // const loc = Magix.Router.parse() const { Dayjs } = this.updater.get() const validDate = Dayjs().add(29, 'd').format('YYYY-MM-DD') const minDate = Dayjs().format('YYYY-MM-DD') const maxDate = Dayjs().add(1, 'y').format('YYYY-MM-DD') this.updater.digest({ minDate, maxDate, validDate }) }, async 'confirm'(e) { if (!this.isValid()) { return } const { params } = this.options const { validDate, crowdName } = this.updater.get() Object.assign(params, { validDate, crowdName }) try { this.updater.digest({ loading: true }) const models = [ { name: 'api_quickcase_dumpModuleCrowd_post', isJson: true, params } ] const [model] = await this.fetch(models) // const taskId = model.get('data') // 轮询查看任务运行状态 - 保存接口直接轮询状态了。 // await this.pollingTaskStatus(taskId) this._alert( { title: '创建成功', content: '人群创建成功,您可以在我的人群列表查看新创建的人群。', // 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 }) }, // 创建人群完毕后轮询任务状态 // pollingTaskStatus (taskId) { // return new Promise((resolve, reject) => { // async function polling () { // try { // // taskStatus: RUNNING: 运行中,SUCCESS: 成功,FAIL:失败 // const taskStatus = await this.checkTaskStatus(taskId) // switch (taskStatus) { // case 'RUNNING': // setTimeout(() => { // polling.bind(this)() // }, 1000) // break // case 'FAIL': // reject(new Error('人群创建失败')) // break // case 'SUCCESS': // resolve(taskStatus) // break // } // } catch (error) { // return reject(error) // } // } // polling.bind(this)() // }) // }, // async checkTaskStatus (taskId) { // const { params } = this.options // const { bp } = params // const models = [{ // name: 'api_quickcase_dumpModuleCrowd_status_get', // params: { // bp, // taskId // } // }] // const [model] = await this.fetch(models) // const data = model.get('data') // return data // }, 'cancel'(e) { this.options.dialog.close() } })