FriendItem.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { _decorator, Sprite, Label, SpriteFrame, ImageAsset, Texture2D } from 'cc';
  2. import InfiniteCell from '../core/InfiniteList/InfiniteCell';
  3. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  4. import { BitmapFont } from '../core/ui/BitmapFont';
  5. import { ISJSB } from '../Data/platform';
  6. import { FsUtils } from '../FsUtils/FsUtils';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('FriendItem')
  9. export class FriendItem extends InfiniteCell {
  10. @property({ type: Sprite, tooltip: "头像" })
  11. headImg: Sprite;
  12. @property({ type: Label, tooltip: "昵称文本" })
  13. nickNameLabel: Label;
  14. // @property({ type: Label, tooltip: "等级文本" })
  15. // LvLabel: Label;
  16. // @property({ type: Label, tooltip: "关系文本" })
  17. // relationLabel: Label;
  18. @property({ type: BitmapFont, tooltip: "贡献文本" })
  19. contributionLabel: BitmapFont;
  20. private numArr = ["一", "二", "三", "四", "五"];
  21. start() {
  22. }
  23. async UpdateContent(itemData: any) {
  24. if (ISJSB && itemData.avatar) {
  25. let img = await ResourcesUtils.loadRemote<ImageAsset>(itemData.avatar, { ext: ".png" }, this);
  26. const spriteFrame = new SpriteFrame();
  27. const texture = new Texture2D();
  28. texture.image = img;
  29. spriteFrame.texture = texture;
  30. this.headImg.spriteFrame = spriteFrame;
  31. }
  32. this.nickNameLabel.string = FsUtils.beautySub(itemData.nickname, 4);
  33. let lv = itemData.lv ? itemData.lv : 1;
  34. itemData.totalRevenueAmount = itemData.totalRevenueAmount || 0;
  35. this.contributionLabel.string = itemData.totalRevenueAmount.toFixed(0);
  36. }
  37. }