ArtistResident.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.close();
  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.close();
  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 s = cc.sequence(cc.moveTo(0.2, 0, -40).easing(cc.easeCubicActionOut()), cc.moveBy(0.05, 0, -40));
  66. this.content.runAction(s);
  67. },
  68. getNetworkData() {
  69. HomeApi.friendGetArtistsByBuildingId(this.uid, this.buildingInfo.buildingId, (responseData) => {
  70. if (responseData.list === undefined || responseData.list.length === 0) {
  71. this.noArtistTip.active = true;
  72. this.talentBtn.node.active = true;
  73. this.confirmBtn.node.active = false;
  74. } else {
  75. this.talentBtn.node.active = false;
  76. this.confirmBtn.node.active = true;
  77. this._residentList = responseData.list;
  78. this.layout();
  79. }
  80. }, (err) => {
  81. console.log(err);
  82. });
  83. },
  84. layout() {
  85. DWTool.loadResPrefab('./prefabs/artist_resident_item')
  86. .then((result) => {
  87. for (let i = 0; i < this._residentList.length; i++) {
  88. let item = cc.instantiate(result);
  89. item.getComponent(`ArtistResidentItem`).init(this.uid, this.buildingInfo, this.isSelf, this._residentList[i], (artistData) => {
  90. this._currentResidentArtist = artistData;
  91. console.log(this._currentResidentArtist);
  92. });
  93. this.scrollView.content.addChild(item);
  94. }
  95. }).catch((err) => {
  96. console.log(err);
  97. });
  98. },
  99. confirm() {
  100. this.confirmEvent();
  101. },
  102. showTalent() {
  103. this.showTalentEvent();
  104. },
  105. close() {
  106. let finish = cc.callFunc(() => {
  107. this.node.destroy();
  108. }, this)
  109. this.content.runAction(cc.sequence(cc.moveTo(0.2, 0, -cc.view.getVisibleSize().height).easing(cc.easeCubicActionIn()), finish));
  110. // this.node.destroy();
  111. },
  112. // update (dt) {},
  113. });