// mounted from './create-crowds' import Magix from 'magix' import * as View from '../../../view' Magix.applyStyle('@./speedy-crowds.less') export default View.extend({ tmpl: '@speedy-crowds.html', init (options) { this.options = options }, async render () { const list = await this.getCombine() // 权限 const permissions = Magix.config('bpCustomCrowdPermissions') this.updater.digest({ permissions, list }) }, // 递归查找 selectTagOptionSetDTO 结构里所有的标签 recurSet (selectTagOptionSetDTO, callback) { function recur (tagSets) { for (const set of tagSets) { if (set.selects && set.selects.length) { callback(set.selects) } if (set.selectTagOptionSetDTO && set.selectTagOptionSetDTO.length) { recur(set.selectTagOptionSetDTO) } } } recur(selectTagOptionSetDTO) }, // 获取推荐标签组合 async getCombine () { try { const params = { bizCode: this.options.bizCode, queryBizId: 1 } const models = [{ name: 'appone_api_dmp_tag_recommend_list_post', params }] const [model] = await this.fetch(models) const data = model.get('data.list', []) // 拼接标签组合名称 for (const item of data) { const tags = [] const tagInfos = [] this.recurSet([item.selectTagOptionSetDTO], (selects) => { const tagInfo = { tagName: selects[0].tagName, names: selects.map(item => { return item.names }).join(',') } tags.push({ selects }) tagInfos.push(tagInfo) }) item.tagCombineNames = tagInfos item.tagCombines = tags } return data } catch (error) { this.alert('错误提示', error.msg || error.message || error, null, { mask: true }) } }, _confirm () { return new Promise((resolve, reject) => { const viewPath = '@./speedy-confirm' const viewOptions = { callback: (result) => { resolve(result) } } const dialogOptions = { top: 100, width: 320, closable: false } this.mxDialog(viewPath, viewOptions, dialogOptions) }) }, async 'accept' (e) { const { index } = e.params const { list } = this.updater.get() const data = list[index] let isConfirm = true if (!localStorage.__dmp_speedy_crowds_no_confirm) { isConfirm = await this._confirm() } if (isConfirm) { this.options.dialog.close() this.options.callback(data) } } // async check() { // let { selected, list } = this.updater.get() // let ok = !!selected // let data = list[selected] // let msg = '请选择一个标签组合' // if (ok) { // if (!localStorage.__dmp_speedy_crowds_no_confirm) { // let isConfirm = await this._confirm() // ok = !!isConfirm // } // msg = '' // } // return { // ok, // true or false,是否校验通过,false的时候不关闭按钮 // data, // callback回调数据,可选 // msg // } // } })