CashRecordNode.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /** 提现记录界面 */
  2. import { HTTP_TYPE } from "../datas/CommonData";
  3. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  4. import UiM, { PANEL_NAME } from "../manager/UiM";
  5. import RecordItem from "../prefabs/RecordItem";
  6. import LogUtil from "../utils/LogUtil";
  7. import { Utils } from "../utils/Utils";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class CashRecordNode extends cc.Component {
  11. @property(cc.Node)
  12. recordContent: cc.Node = null;
  13. @property(cc.Node)
  14. recordSview: cc.Node = null;
  15. itemP = null
  16. //分帧加载
  17. addNum = 0
  18. addTotal = 0
  19. _n = 0
  20. _dis = 5
  21. private disY = 0
  22. private lastY = 0
  23. /**提现记录类型 1:俱乐部提现*/
  24. private type = 0
  25. async onLoad() {
  26. this.node.height = cc.winSize.height
  27. this.addNum = 0
  28. this.addTotal = 0
  29. this.itemP = await Utils.loadResPromise('prefabs/RecordItem')
  30. this.recordSview.height += (cc.winSize.height - 1334)
  31. this.recordContent.parent.height += (cc.winSize.height - 1334)
  32. }
  33. initType(type = 0) {
  34. this.type = type
  35. this.recordContent.removeAllChildren()
  36. if (this.type == 1) {
  37. GameM.ClubData.requestClubWithDrawRecords()
  38. }
  39. if (GameM.commonData.isAuth && this.type != 1) {
  40. LogUtil.logV('BBBB ', " getCashRecord")
  41. GameM.httpM.sendDatas(HTTP_TYPE.getCashRecord, null, GameM.commonData.resultCashRecord.bind(GameM.commonData))
  42. }
  43. }
  44. // onEnable() {
  45. // this.recordContent.removeAllChildren()
  46. // if (GameM.commonData.isAuth) {
  47. // GameM.httpM.sendDatas(HTTP_TYPE.getCashRecord, {})
  48. // }
  49. // }
  50. freshRecord() {
  51. if (this.type == 1) {
  52. this.addTotal = GameM.ClubData.clubCashRecord.length
  53. } else {
  54. this.addTotal = GameM.commonData.cashRecord.length
  55. LogUtil.logV('BBBB GameM.ClubData.cashRecord ', GameM.ClubData.cashRecord)
  56. }
  57. this.addNum = 0
  58. }
  59. update(dt) {
  60. if (this.addNum < this.addTotal) {
  61. if (this._n <= this._dis) {
  62. this._n++
  63. }
  64. else {
  65. this._n = 0
  66. let item: cc.Node = cc.instantiate(this.itemP)
  67. item.name = this.addNum.toString()
  68. let s = item.getComponent(RecordItem)
  69. let data = null
  70. if (this.type == 1) {
  71. data = GameM.ClubData.clubCashRecord[this.addNum]
  72. let cashMode = 0
  73. if (typeof data.withdrawCode === 'string' && data.withdrawCode != "" && data.withdrawCode != "null") {
  74. cashMode = 2
  75. }
  76. LogUtil.logV("typeof data.withdrawCode ", typeof data.withdrawCode)
  77. LogUtil.logV("ClubCashRecordNode cashMode", cashMode + " withdrawalCode:" + data.withdrawCode)
  78. let createTime: string = data.createTime
  79. let spliteStr = createTime.split(" ")
  80. let timeStr = ""
  81. if (spliteStr.length > 0) {
  82. timeStr = spliteStr[0]
  83. } else {
  84. timeStr = createTime
  85. }
  86. s.init(data.applyType, spliteStr[0], (data.amount * 0.0001).toFixed(2), (data.currentBalance * 0.0001).toFixed(2), cashMode, data.withdrawCode, true)
  87. } else {
  88. data = GameM.commonData.cashRecord[this.addNum]
  89. LogUtil.logV("cashType ", data.cashType)
  90. s.init(data.cashType, data.applyTime, (data.amount * 0.01).toFixed(2), (data.remain * 0.0001).toFixed(2), data.CashMode, data.withdrawalCode)
  91. }
  92. // to do
  93. this.disY = item.height + 2
  94. item.y = - item.height * 0.5 - this.disY * this.addNum
  95. this.recordContent.addChild(item)
  96. this.checkVisible(item)
  97. this.recordContent.height = this.addTotal * this.disY
  98. this.addNum++
  99. }
  100. }
  101. this.onScroll()
  102. }
  103. onScroll() {
  104. if (Math.abs(this.recordContent.y - this.lastY) >= this.disY) {
  105. this.lastY = this.recordContent.y
  106. this.recordContent.children.forEach(element => {
  107. this.checkVisible(element)
  108. });
  109. }
  110. }
  111. checkVisible(item: cc.Node) {
  112. let disy = item.y + this.recordContent.y
  113. if (disy >= 45 + this.disY || disy <= -this.recordSview.height - 45 - this.disY) {
  114. item.active = false
  115. }
  116. else {
  117. item.active = true
  118. }
  119. }
  120. clickClose() {
  121. GameM.audioM.playEffect(AUDIO_TYPE.button)
  122. UiM.Instance.offPanel(PANEL_NAME.CashRecordNode, true)
  123. }
  124. }