RedPackeItemView.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-03-20 18:39:37
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-08 14:07:54
  6. * @Description: 红包列表item
  7. */
  8. import { _decorator, Node } from 'cc';
  9. import { oops } from 'db://oops-framework/core/Oops';
  10. import { Label } from 'cc';
  11. import { ProgressBar } from 'cc';
  12. import { Sprite } from 'cc';
  13. import VMParent from 'db://oops-framework/libs/model-view/VMParent';
  14. const { ccclass, property } = _decorator;
  15. /** 显示对象控制 */
  16. @ccclass('RedPackeItemView')
  17. export class RedPackeItemView extends VMParent {
  18. @property(Node)
  19. private receiveNode: Node = null!;
  20. @property(Node)
  21. private unReceiveNode: Node = null!;
  22. private lab_title: Label = null!;
  23. private lab_progress: Label = null!;
  24. private pro_progress: ProgressBar = null!;
  25. private sp_icon: Sprite = null!;
  26. private lab_num: Label = null!;
  27. data: any = {
  28. title: "完成任务即可领取红包~",
  29. current: 10,
  30. total: 100,
  31. state: 1,
  32. goods: [
  33. {
  34. type: 1001,
  35. num: 100
  36. }
  37. ]
  38. }
  39. protected start() {
  40. this.setButton();
  41. this.initComponent();
  42. }
  43. private initComponent() {
  44. this.lab_title = this.node.getChildByPath("Bg/lab_title")?.uiLabel!;
  45. this.lab_progress = this.node.getChildByPath("Bg/lab_progress")?.uiLabel!;
  46. this.pro_progress = this.node.getChildByPath("Bg/pro_progress")?.uiProgressBar!;
  47. this.sp_icon = this.node.getChildByPath("Bg/sp_icon")?.uiSprite!;
  48. this.lab_num = this.node.getChildByPath("Bg/lab_num")?.uiLabel!;
  49. }
  50. setItem(data: any, idx: number) {
  51. console.log("setData>>>>>>>>>>>>>", data);
  52. this.data = data;
  53. this.updateData();
  54. }
  55. public getdata() {
  56. return this.data;
  57. }
  58. //更新数据
  59. private updateData() {
  60. console.log("updateData", this.data);
  61. if (this.data.state == 0) {
  62. this.receiveNode.active = false;
  63. this.unReceiveNode.active = true;
  64. } else if (this.data.state == 1) {
  65. this.receiveNode.active = true;
  66. this.unReceiveNode.active = false;
  67. }
  68. this.lab_title.string = this.data.title;
  69. this.lab_progress.string = `${this.data.current}/${this.data.total}`;
  70. this.pro_progress.progress = this.data.current / this.data.total;
  71. // this.sp_icon.spriteFrame = oops.res.getSpriteFrame(this.data.goods[0].type);
  72. this.lab_num.string = this.data.goods[0].num;
  73. }
  74. //进行中按钮
  75. private btn_none() {
  76. oops.gui.toast("完成任务即可领取红包~");
  77. }
  78. //可领取按钮
  79. private btn_receive() {
  80. oops.gui.toast("领取红包~");
  81. //发送领取红包请求
  82. }
  83. }