FriendHelpItem.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const {QuestMainMissionType, GameNotificationKey} = require("../utils/GameEnum");
  2. const DWTool = require('../utils/DWTool');
  3. const InviteApi = require('../net/InviteApi');
  4. const GameModule = require("../utils/GameModule");
  5. const TapTapTool = require("../utils/TapTapTool");
  6. const GameRedDot = require('../utils/GameEnum').GameRedDot;
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. friendCountRichText: cc.RichText,
  11. timeRichText: cc.RichText,
  12. noButton: cc.Button,
  13. gainButton: cc.Button,
  14. finishButton: cc.Button,
  15. },
  16. // LIFE-CYCLE CALLBACKS:
  17. // onLoad () {},
  18. start () {
  19. },
  20. configData(model) {
  21. this.model = model;
  22. this.hideAllButton();
  23. switch (model.status) {
  24. case QuestMainMissionType.NoFinished:
  25. this.noButton.node.active = true;
  26. break;
  27. case QuestMainMissionType.AlreadyGet:
  28. this.finishButton.node.active = true;
  29. break;
  30. case QuestMainMissionType.CanGain:
  31. this.gainButton.node.active = true;
  32. break;
  33. }
  34. this.friendCountRichText.string = `<b>${model.count}位好友已成功点击</b>`;
  35. var timeString = model.time / 60;
  36. if (DWTool.isDot(timeString)) {
  37. timeString = timeString.toFixed(2);
  38. }
  39. this.timeRichText.string = `<b><color=#61250e>${timeString}分钟</color></b>`;
  40. },
  41. hideAllButton() {
  42. this.noButton.node.active = false;
  43. this.gainButton.node.active = false;
  44. this.finishButton.node.active = false;
  45. },
  46. gainAward() {
  47. InviteApi.postFriendGainAward(this.model.rewardId, (responseData) => {
  48. if (responseData.isCancel) {
  49. TapTapTool.removeRedDot(GameRedDot.friendAward);
  50. }
  51. this.refreshButtonState();
  52. let isNew = true;
  53. for (let i = 0; i < Global._timeInformations.length; ++ i) {
  54. let information = Global._timeInformations[i];
  55. if (information.type == 3) {
  56. /// 如果是已经使用过的直接刷新时间就可以啦
  57. information.cdTime = Global.friendRewardCdTime;
  58. isNew = false;
  59. break;
  60. }
  61. }
  62. if (isNew) {
  63. let messageItem = {'cdTime': Global.friendRewardCdTime, 'type': 3};
  64. Global._timeInformations.push(messageItem);
  65. GameEvent.fire(GameNotificationKey.GameUpdateMessageList, 1, true);
  66. }
  67. }, (error) => {
  68. Global.commonAlert.showCommonErrorAlert("领取失败");
  69. });
  70. },
  71. refreshButtonState() {
  72. GameModule.audioMng.playGetAward();
  73. this.model.status = QuestMainMissionType.AlreadyGet;
  74. this.hideAllButton();
  75. this.finishButton.node.active = true;
  76. Global.friendRewardCdTime += this.model.time * 1000;
  77. GameEvent.fire(GameNotificationKey.GainFriendHelpClick);
  78. }
  79. // update (dt) {},
  80. });