12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- const DWTool = require('../utils/DWTool');
- const Notikey = require('../utils/GameEnum').GameNotificationKey;
- const HomeApi = require("../net/HomeApi");
- cc.Class({
- extends: cc.Component,
- properties: {
- noActorTipLabel: cc.Label,
- confirmButton: cc.Button,
- scrollView: cc.ScrollView,
- _otherActorItem: cc.Prefab,
- },
- onLoad() {
- this.artists = [];
- this.itemPool = new cc.NodePool();
- this.getNetwoekData();
- },
- init(artists) {
- this.artists = artists;
- if (this.artists === undefined || this.artists.length === 0) {
- this.noActorTipLabel.node.active = true;
- this.scrollView.node.active = false;
- } else {
- this.noActorTipLabel.node.active = false;
- this.scrollView.node.active = true;
- this.setNodePool().then(this.layout.bind(this));
- }
- },
- setNodePool() {
- return new Promise((resolve, reject) => {
-
- DWTool.loadResPrefab("./prefabs/other_actor_item")
- .then((prefab) => {
- this._otherActorItem = prefab;
- for (let index = 0; index < 21; index++) {
- let item = cc.instantiate(this._otherActorItem);
- this.itemPool.put(item);
- }
- resolve();
- });
- });
- },
- getNetwoekData() {
- HomeApi.friendGetArtists(this.uid, (responseData) => {
- console.log(responseData);
- this.init(responseData.list);
- }, (err) => {
- console.log(err);
- })
- },
- layout() {
- for (let i = 0; i < this.artists.length; i++) {
- let item = null;
- if (this.itemPool.size() > 0) {
- item = this.itemPool.get();
- } else {
- item = cc.instantiate(this._otherActorItem);
- }
- this.scrollView.content.addChild(item);
- item.getComponent('OtherActorItem').updateItem(this.artists[i], i);
- }
- },
- close() {
- this.node.destroy();
- }
- });
|