const StarApi = require('../net/StarApi'); const GameModule = require('../utils/GameModule'); const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; const AlertManager = require('../utils/AlertManager'); var Promise = require('../lib/es6-promise').Promise; cc.Class({ extends: cc.Component, properties: { content: cc.Node, // starItemPrefab: cc.Prefab, starLayout: cc.Layout, // progressBar: cc.ProgressBar, countLabel: cc.Label, percentRichText: cc.RichText, // descNode: cc.Node, //底部信息 discountRichText: cc.RichText, discount50Label: cc.Label, discount30Label: cc.Label }, // LIFE-CYCLE CALLBACKS: onLoad () { if (GameGlobal.winSize.height <= 1000) { this.content.height = 800; } GameEvent.on('show_star_desc', this, (starInfo) => { this.showDescView(starInfo); }); this.isRecalling = false; this.showGiftBag = _.debounce((array) => { AlertManager.showStarGiftBag(array); }, 1000, true); }, onDestroy() { GameModule.audioMng.playClickButton(); GameEvent.off('show_star_desc', this); }, start () { this.getAllStars().then((respondData) => { // console.log(respondData); this.configData(respondData); }).catch((code) => { console.log(code); }); }, /// 网络请求 getAllStars() { return new Promise((resolve, reject) => { // 获取目标用户的建筑 StarApi.getAllStars((respondData) => { resolve(respondData); }, (errCode, errMsg) => { reject(code); }); }) }, configData(respondData) { this.respondData = respondData; if (respondData.userStars.length > 0) { var isUnlockedCount = 0; for (let i = 0; i < respondData.userStars.length; ++i) { let star = respondData.userStars[i]; let item = cc.instantiate(this.starItemPrefab); item = item.getComponent('StarHandbookItem'); item.configData(star); this.starLayout.node.addChild(item.node); if (star.starCount > 0) { isUnlockedCount++; } } let totalCount = respondData.userStars.length; this.countLabel.string = `${isUnlockedCount}/${totalCount} 已收集的明星`; let percent = (isUnlockedCount/totalCount * 100).toFixed(2); this.percentRichText.string = `${percent}%`; this.progressBar.progress = isUnlockedCount/totalCount; } let percent = parseInt(this.respondData.starZk * 100); this.discountRichText.string = `${percent}%`; //遍历礼包折扣 this.discount50Array = []; this.discount30Array = []; this.discount50 = 0; this.discount30 = 0; if (this.respondData.userShops.length > 0) { for (let i = 0; i < this.respondData.userShops.length; ++i) { let shop = this.respondData.userShops[i]; if (shop.zk == 0.5) { this.discount50 += 1; this.discount50Array.push(shop); } else if (shop.zk == 0.3) { this.discount30 += 1; this.discount30Array.push(shop); } } } this.discount50Label.string = `x ${this.discount50}`; this.discount30Label.string = `x ${this.discount30}`; }, closeView() { this.node.destroy(); }, //显示描述信息 showDescView(starInfo) { GameModule.audioMng.playClickButton(); this.descNode.active = true; this.descNode.getComponent('StarHandbookDesc').configData(starInfo); }, closeDescView() { GameModule.audioMng.playClickButton(); this.descNode.active = false; }, refreshData() { for (let i = 0; i < this.respondData.userStars.length; ++i) { let star = this.respondData.userStars[i]; star.starRoomCount = 0; } }, recallAllStar() { if (this.respondData.userStars.length <= 0) { return; } if (this.isRecalling) { return; } this.isRecalling = true; StarApi.recallAllStar((respondData) => { this.isRecalling = false; this.refreshData(); GameEvent.fire(GameNotificationKey.AllStarLeaveRoom); }, (code, msg) => { this.isRecalling = false; GameGlobal.commonAlert.showCommonErrorAlert(`收回失败 \n${msg}`); }); }, //tabIndex:0为5折,1为3折数据 showDiscountGift(event, tabIndex) { if (this.respondData == undefined) { return; } if (tabIndex == 0) { this.showGiftBag(this.discount50Array); } else { this.showGiftBag(this.discount30Array); } }, // update (dt) {}, });