import Magix from 'magix' import * as View from '../../../view' Magix.applyStyle('@./recommend-combines.less') export default View.extend({ tmpl: '@recommend-combines.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) => { let tagInfo = `${selects[0].tagName}:` tagInfo += selects.map(item => { return item.names }).join(',') tags.push({ selects }) tagInfos.push(tagInfo) }) item.tagCombineNames = tagInfos item.tagCombines = tags } // 三个一组 const result = [] let count = -1 data.forEach((item, i) => { if (i % 3 === 0) { count++ } if (result[count]) { result[count].push(item) } else { result[count] = [item] } }) return result } 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, _index } = e.params const { list } = this.updater.get() const data = list[index][_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) } } })