TalentMission.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. var TalentApi = require('../net/TalentApi');
  2. const wechat = require('../net/WeChat');
  3. const inviteMission = require('../data/inviteReward');
  4. const { GameNotificationKey } = require('../utils/GameEnum');
  5. const GameModule = require("../utils/GameModule");
  6. const FriendSystemApi = require('../net/FriendSystemApi');
  7. var InvitedItem = require("TalentInvitedItem");
  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. //
  18. actGift: {
  19. tooltip: '活跃度弹出层',
  20. default: null,
  21. type: cc.Node
  22. },
  23. actGiftFrames: {
  24. tooltip: '奖品大图',
  25. default: [],
  26. type: [cc.SpriteFrame]
  27. },
  28. actGiftSprite: cc.Sprite,
  29. actGiftLabel: cc.Label,
  30. },
  31. // LIFE-CYCLE CALLBACKS:
  32. onLoad() {
  33. this.giftMap = ['coin', 'diamond', 'ticket'];
  34. for (var i = 0; i < 10; i++) {
  35. let item = cc.instantiate(this.invitedPrefab);
  36. item = item.getComponent('TalentInvitedItem');
  37. item.node.parent = this.invitedScrollViewNode.content;
  38. this.invitedItemArray.push(item);
  39. }
  40. GameEvent.on(GameNotificationKey.TalentGainAward, this, (model) => {
  41. this.gainActGift(model);
  42. });
  43. },
  44. start() {
  45. },
  46. onDisable() {
  47. for (let child of this.listScrollViewNode.content.children) {
  48. child.destroy();
  49. }
  50. },
  51. // update (dt) {},
  52. init() {
  53. this.node.parent = cc.find('Canvas');
  54. this.node.active = true;
  55. this.node.setContentSize(cc.view.getVisibleSize());
  56. this.contentNode.y = -cc.view.getVisibleSize().height;
  57. let action = cc.sequence(cc.moveTo(0.2, 0, 0).easing(cc.easeCubicActionOut()), cc.callFunc(() => {
  58. this.getNetworkData();
  59. }));
  60. this.contentNode.runAction(action);
  61. },
  62. closeNode() {
  63. let finish = cc.callFunc(() => {
  64. this.node.active = false;
  65. }, this);
  66. this.contentNode.runAction(cc.sequence(cc.moveTo(0.2, 0, -cc.view.getVisibleSize().height).easing(cc.easeCubicActionIn()), finish));
  67. },
  68. getNetworkData() {
  69. TalentApi.getTalentMissionList((responseData) => {
  70. // console.log("responseData: " + JSON.stringify(responseData));
  71. this.loadData(responseData);
  72. }, (error) => {
  73. console.log('talentmission error' + error);
  74. });
  75. },
  76. loadData(responseData) {
  77. this.userHeadInfoList = responseData.userHeadInfoList;
  78. this.inviteRewardRecordVoList = responseData.inviteRewardRecordVoList;
  79. this.invitedCount = responseData.invited;
  80. this.layoutInvitedUser();
  81. this.layoutMission();
  82. },
  83. layoutInvitedUser() {
  84. for (var i = 0; i < this.userHeadInfoList.length; i++) {
  85. let item = this.invitedItemArray[i];
  86. let itemModel = this.userHeadInfoList[i];
  87. item.configData(itemModel);
  88. }
  89. },
  90. layoutMission() {
  91. for (var i = 0; i < this.inviteRewardRecordVoList.length; i++) {
  92. let itemModel = this.inviteRewardRecordVoList[i];
  93. for (let mission of inviteMission) {
  94. if (mission.id == itemModel.rid) {
  95. let item = cc.instantiate(this.missionPrefab);
  96. item = item.getComponent('TalentInviteMissionItem');
  97. item.node.parent = this.listScrollViewNode.content;
  98. item.node.width = this.listScrollViewNode.node._contentSize.width;
  99. mission.state = itemModel.state;
  100. item.configData(mission, this.invitedCount);
  101. break;
  102. }
  103. }
  104. }
  105. },
  106. inviteArtist() {
  107. wechat.inviteArtistPromise().then(() => {
  108. FriendSystemApi.shareSuccessNotice();
  109. });
  110. },
  111. /**
  112. * 显示领取活跃度奖励动画
  113. * @param {string} type {coin: 金币, diamond: 钻石, ticket: 艺人券,}
  114. */
  115. showActGift(type, showText) {
  116. this.actGift.active = true;
  117. this.giftMap.forEach((value, index) => {
  118. if (type == value) {
  119. this.actGiftSprite.spriteFrame = this.actGiftFrames[index];
  120. if (showText) {
  121. this.actGiftLabel.node.active = true;
  122. this.actGiftLabel.string = showText;
  123. } else {
  124. this.actGiftLabel.node.active = false;
  125. }
  126. }
  127. })
  128. },
  129. hideActGift() {
  130. this.showArray.shift();
  131. if (this.showArray.length > 0) {
  132. let itemModel = this.showArray[0];
  133. this.showActGift(itemModel.type, itemModel.count);
  134. } else {
  135. this.actGift.active = false;
  136. }
  137. },
  138. gainActGift(model) {
  139. this.showArray = [];
  140. let coin = model.coin;
  141. let diamond = model.diamond;
  142. let ticket = model.ticket;
  143. if (coin > 0) {
  144. let type = { 'type': 'coin', 'count': `金币 x ${coin}` };
  145. this.showArray.push(type);
  146. }
  147. if (diamond > 0) {
  148. let type = { 'type': 'diamond', 'count': `钻石 x ${diamond}` };
  149. this.showArray.push(type);
  150. }
  151. if (ticket > 0) {
  152. let type = { 'type': 'ticket', 'count': `艺人券 x ${ticket}` };
  153. this.showArray.push(type);
  154. }
  155. if (this.showArray.length > 0) {
  156. let itemModel = this.showArray[0];
  157. this.showActGift(itemModel.type, itemModel.count);
  158. }
  159. GameModule.userInfo.updateUserRes({
  160. grossIncome: parseInt(coin),
  161. diamond: parseInt(diamond),
  162. ticket: parseInt(ticket),
  163. });
  164. },
  165. });