OtherArtistList.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const DWTool = require('../utils/DWTool');
  2. const Notikey = require('../utils/GameEnum').GameNotificationKey;
  3. const HomeApi = require("../net/HomeApi");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. content: cc.Node,
  8. noActorTipLabel: cc.Label,
  9. confirmButton: cc.Button,
  10. scrollView: cc.ScrollView,
  11. _otherActorItem: cc.Prefab,
  12. },
  13. onLoad() {
  14. this.node.height = cc.view.getVisibleSize().height;
  15. this.contentY = (this.content.height - this.node.height) / 2;
  16. this.artists = [];
  17. this.itemPool = new cc.NodePool();
  18. this.getNetwoekData();
  19. this.content.y = -cc.view.getVisibleSize().height;
  20. let s = cc.sequence(cc.moveTo(0.2, 0, this.contentY + 20).easing(cc.easeCubicActionOut()), cc.moveBy(0.05, 0, -20));
  21. this.content.runAction(s);
  22. },
  23. init(artists) {
  24. this.artists = artists;
  25. if (this.artists === undefined || this.artists.length === 0) {
  26. this.noActorTipLabel.node.active = true;
  27. this.scrollView.node.active = false;
  28. } else {
  29. this.noActorTipLabel.node.active = false;
  30. this.scrollView.node.active = true;
  31. this.setNodePool().then(this.layout.bind(this));
  32. }
  33. },
  34. setNodePool() {
  35. return new Promise((resolve, reject) => {
  36. DWTool.loadResPrefab("./prefabs/other_artist_item")
  37. .then((prefab) => {
  38. this._otherActorItem = prefab;
  39. for (let index = 0; index < 21; index++) {
  40. let item = cc.instantiate(this._otherActorItem);
  41. this.itemPool.put(item);
  42. }
  43. resolve();
  44. });
  45. });
  46. },
  47. getNetwoekData() {
  48. HomeApi.friendGetArtists(this.uid, (responseData) => {
  49. console.log(responseData);
  50. this.init(responseData.list);
  51. }, (err) => {
  52. console.log(err);
  53. })
  54. },
  55. layout() {
  56. for (let i = 0; i < this.artists.length; i++) {
  57. let item = null;
  58. if (this.itemPool.size() > 0) {
  59. item = this.itemPool.get();
  60. } else {
  61. item = cc.instantiate(this._otherActorItem);
  62. }
  63. this.scrollView.content.addChild(item);
  64. item.getComponent('OtherArtistItem').updateItem(this.artists[i], i, () => {
  65. this.node.destroy();
  66. });
  67. }
  68. },
  69. close() {
  70. if (this.node && this.node.parent) {
  71. let finish = cc.callFunc(() => {
  72. this.node.destroy();
  73. }, this)
  74. this.content.runAction(cc.sequence(cc.moveTo(0.2, 0, -cc.view.getVisibleSize().height).easing(cc.easeCubicActionIn()), finish));
  75. }
  76. }
  77. });