RedBagCashItem.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { DataEventId, GameProp, RewardState } from "../../data/GameData";
  2. import { CDataType } from "../../data/module/RedBagCashData";
  3. const { ccclass, property } = cc._decorator;
  4. /**
  5. * 常规提现条目
  6. * @author 薛鸿潇
  7. */
  8. @ccclass
  9. export default class RedBagCashItem extends cc.Component {
  10. @property({ displayName: '已领取', type: cc.Node })
  11. node_none: cc.Node = null;
  12. @property({ displayName: '未达成', type: cc.Node })
  13. node_lock: cc.Node = null;
  14. @property({ displayName: '可领取', type: cc.Node })
  15. node_unlock: cc.Node = null;
  16. @property({ displayName: '红包数量', type: cc.Label })
  17. lbl_red_value: cc.Label = null;
  18. @property({ displayName: '毛币数量', type: cc.Label })
  19. lbl_rmb_value: cc.Label = null;
  20. /** 条目数据 */
  21. private item_data: CDataType = null;
  22. onLoad() {
  23. }
  24. start() {
  25. }
  26. /**
  27. * 初始化数据
  28. */
  29. public async setItemData(item_data) {
  30. // if (this.item_data == null && item_data.index == 1) {
  31. // mk.event.register("event_guide", this.clickGuide.bind, this);
  32. // }
  33. await this.initStyle(item_data);
  34. }
  35. private clickGuide(data: string) {
  36. if (data == "2_2") {
  37. this.clickCashOP();
  38. }
  39. }
  40. /**
  41. * 初始化样式
  42. * @param item_data 条目数据
  43. */
  44. private initStyle(item_data) {
  45. this.item_data = item_data;
  46. this.lbl_red_value.string = `${this.item_data.type_value}`;
  47. let rmb_value = this.item_data.money / 100;
  48. rmb_value = rmb_value > 1 ? rmb_value : parseFloat(rmb_value.toFixed(2))
  49. this.lbl_rmb_value.string = rmb_value + '元';
  50. if (this.item_data.state === RewardState.none) {
  51. // 已提现
  52. this.node_none.active = true;
  53. this.node_lock.active = false;
  54. this.node_unlock.active = false;
  55. } else if (this.item_data.state === RewardState.lock) {
  56. // 未达成
  57. this.node_none.active = false;
  58. this.node_lock.active = true;
  59. this.node_unlock.active = false;
  60. } else if (this.item_data.state === RewardState.unlock) {
  61. // 已解锁
  62. this.node_none.active = false;
  63. this.node_lock.active = false;
  64. this.node_unlock.active = true;
  65. }
  66. }
  67. /**
  68. * 提现操作
  69. */
  70. private clickCashOP() {
  71. // if (!gData.redBagCash.cash_enable) return;
  72. if (this.item_data.index > gData.redBagCash.cash_bar + 1) {
  73. mk.tip.pop('请按顺序提现');
  74. return;
  75. }
  76. gData.redBagCash.cashOP();
  77. }
  78. onDestroy() {
  79. mk.event.remove("event_guide", this.clickGuide, this);
  80. }
  81. }