123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- 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 = `<outline color=white width=2><b><color=#7D4025>X${this.award.diamond}</color></b></outline>`;
- }
- }
- }
- // update (dt) {},
- });
|