WithdrawaGTlItem.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { _decorator, Component, Node, Label, RichText, utils } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('WithdrawaGTlItem')
  4. export class WithdrawaGTlItem extends Component {
  5. @property({ tooltip: "记录类型", type: Node })
  6. public withdrawType: Node;
  7. @property({ tooltip: "记录时间", type: Node })
  8. public withdrawTime: Node;
  9. @property({ tooltip: "记录金额", type: Node })
  10. public money: Node;
  11. start() {
  12. }
  13. /**
  14. * 初始化ui
  15. * @param type 记录类型
  16. * @param time 记录时间
  17. * @param money 金额
  18. */
  19. public onDataChange(data: any) {
  20. // this.withdrawType.getComponent(Label).string = data.type == 1 ? "提现申请" : "贡献红包";
  21. this.withdrawType.getComponent(Label).string = "提现申请";
  22. this.withdrawTime.getComponent(Label).string = this.dateFormat(data.createTime * 1000);
  23. let color = data.value < 0 ? 'ff0000' : '238e23';
  24. this.money.getComponent(RichText).string = "<color=#" + color + ">¥ " + data.value / 10000 + "元</color>";
  25. }
  26. /**
  27. * 时间格式
  28. */
  29. public dateFormat(time: number): string {
  30. let dt = new Date(time);
  31. let y = dt.getFullYear();
  32. let _m = dt.getMonth() + 1;
  33. let m = _m < 10 ? "0" + _m : _m;
  34. let _d = dt.getDate();
  35. let d = _d < 10 ? "0" + _d : _d;
  36. let _h = dt.getHours();
  37. let h = _h < 10 ? "0" + _h : _h;
  38. let _minutes = dt.getMinutes();
  39. let minutes = _minutes < 10 ? "0" + _minutes : _minutes;
  40. let _s = dt.getSeconds();
  41. let s = _s < 10 ? "0" + _s : _s;
  42. return y + "年" + m + "月" + d + "日" + " " + h + "时" + minutes + "分" + s + "秒";
  43. }
  44. }