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