FriendRecommendItem .js 3.6 KB

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