TalentInviteMissionItem.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. const DWTool = require("../utils/DWTool");
  2. const {GameNotificationKey} = require('../utils/GameEnum');
  3. var TalentApi = require('../net/TalentApi');
  4. //任务状态[0 : 完成可领取, 1 : 未完成, 2 : 完成已领取]
  5. var TalentMissionItemType = cc.Enum({
  6. Gain: 0,
  7. NoFinished: 1,
  8. Finished: 2,
  9. });
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. awardNode1: cc.Node,
  14. awardItemNode1: cc.Node,
  15. countLabel1: cc.Label,
  16. awardNode2: cc.Node,
  17. awardItemNode2: cc.Node,
  18. countLabel2: cc.Label,
  19. awardRichText: cc.RichText,
  20. noButton: cc.Button,
  21. gainButton: cc.Button,
  22. finishButton: cc.Button,
  23. },
  24. // LIFE-CYCLE CALLBACKS:
  25. // onLoad () {},
  26. start () {
  27. },
  28. hideAllButton() {
  29. this.noButton.node.active = false;
  30. this.gainButton.node.active = false;
  31. this.finishButton.node.active = false;
  32. },
  33. onDisable() {
  34. this.awardNode1.active = false;
  35. this.awardNode2.active = false;
  36. },
  37. configData(model, invitedCount) {
  38. this.model = model;
  39. this.hideAllButton();
  40. switch (model.state) {
  41. case TalentMissionItemType.NoFinished:
  42. this.noButton.node.active = true;
  43. break;
  44. case TalentMissionItemType.Finished:
  45. this.finishButton.node.active = true;
  46. break;
  47. case TalentMissionItemType.Gain:
  48. this.gainButton.node.active = true;
  49. break;
  50. }
  51. let coin = model.coin;
  52. let diamond = model.diamond;
  53. let ticket = model.ticket;
  54. if (coin > 0) {
  55. this.awardNode1.active = true;
  56. cc.loader.loadRes("talent/talent_invite_coin", cc.SpriteFrame, (err, spriteFrame) => {
  57. if (err) {
  58. } else {
  59. this.awardItemNode1.getComponent('cc.Sprite').spriteFrame = spriteFrame;
  60. }
  61. });
  62. this.countLabel1.string = DWTool.coinParse(coin);
  63. }
  64. if (diamond > 0) {
  65. if (this.awardNode1.active) {
  66. this.awardNode2.active = true;
  67. cc.loader.loadRes("talent/talent_invite_diamond", cc.SpriteFrame, (err, spriteFrame) => {
  68. if (err) {
  69. } else {
  70. this.awardItemNode2.getComponent('cc.Sprite').spriteFrame = spriteFrame;
  71. }
  72. });
  73. this.countLabel2.string = DWTool.coinParse(diamond);
  74. } else {
  75. this.awardNode1.active = true;
  76. cc.loader.loadRes("talent/talent_invite_diamond", cc.SpriteFrame, (err, spriteFrame) => {
  77. if (err) {
  78. } else {
  79. this.awardItemNode1.getComponent('cc.Sprite').spriteFrame = spriteFrame;
  80. }
  81. });
  82. this.countLabel1.string = DWTool.coinParse(diamond);
  83. }
  84. }
  85. if (ticket > 0) {
  86. if (this.awardNode1.active) {
  87. this.awardNode2.active = true;
  88. cc.loader.loadRes("talent/talent_invite_ticket", cc.SpriteFrame, (err, spriteFrame) => {
  89. if (err) {
  90. } else {
  91. this.awardItemNode2.getComponent('cc.Sprite').spriteFrame = spriteFrame;
  92. }
  93. });
  94. this.countLabel2.string = DWTool.coinParse(ticket);
  95. } else {
  96. this.awardNode1.active = true;
  97. cc.loader.loadRes("talent/talent_invite_ticket", cc.SpriteFrame, (err, spriteFrame) => {
  98. if (err) {
  99. } else {
  100. this.awardItemNode1.getComponent('cc.Sprite').spriteFrame = spriteFrame;
  101. }
  102. });
  103. this.countLabel1.string = DWTool.coinParse(ticket);
  104. }
  105. }
  106. this.awardRichText.string = `签约奖励\n<color=#AF7434 >(艺人:${invitedCount}/${model.count}名)</c>`;
  107. },
  108. gainAward() {
  109. TalentApi.postGainAward(this.model.id, (responseData) => {
  110. this.refreshButtonState();
  111. }, (error) => {
  112. console.log('星探领取 error' + error);
  113. });
  114. },
  115. refreshButtonState() {
  116. this.model.state = TalentMissionItemType.Finished;
  117. this.hideAllButton();
  118. this.finishButton.node.active = true;
  119. GameEvent.fire(GameNotificationKey.TalentGainAward, this.model);
  120. },
  121. // update (dt) {},
  122. });