UserInformationTimeline.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. var UserInformationApi = require('../net/UserInformationApi');
  2. var {UserInformationType} = require('../utils/GameEnum');
  3. var TimelineItem = require("UserInformationTimelineItem");
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. emptyNode: cc.Node,
  8. scrollViewNode: cc.ScrollView,
  9. timelinePrefab: cc.Prefab,
  10. itemArray: [TimelineItem],
  11. },
  12. // LIFE-CYCLE CALLBACKS:
  13. init() {
  14. },
  15. onLoad () {
  16. },
  17. onDisable() {
  18. for (let item of this.itemArray) {
  19. item.node.active = false;
  20. }
  21. this.scrollViewNode.scrollToTop();
  22. this.emptyNode.active = false;
  23. },
  24. start () {
  25. },
  26. loadUserTimeline(uid) {
  27. this.uid = uid;
  28. this.getNetworkData();
  29. },
  30. //获取个人信息
  31. getNetworkData() {
  32. UserInformationApi.getTimelineList(this.uid, (responseData)=> {
  33. // console.log("timeline responseData: " + JSON.stringify(responseData));
  34. this.configData(responseData);
  35. }, (error) => {
  36. console.log('error' + error);
  37. this.loadDataError();
  38. });
  39. },
  40. configData(responseData) {
  41. for (let item of this.itemArray) {
  42. item.node.active = false;
  43. }
  44. this.dataList = responseData.list;
  45. if (this.dataList == undefined || this.dataList.length == 0) {
  46. this.emptyNode.active = true;
  47. this.scrollViewNode.node.active = false;
  48. } else {
  49. this.emptyNode.active = false;
  50. this.scrollViewNode.node.active = true;
  51. this.loadItemData()
  52. }
  53. },
  54. loadDataError() {
  55. for (let item of this.itemArray) {
  56. item.node.active = false;
  57. }
  58. this.emptyNode.active = true;
  59. this.scrollViewNode.node.active = false;
  60. },
  61. loadItemData() {
  62. for (var i = 0; i < this.dataList.length; i++) {
  63. let item = null;
  64. if (this.itemArray[i]) {
  65. item = this.itemArray[i];
  66. item.node.active = true;
  67. } else {
  68. item = cc.instantiate(this.timelinePrefab);
  69. item = item.getComponent('UserInformationTimelineItem');
  70. item.node.parent = this.scrollViewNode.content;
  71. this.itemArray.push(item);
  72. }
  73. let itemModel = this.dataList[i];
  74. item.configData(itemModel);
  75. }
  76. }
  77. // update (dt) {},
  78. });