let ButtonSelect1 = require('ButtonSelect1') let ViewBase = require('ViewBase') cc.Class({ extends: ViewBase, properties: { button1: { default: null, type: ButtonSelect1, serializable: true, }, button2: { default: null, type: ButtonSelect1, serializable: true, }, button3: { default: null, type: ButtonSelect1, serializable: true, }, button4: { default: null, type: ButtonSelect1, serializable: true, }, viewContent: { default: null, type: cc.Node, serializable: true, } }, onLoad () { this.buttons = [ this.button1, this.button2, this.button3, this.button4, ]; this.views = [ {type:JMC.UIEnum.DreamPopular, view:null, initing:false}, {type:JMC.UIEnum.DreamBrilliant, view:null, initing:false}, {type:JMC.UIEnum.DreamDropRecord, view:null, initing:false}, {type:JMC.UIEnum.DreamStatistics, view:null, initing:false}, ]; this.curViewType = null this.onClickTitle(null, "0") }, onClickTitle(event, customEventData) { let index = parseInt(customEventData) this.updateButtonSelect(index); this.curViewType = index; this.createOrShowView(this.curViewType) }, updateButtonSelect(index) { for (let i = 0; i < this.buttons.length; i++) { const b = this.buttons[i]; b.setSelect(index == i) } }, createOrShowView(type) { let viewData = this.views[type] for (let vd of this.views) { if (vd.view == null) { continue } vd.view.active = false; } if (viewData.initing) { return } if (viewData.view != null) { viewData.view.active = true; return } viewData.initing = true let self = this this.createComponent(viewData.type, this.viewContent, null, function(node, status) { if (status != 'ok') { return } viewData.view = node viewData.initing = false node.active = self.curViewType == type }) } // update (dt) {}, });