ArtistResidentItem.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. const Api = require('../net/Api');
  2. const { GameNotificationKey } = require("../utils/GameEnum");
  3. const HomeApi = require("../net/HomeApi");
  4. const AlertManager = require("../utils/AlertManager");
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. bgSpriteFrames: [cc.SpriteFrame],
  9. headSprite: cc.Sprite,
  10. nickRichText: cc.RichText,
  11. jobLevelLabel: cc.Label,
  12. jobTitleLabel: cc.Label,
  13. effectLabel: cc.Label,
  14. cancelResidentBtn: cc.Button,
  15. recallArtistBtn: cc.Button,
  16. bgSprite: {
  17. get: function() {
  18. if (!this._bgSprite) {
  19. this._bgSprite = this.getComponent(cc.Sprite);
  20. }
  21. return this._bgSprite;
  22. },
  23. set: function(value) {
  24. this._bgSprite = value;
  25. }
  26. },
  27. flag: {
  28. get: function () {
  29. if (!this._flag) {
  30. this._flag = 0;
  31. }
  32. return this._flag;
  33. },
  34. set: function (value) {
  35. this._flag = value;
  36. this._bgSprite.spriteFrame = this.bgSpriteFrames[value];
  37. }
  38. }
  39. },
  40. init(uid, buildingInfo, isSelf, artistData, selectedCallback) {
  41. this.uid = uid;
  42. this.buildingInfo = buildingInfo;
  43. this.artistData = artistData;
  44. this.isSelf = isSelf;
  45. this.selectedCallback = selectedCallback;
  46. this.jobLevelLabel.string = this.artistData.jobLevel;
  47. this.jobTitleLabel.string = this.artistData.jobName;
  48. if (this.artistData.isStationed === 0) { // 没有任何驻场艺人
  49. this.cancelResidentBtn.node.active = false;
  50. this.recallArtistBtn.node.active = false;
  51. this.bgSprite.spriteFrame = this.bgSpriteFrames[0];
  52. } else if (this.artistData.isStationed === 1) { // 入驻了自己家园
  53. this.cancelResidentBtn.node.active = true;
  54. this.recallArtistBtn.node.active = false;
  55. this.bgSprite.spriteFrame = this.bgSpriteFrames[1];
  56. } else { // 入驻他人家园
  57. this.cancelResidentBtn.node.active = false;
  58. this.recallArtistBtn.node.active = true;
  59. }
  60. this.nickRichText.string = `<color=#584a47>${this.artistData.nick}</c> <img src='50002'/>`;
  61. this.effectLabel.string = `加成效果: 收益增加${this.artistData.addition}%`;
  62. Api.createImageFromUrl(this.artistData.head, (spriteFrame) => {
  63. this.headSprite.spriteFrame = spriteFrame;
  64. }, null);
  65. },
  66. cancelResident() {
  67. this.cancelResidentEvent();
  68. } ,
  69. // 召回自己艺人
  70. recallArtist() {
  71. this.recallArtistEvent();
  72. },
  73. onLoad () {
  74. this.bgSprite = this.getComponent(cc.Sprite);
  75. this.node.on(cc.Node.EventType.TOUCH_END, () => {
  76. this.selectedCallback(this.artistData);
  77. }, this);
  78. this.recallArtistEvent = _.debounce(() => {
  79. AlertManager.showArtistOperationAlert(this.buildingInfo, this.uid, this.isSelf, this.artistData);
  80. }, 1000, true);
  81. this.cancelResidentEvent = _.debounce(() => {
  82. HomeApi.friendExpelRecall(this.artistData.id || this.artistData.uid, (responseData) => {
  83. this.cancelResidentBtn.node.active = false;
  84. // 取消入驻要收取所有金币
  85. GameEvent.fire(GameNotificationKey.RefreshResidentArtistList);
  86. GameEvent.fire(GameNotificationKey.ResidentArtist, this.uid, this.buildingInfo.buildingId);
  87. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.uid, 6);
  88. }, (code, msg) => {
  89. console.log(msg);
  90. });
  91. }, 1000, true);
  92. },
  93. setStyle(uid) {
  94. this.flag = (this.artistData.uid === uid) ? 1 : 0;
  95. },
  96. selectItem() {
  97. this.flag = 1;
  98. this.selectedCallback(this.artistData);
  99. },
  100. start () {
  101. },
  102. // update (dt) {},
  103. });