InviteMission.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. const InviteApi = require('../net/InviteApi');
  2. const WeChat = require('../net/WeChat');
  3. const inviteReward = require('../data/inviteReward');
  4. const { GameNotificationKey, WechatShareType } = require('../utils/GameEnum');
  5. const GameModule = require("../utils/GameModule");
  6. const InvitedItem = require("InvitedItem");
  7. const AlertManager = require('../utils/AlertManager');
  8. cc.Class({
  9. extends: cc.Component,
  10. properties: {
  11. contentNode: cc.Node,
  12. invitedPrefab: cc.Prefab,
  13. invitedScrollViewNode: cc.ScrollView,
  14. listScrollViewNode: cc.ScrollView,
  15. missionPrefab: cc.Prefab,
  16. invitedItemArray: [InvitedItem],
  17. shareButtonNode: cc.Node,
  18. shareTipsLabel: cc.Label
  19. },
  20. // LIFE-CYCLE CALLBACKS:
  21. onLoad() {
  22. if (GameGlobal.winSize.height <= 1000) {
  23. this.contentNode.height = 820;
  24. }
  25. this.giftMap = ['diamond'];
  26. for (var i = 0; i < 10; i++) {
  27. let item = cc.instantiate(this.invitedPrefab);
  28. item = item.getComponent('InvitedItem');
  29. item.node.parent = this.invitedScrollViewNode.content;
  30. this.invitedItemArray.push(item);
  31. }
  32. GameEvent.on(GameNotificationKey.InviteGainAward, this, (model) => {
  33. this.gainActGift(model);
  34. });
  35. if (window.tt != undefined) {
  36. this.shareTipsLabel.string = "发送链接给你的好友,邀请TA来一起玩游戏吧~";
  37. } else if (CC_QQPLAY) {
  38. this.shareTipsLabel.string = "发送链接给你的QQ好友,邀请TA来一起玩游戏吧~";
  39. }
  40. },
  41. start() {
  42. this.getNetworkData();
  43. let scaleAction1 = cc.scaleTo(0.6, 1.2, 1.2);
  44. let scaleAction2 = cc.scaleTo(0.6, 0.8, 0.8);
  45. let seq = cc.repeatForever(cc.sequence(scaleAction1, scaleAction2));
  46. this.shareButtonNode.runAction(seq);
  47. },
  48. onDestroy() {
  49. GameEvent.off(GameNotificationKey.InviteGainAward, this);
  50. },
  51. closeNode() {
  52. GameModule.audioMng.playClickButton();
  53. this.node.destroy();
  54. },
  55. getNetworkData() {
  56. InviteApi.getInviteMissionList((responseData) => {
  57. // console.log("responseData: " + JSON.stringify(responseData));
  58. this.loadData(responseData);
  59. }, (error) => {
  60. console.log('mission error' + error);
  61. });
  62. },
  63. loadData(responseData) {
  64. this.userHeadInfoList = responseData.userHeadInfoList;
  65. this.inviteRewardRecordVoList = responseData.inviteRewardRecordVoList;
  66. this.invitedCount = responseData.invited;
  67. this.layoutInvitedUser();
  68. this.layoutMission();
  69. },
  70. layoutInvitedUser() {
  71. for (var i = 0; i < this.userHeadInfoList.length; i++) {
  72. let item = this.invitedItemArray[i];
  73. let itemModel = this.userHeadInfoList[i];
  74. item.configData(itemModel);
  75. }
  76. },
  77. layoutMission() {
  78. for (var i = 0; i < this.inviteRewardRecordVoList.length; i++) {
  79. let itemModel = this.inviteRewardRecordVoList[i];
  80. for (let mission of inviteReward) {
  81. if (mission.id == itemModel.rid) {
  82. let item = cc.instantiate(this.missionPrefab);
  83. item = item.getComponent('InviteMissionItem');
  84. item.node.parent = this.listScrollViewNode.content;
  85. item.node.width = this.listScrollViewNode.node._contentSize.width;
  86. mission.state = itemModel.state;
  87. item.configData(mission, this.invitedCount);
  88. break;
  89. }
  90. }
  91. }
  92. },
  93. gainActGift(model) {
  94. let diamond = model.diamond;
  95. let gainModel = { 'type': 'diamond', 'text': `钻石 x ${diamond}` };
  96. AlertManager.showActGiftAlert(gainModel.type, gainModel.text);
  97. GameModule.userInfo.updateUserRes({
  98. diamond: parseInt(diamond)
  99. });
  100. },
  101. inviteFriend() {
  102. GameModule.audioMng.playClickButton();
  103. WeChat.shareAction(WechatShareType.InviteFriend, () => {
  104. }, () => {
  105. console.log('分享失败或取消');
  106. });
  107. GameGlobal.isIgnoreShareStatus = true;
  108. },
  109. });