const {QuestMainMissionType} = require("../utils/GameEnum");
const DWTool = require('../utils/DWTool');
const InviteApi = require('../net/InviteApi');
const GameModule = require("../utils/GameModule");
cc.Class({
extends: cc.Component,
properties: {
friendCountRichText: cc.RichText,
timeRichText: cc.RichText,
noButton: cc.Button,
gainButton: cc.Button,
finishButton: cc.Button,
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start () {
},
configData(model) {
this.model = model;
this.hideAllButton();
switch (model.status) {
case QuestMainMissionType.NoFinished:
this.noButton.node.active = true;
break;
case QuestMainMissionType.Finished:
this.finishButton.node.active = true;
break;
case QuestMainMissionType.Gain:
this.gainButton.node.active = true;
break;
}
this.friendCountRichText.string = `${model.count}位好友已成功点击`;
var timeString = model.time / 60;
if (DWTool.isDot(timeString)) {
timeString = timeString.toFixed(2);
}
this.timeRichText.string = `${timeString}分钟`;
},
hideAllButton() {
this.noButton.node.active = false;
this.gainButton.node.active = false;
this.finishButton.node.active = false;
},
gainAward() {
InviteApi.postFriendGainAward(this.model.rewardId, (responseData) => {
// if (responseData.isCancel) {
// TapTapTool.removeRedDot(GameRedDot.inviteFriend);
// }
this.refreshButtonState();
}, (error) => {
Global.commonAlert.showCommonErrorAlert("领取失败");
});
},
refreshButtonState() {
GameModule.audioMng.playGetAward();
this.model.state = QuestMainMissionType.Finished;
this.hideAllButton();
this.finishButton.node.active = true;
// GameEvent.fire(GameNotificationKey.InviteGainAward, this.model);
},
// update (dt) {},
});