const SignInApi = require("../net/SignInApi"); const GameModule = require("../utils/GameModule"); cc.Class({ extends: cc.Component, properties: { layout: cc.Layout, zIndex: { default: 0, notify(oldValue) { //减少无效赋值 if (oldValue === this.zIndex) { return; } this.node.zIndex = this.zIndex; } }, awardSprite: cc.Sprite, awardRichText: cc.RichText, signInItem: cc.Prefab }, // LIFE-CYCLE CALLBACKS: onLoad () { this.node.zIndex = this.zIndex; this.isSigned = false; }, handleSignIn() { if (this.isSigned) { return; } if (this.award) { this.isSigned = true; GameModule.audioMng.playClickButton(); SignInApi.postSignAward(this.award.signId, (respondData) => { this.isSigned = false; // 更新全局userInfo GameModule.userInfo.diamond += this.award.diamond; GameGlobal.isSignAward = true; this.node.destroy(); }, (errCode, errMsg) => { this.isSigned = false; if (errCode == -3) { this.node.destroy(); } else { GameGlobal.commonAlert.showCommonErrorAlert(`签到失败 \n${errMsg}`); } }); } }, start () { this.getAllSign((respondData) => { this.configData(respondData); }, (code) => { console.log(code); this.node.destroy(); }); }, /// 网络请求 getAllSign(success, fail) { SignInApi.getUserAllSign(success, fail); }, configData(respondData) { this.respondData = respondData; var hasObject = false; if (respondData.userSigns.length > 0) { for (let i = 0; i < respondData.userSigns.length; ++i) { let model = respondData.userSigns[i]; let item = cc.instantiate(this.signInItem); item = item.getComponent('SignInItem'); item.configData(model); this.layout.node.addChild(item.node); if (model.status == 0 && !hasObject) { this.award = model; hasObject = true; } } if (this.award) { this.awardRichText.string = `X${this.award.diamond}`; } } } // update (dt) {}, });