cc.Class({ extends: cc.Component, properties: { barPointerPrefab: { default: null, type: cc.Prefab }, barCubePrefab: { default: null, type: cc.Prefab }, barPopPrefab: { default: null, type: cc.Prefab }, bar: { default: null, type: cc.Node }, countLabel: { default: null, type: cc.Label }, barCover: { default: null, type: cc.Node }, popTitles: [], currentVal: 1000 }, // LIFE-CYCLE CALLBACKS: onLoad () { let margin = 170; this.countLabel.string = '当前预约人数: ' + this.currentVal; let width = 75; if (this.currentVal <= 10000) { width += margin * this.currentVal / 10000; } else if (this.currentVal > 10000 && this.currentVal <= 30000) { width += (margin + margin * (this.currentVal - 10000) / 20000); } else if (this.currentVal > 30000 && this.currentVal <= 50000) { width += (margin * 2 + margin * (this.currentVal - 30000) / 20000); } else if (this.currentVal > 50000 && this.currentVal <= 55000) { width += (margin * 3 + 68 * (this.currentVal - 50000) / 5000); } else { width = this.bar.width; } this.barCover.width = width; this.popTitle = ['预约\n即送', '1w', '3w', '5w']; let xNum = [-245, -75, 95, 265]; let cubeTypes = ['', 'wood', 'silver', 'gold']; let openVals = [0, 10000, 30000, 50000]; for(let i = 0; i < 4; i++) { var pop = cc.instantiate(this.barPopPrefab); pop.getComponent('barCountPop').title = this.popTitle[i]; if (i === 0) { pop.getComponent('barCountPop').titleLabel.fontSize = 25; } else { pop.getComponent('barCountPop').titleLabel.fontSize = 30; } this.node.addChild(pop); pop.setPosition(cc.v2(xNum[i], 95)); var point = cc.instantiate(this.barPointerPrefab); point.getComponent('barLine').color = (this.currentVal >= openVals[i]) ? 'w' : 'b'; this.bar.addChild(point); point.setPosition(cc.v2(xNum[i], 21)); if (i > 0) { var cube = cc.instantiate(this.barCubePrefab); cube.getComponent('barCube').type = cubeTypes[i]; cube.getComponent('barCube').status = (this.currentVal >= openVals[i]) ? 'o' : 'c'; this.node.addChild(cube); cube.setPosition(cc.v2(xNum[i], -125)); } } }, start () { }, // update (dt) {}, });