ArtistResident.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. const DWTool = require("../utils/DWTool");
  2. const HomeApi = require("../net/HomeApi");
  3. const { GameNotificationKey } = require("../utils/GameEnum");
  4. const Base64 = require("../lib/Base64").Base64;
  5. const AlertManager = require("../utils/AlertManager");
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. content: cc.Node,
  10. scrollView: cc.ScrollView,
  11. noArtistTip: cc.Node,
  12. talentBtn: cc.Button,
  13. confirmBtn: cc.Button,
  14. },
  15. init(buildingInfo, uid, isSelf) {
  16. this.buildingInfo = buildingInfo;
  17. this.uid = uid;
  18. this.isSelf = isSelf;
  19. },
  20. // LIFE-CYCLE CALLBACKS:
  21. onLoad () {
  22. this._residentList = [];
  23. this._currentResidentArtist = null;
  24. this.getNetworkData();
  25. GameEvent.on(GameNotificationKey.RefreshResidentArtistList, this, () => {
  26. for (let child of this.scrollView.content.children) {
  27. child.destroy();
  28. }
  29. this.getNetworkData();
  30. });
  31. this.confirmEvent = _.debounce(() => {
  32. if (this._currentResidentArtist && !this._currentResidentArtist.isStationed) {
  33. let reportFormInfo = {};
  34. reportFormInfo["artistUid"] = this._currentResidentArtist.uid;
  35. reportFormInfo["buildingId"] = this.buildingInfo.buildingId;
  36. reportFormInfo["buildingLevel"] = this.buildingInfo.level;
  37. reportFormInfo["targetUid"] = this.uid;
  38. HomeApi.friendStation(JSON.stringify(reportFormInfo), (responseData) => {
  39. this.node.destroy();
  40. // 入驻成功, 要将现有的金币收取, 并且刷新入驻艺人列表
  41. GameEvent.fire(GameNotificationKey.ResidentArtist, this.uid, this.buildingInfo.buildingId);
  42. // 触发入驻通知,opt = 5
  43. GameEvent.fire(GameNotificationKey.NoticeRoleOpt, this.uid, 5)
  44. }, (code, msg) => {
  45. // 亲密度不够
  46. if (code === 814) {
  47. AlertManager.showIntimacyBotEnough();
  48. }
  49. console.log(msg);
  50. });
  51. } else {
  52. this.node.destroy();
  53. }
  54. }, 1000, true);
  55. this.showTalentEvent = _.debounce(() => {
  56. this.node.destroy();
  57. AlertManager.showTalentAlert();
  58. }, 1000, true);
  59. },
  60. onDestroy() {
  61. GameEvent.off(GameNotificationKey.RefreshResidentArtistList, this);
  62. },
  63. start() {
  64. this.content.y = -cc.view.getVisibleSize().height;
  65. let bouncesActionArray = [];
  66. let space = 50;
  67. let upAction = cc.moveTo(0.25, cc.v2(0, space));
  68. let downAction = cc.moveBy(0.1, cc.v2(0, -space));
  69. bouncesActionArray.push(upAction);
  70. bouncesActionArray.push(downAction);
  71. this.content.runAction(cc.sequence(bouncesActionArray));
  72. },
  73. getNetworkData() {
  74. HomeApi.friendGetArtistsByBuildingId(this.uid, this.buildingInfo.buildingId, (responseData) => {
  75. if (responseData.list === undefined || responseData.list.length === 0) {
  76. this.noArtistTip.active = true;
  77. this.talentBtn.node.active = true;
  78. this.confirmBtn.node.active = false;
  79. } else {
  80. this.talentBtn.node.active = false;
  81. this.confirmBtn.node.active = true;
  82. this._residentList = responseData.list;
  83. this.layout();
  84. }
  85. }, (err) => {
  86. console.log(err);
  87. });
  88. },
  89. layout() {
  90. DWTool.loadResPrefab('./prefabs/artist_resident_item')
  91. .then((result) => {
  92. for (let i = 0; i < this._residentList.length; i++) {
  93. let item = cc.instantiate(result);
  94. item.getComponent(`ArtistResidentItem`).init(this.uid, this.buildingInfo, this.isSelf, this._residentList[i], (artistData) => {
  95. this._currentResidentArtist = artistData;
  96. console.log(this._currentResidentArtist);
  97. });
  98. this.scrollView.content.addChild(item);
  99. }
  100. }).catch((err) => {
  101. console.log(err);
  102. });
  103. },
  104. confirm() {
  105. this.confirmEvent();
  106. },
  107. showTalent() {
  108. this.showTalentEvent();
  109. },
  110. close() {
  111. this.node.destroy();
  112. },
  113. // update (dt) {},
  114. });