import Magix from 'magix' import View from 'dmp-new/view' Magix.applyStyle('@./list.less') const BENCHMARK_TYPE_MAP = { 1: { text: '系统预设', desc: '系统预定义标杆池,不可修改,季度更新。' }, 2: { text: '自定义', desc: '自定义品牌池,单个品牌池品牌个数为5个,不可小于5个。品牌池添加后30天内不可修改删除。' } } export default View.extend({ tmpl: '@list.html', init(options) { this.options = options this.observeLocation(['brandId']) }, async render() { const loc = Magix.Router.parse() const { brands, brandsMap } = await this.getBrands() const { brandId = brands[0].value } = loc.params const { list, quotaInfo } = await this.getData(brandId) this.updater.digest({ brandsMap, BENCHMARK_TYPE_MAP, brands, list, brandId, quotaInfo }) }, async getData(brandId) { try { const params = { brandId } const models = [ { name: 'api_deeplink_benchmark_list_get', params } ] const [model] = await this.fetch(models) const data = model.get('data', {}) return data } catch (error) { console.error(error) } }, async getBrands() { const { brands, brandsMap, user, all } = this.updater.get() if (brands && brandsMap) { return { brands, brandsMap } } const models = user.permissions2[all.CUSTOM_BENCHMARK_PERMISSION_KEY] ? { name: 'api_deeplink_vip_brand_list_get', params: { type: 2 } } : { name: 'api_databank_deeplink_get' } const [model] = await this.fetch(models) const _brands = model.get('data', []).filter(item => { return item.status == 1 }) const _brandsMap = Magix.toMap(_brands, 'brandId') return { brands: _brands, brandsMap: _brandsMap } }, 'create'(e) { const { quotaInfo, brandsMap, brandId } = this.updater.get() const brand = brandsMap[brandId] if (quotaInfo.leftCount === 0) { return } const viewPath = '@./dialog/create' const viewOptions = { brand, callback: () => { this.render() } } const dialogOptions = { header: { title: '创建自定义品牌标杆池' }, footer: { enter: true, enterText: '创建新的竞争品牌池', cancel: true }, width: 780 } this.mxModal(viewPath, viewOptions, dialogOptions) }, 'modify'(e) { const { brandsMap, brandId } = this.updater.get() const brand = brandsMap[brandId] const { item } = e.params if (item.isLocked) { return } const viewPath = '@./dialog/create' const viewOptions = { benchmark: item, brand, callback: () => { this.render() } } const dialogOptions = { header: { title: '修改自定义品牌标杆池' }, footer: { enter: true, enterText: '修改竞争品牌池', cancel: true }, width: 780 } this.mxModal(viewPath, viewOptions, dialogOptions) }, 'remove'(e) { const { item } = e.params if (item.isLocked) { return } this.confirm( { title: '提示', content: '确定要删除该标杆品牌池吗?', enterCallback: async () => { try { const { benchmarkId } = item const models = [ { name: 'api_deeplink_benchmark_$id_delete', pathParams: [benchmarkId] } ] const [model] = await this.fetch(models) this.render() } catch (error) { this.alert( { title: '提示', content: error.msg ?? error.message }, { mask: true, type: 'error' } ) } } }, { mask: true } ) }, 'back'(e) { const loc = Magix.Router.parse() Magix.Router.to(loc.get('backPath'), JSON.parse(loc.get('backPathParams'))) }, 'changeBrand'(e) { const { brandId } = this.updater.get() Magix.Router.to({ brandId }) } })