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