FriendRecommendItem .js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. const Api = require('../net/Api');
  2. var FriendApi = require('../net/FriendSystemApi');
  3. var DWTool = require('../utils/DWTool');
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. bgSprite: cc.Sprite,
  8. headSprite: cc.Sprite,
  9. nickLabel: cc.Label,
  10. starCountLabel: cc.Label,
  11. genderIcon: cc.Sprite,
  12. commonFriend1: cc.Node,
  13. commonFriend2: cc.Node,
  14. commonFriend3: cc.Node,
  15. commonFriendLabel: cc.Label,
  16. addFriendButton: cc.Button,
  17. _friendList: null,
  18. _itemId: 0,
  19. },
  20. // LIFE-CYCLE CALLBACKS:
  21. onLoad() {
  22. },
  23. setFriendList(friendList) {
  24. this._friendList = friendList;
  25. },
  26. setListViewAdapter(listViewAdapter) {
  27. this._listViewAdapter = listViewAdapter;
  28. },
  29. /**
  30. * gender [int]
  31. * head [string]
  32. * nick [string]
  33. * stars [int]
  34. * uid [int]
  35. * */
  36. updateItem(userInfo, itemId) {
  37. this._itemId = itemId;
  38. this.user = userInfo;
  39. DWTool.setGenderIcon(userInfo.gender).then((spriteFrame) => {
  40. this.genderIcon.spriteFrame = spriteFrame;
  41. }, (error) => {
  42. this.genderIcon.node.active = false;
  43. });
  44. this.nickLabel.string = userInfo.nick;
  45. this.starCountLabel.string = userInfo.stars;
  46. Api.createImageFromUrl(userInfo.head, (spriteFrame) => {
  47. this.headSprite.spriteFrame = spriteFrame;
  48. }, (err) => {
  49. this.headSprite.spriteFrame = null;
  50. });
  51. // let addBg = this.user.sendedApply === undefined ? this._addFriendBg : this._sendedBg;
  52. // cc.loader.loadRes(addBg, cc.SpriteFrame, (err, spriteFrame) => {
  53. // this.addFriendButton.getComponent(cc.Sprite).spriteFrame = spriteFrame;
  54. // });
  55. if (userInfo.commons != undefined && userInfo.commons != null && userInfo.commons.length > 0) {
  56. this.commonFriendLabel.string = '...' + userInfo.commons.length + '个共同好友';
  57. // this.commonFriend1.active = true;
  58. // this.commonFriend1.getComponent('CommonFriend').setAvatar(userInfo.commons[0].head);
  59. // if (userInfo.commons.length > 1) {
  60. // this.commonFriend2.active = true;
  61. // this.commonFriend2.getComponent('CommonFriend').setAvatar(userInfo.commons[1].head);
  62. // } else {
  63. // this.commonFriend2.active = false;
  64. // this.commonFriend3.active = false;
  65. // }
  66. // if (userInfo.commons.length > 2) {
  67. // this.commonFriend3.active = true;
  68. // this.commonFriend3.getComponent('CommonFriend').setAvatar(userInfo.commons[1].head);
  69. // } else {
  70. // this.commonFriend3.active = false;
  71. // }
  72. // } else {
  73. // this.commonFriend1.active = false;
  74. // this.commonFriend2.active = false;
  75. // this.commonFriend3.active = false;
  76. // this.commonFriendLabel.string = '...0个共同好友';
  77. }
  78. },
  79. start() {
  80. },
  81. deleteItem() {
  82. FriendApi.processApply(this.user.uid, -1);
  83. this._listViewAdapter.removeItem(this);
  84. },
  85. friendApply() {
  86. if (this.user.sendedApply === undefined) {
  87. this.user.sendedApply = true;
  88. FriendApi.friendApply(this.user.uid, () => {
  89. this.addFriendButton.interactable = false;
  90. });
  91. }
  92. },
  93. // update (dt) {},
  94. });