InviteMission.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. },
  19. // LIFE-CYCLE CALLBACKS:
  20. onLoad() {
  21. if (Global.winSize.height <= 1000) {
  22. this.contentNode.height = 820;
  23. }
  24. this.giftMap = ['diamond'];
  25. for (var i = 0; i < 10; i++) {
  26. let item = cc.instantiate(this.invitedPrefab);
  27. item = item.getComponent('InvitedItem');
  28. item.node.parent = this.invitedScrollViewNode.content;
  29. this.invitedItemArray.push(item);
  30. }
  31. GameEvent.on(GameNotificationKey.InviteGainAward, this, (model) => {
  32. this.gainActGift(model);
  33. });
  34. },
  35. start() {
  36. this.getNetworkData();
  37. let scaleAction1 = cc.scaleTo(0.6, 1.2, 1.2);
  38. let scaleAction2 = cc.scaleTo(0.6, 0.8, 0.8);
  39. let seq = cc.repeatForever(cc.sequence(scaleAction1, scaleAction2));
  40. this.shareButtonNode.runAction(seq);
  41. },
  42. onDestroy() {
  43. GameEvent.off(GameNotificationKey.InviteGainAward, this);
  44. },
  45. closeNode() {
  46. GameModule.audioMng.playClickButton();
  47. this.node.destroy();
  48. },
  49. getNetworkData() {
  50. InviteApi.getInviteMissionList((responseData) => {
  51. // console.log("responseData: " + JSON.stringify(responseData));
  52. this.loadData(responseData);
  53. }, (error) => {
  54. console.log('mission error' + error);
  55. });
  56. },
  57. loadData(responseData) {
  58. this.userHeadInfoList = responseData.userHeadInfoList;
  59. this.inviteRewardRecordVoList = responseData.inviteRewardRecordVoList;
  60. this.invitedCount = responseData.invited;
  61. this.layoutInvitedUser();
  62. this.layoutMission();
  63. },
  64. layoutInvitedUser() {
  65. for (var i = 0; i < this.userHeadInfoList.length; i++) {
  66. let item = this.invitedItemArray[i];
  67. let itemModel = this.userHeadInfoList[i];
  68. item.configData(itemModel);
  69. }
  70. },
  71. layoutMission() {
  72. for (var i = 0; i < this.inviteRewardRecordVoList.length; i++) {
  73. let itemModel = this.inviteRewardRecordVoList[i];
  74. for (let mission of inviteReward) {
  75. if (mission.id == itemModel.rid) {
  76. let item = cc.instantiate(this.missionPrefab);
  77. item = item.getComponent('InviteMissionItem');
  78. item.node.parent = this.listScrollViewNode.content;
  79. item.node.width = this.listScrollViewNode.node._contentSize.width;
  80. mission.state = itemModel.state;
  81. item.configData(mission, this.invitedCount);
  82. break;
  83. }
  84. }
  85. }
  86. },
  87. gainActGift(model) {
  88. let diamond = model.diamond;
  89. let gainModel = { 'type': 'diamond', 'text': `钻石 x ${diamond}` };
  90. AlertManager.showActGiftAlert(gainModel.type, gainModel.text);
  91. GameModule.userInfo.updateUserRes({
  92. diamond: parseInt(diamond)
  93. });
  94. },
  95. inviteFriend() {
  96. GameModule.audioMng.playClickButton();
  97. WeChat.shareAction(WechatShareType.InviteFriend, () => {
  98. }, () => {
  99. console.log('分享失败或取消');
  100. });
  101. Global.isIgnoreShareStatus = true;
  102. },
  103. });