CashItem.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import CashOutData from "../datas/CashOutData";
  2. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  3. import UiM from "../manager/UiM";
  4. import CashOut from "../ui/CashOut";
  5. import EffectNode from "../ui/EffectNode";
  6. /** 常规提现item */
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class CashItem extends cc.Component {
  10. //noget--
  11. @property(cc.Node)
  12. noGetNode: cc.Node = null;
  13. @property(cc.Label)
  14. labShowNum: cc.Label = null;
  15. @property(cc.Node)
  16. btnOpen: cc.Node = null;
  17. @property(cc.ProgressBar)
  18. proBar: cc.ProgressBar = null;
  19. //tip
  20. @property(cc.Node)
  21. nodeTime: cc.Node = null;
  22. @property(cc.Label)
  23. labTime: cc.Label = null;
  24. //hasget--
  25. @property(cc.Node)
  26. hasGetNode: cc.Node = null;
  27. @property(cc.Label)
  28. labGetMoney: cc.Label = null;
  29. //car--
  30. @property(cc.Sprite)
  31. car: cc.Sprite = null;
  32. @property(cc.Label)
  33. labCarLv: cc.Label = null;
  34. @property(cc.Label)
  35. labRedCode: cc.Label = null;
  36. hasGet: boolean = false
  37. cfg = null
  38. start() {
  39. }
  40. init(cfg, hasGet, redCode, amount) {
  41. this.cfg = cfg
  42. this.hasGet = hasGet
  43. cc.loader.loadRes('carPic/side/side_' + cfg.type_value, cc.SpriteFrame, (err, assets) => {
  44. if (err) {
  45. cc.error(err);
  46. return;
  47. }
  48. this.car.spriteFrame = assets;
  49. })
  50. this.labCarLv.string = `${cfg.type_value}`
  51. this.noGetNode.active = !this.hasGet
  52. this.hasGetNode.active = this.hasGet
  53. this.labRedCode.string = ""
  54. //已经领取
  55. if (this.hasGet) {
  56. this.labRedCode.string = redCode
  57. this.labGetMoney.string = `${(amount * 0.01).toFixed(2)}`
  58. }
  59. else {
  60. this.labShowNum.string = cfg.moneyshow
  61. this.nodeTime.active = true
  62. let days = Number(cfg.time) - GameM.commonData.loginDays
  63. if (days <= 0) {
  64. days = 0
  65. }
  66. else if (days == 1) {
  67. days = 1
  68. }
  69. else {
  70. if (Number(cfg.time) > 30) {
  71. days = 30
  72. } else {
  73. days = Number(cfg.time)
  74. }
  75. }
  76. if (days == 0) {
  77. // this.labTime.string = '今日可领'
  78. let dis = cfg.type_value - GameM.commonData.maxCarLevel
  79. this.labTime.string = `还差${dis}级`
  80. }
  81. else if (days == 1) {
  82. this.labTime.string = '次日领取'
  83. }
  84. else {
  85. this.labTime.string = `${days}日领取`
  86. }
  87. //可领取
  88. if (GameM.commonData.maxCarLevel >= cfg.type_value && days == 0) {
  89. this.btnOpen.active = true
  90. this.proBar.node.active = false
  91. this.nodeTime.active = false
  92. this.labShowNum.node.y = 160
  93. }
  94. else {
  95. this.btnOpen.active = false
  96. this.proBar.node.active = true
  97. this.nodeTime.active = true
  98. this.labShowNum.node.y = 135
  99. let pro = GameM.commonData.maxCarLevel / cfg.type_value
  100. if (pro > 1) {
  101. pro = 1
  102. }
  103. this.proBar.progress = pro
  104. }
  105. }
  106. }
  107. setRedCode(withdrawalCode) {
  108. this.labRedCode.string = withdrawalCode
  109. }
  110. clickOpen() {
  111. GameM.audioM.playEffect(AUDIO_TYPE.button)
  112. this.goCash()
  113. }
  114. goCash() {
  115. if (GameM.commonData.isAuth) {
  116. if (GameM.commonData.redMoney < 3000) {
  117. EffectNode.instance.PlayTip('红包币不足')
  118. return
  119. }
  120. // CashOutData.Instance.checkDefeatBoss(this.cfg)
  121. if (CashOutData.Instance.checkShowTip(this.cfg)) {
  122. let curCashCfg = CashOutData.Instance.getCashByIndex(this.cfg.index)
  123. if (curCashCfg) {
  124. UiM.Instance.cashNode.getComponent(CashOut).onTixian(curCashCfg)
  125. }
  126. }
  127. }
  128. else {
  129. UiM.Instance.cashNode.getComponent(CashOut).showAuth()
  130. }
  131. }
  132. clickMonster() {
  133. GameM.audioM.playEffect(AUDIO_TYPE.button)
  134. if (CashOutData.Instance.checkShowTip(this.cfg)) {
  135. this.goCash()
  136. }
  137. }
  138. }