WithdrawalPanel.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import GameItem from "./GameItem";
  2. import QCrossWidgetItem from "./QCrossWidgetItem";
  3. import { utils } from "./Utils";
  4. import { BannerLocation, SubLocation } from "./YZ_Constant";
  5. import PlatUtils from "./PlatUtils";
  6. import CompatibleTool from "./CompatibleTool";
  7. import { YzRedBagInfo } from "./CommonConfig";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class WithdrawalPanel extends cc.Component {
  11. private _closeBtn: cc.Node = null;
  12. private _withdrawalBtn: cc.Node = null;
  13. private _moneyItemNodes: cc.Node[] = null;
  14. private _panel: cc.Node = null;
  15. private _balanceLbl: cc.Label = null;
  16. private _redBagInfo: YzRedBagInfo = null;
  17. _location: SubLocation = SubLocation.isMoreGame;
  18. onLoad() {
  19. if (utils.otherConfig && utils.otherConfig.group) {
  20. this.node.group = utils.otherConfig.group;
  21. }
  22. this._panel = this.node.getChildByName("Panel");
  23. this._moneyItemNodes = this._panel.getChildByName("WithdrawalPriceNodes").children;
  24. this._balanceLbl = this._panel.getChildByName("balanceLabel").getComponent(cc.Label);
  25. // this.node.active = false;
  26. this._redBagInfo = utils.yzRedBagInfo;
  27. let ratio: number = 1;
  28. if (cc.winSize.height < cc.winSize.width) {
  29. // 横屏游戏
  30. ratio = cc.winSize.width / 1920 * 0.5;
  31. } else {
  32. ratio = cc.winSize.width / 1080;
  33. }
  34. this._panel.scale = ratio;
  35. this._initWidget();
  36. }
  37. private _initWidget() {
  38. if (this._redBagInfo.balance > 0) {
  39. this._balanceLbl.string = `${this._redBagInfo.balance}元`
  40. }
  41. for (let i = 0; i < 4; i++) {
  42. let data: any = utils.yzRedBagInfo.withdrawaMoneys[i];
  43. if (data) {
  44. this._moneyItemNodes[i].getChildByName("PriceLbl").getComponent(cc.Label).string = `${data}元`
  45. this._moneyItemNodes[i].on(cc.Node.EventType.TOUCH_START, () => {
  46. this.selectedMoneyNode(i)
  47. }, this);
  48. }
  49. }
  50. }
  51. _selectedMoneyItemIndex: number = -1;
  52. selectedMoneyNode(itemIndex) {
  53. if (this._redBagInfo.balance >= utils.yzRedBagInfo.withdrawaMoneys[itemIndex]) {
  54. this._selectedMoneyItemIndex = itemIndex;
  55. this._moneyItemNodes.forEach((element, index) => {
  56. if (itemIndex != index) {
  57. this._moneyItemNodes[index].getChildByName("selectedBg").active = false;
  58. }
  59. });
  60. this._moneyItemNodes[itemIndex].getChildByName("selectedBg").active = true;
  61. } else {
  62. utils.showMsg("当前余额不足!");
  63. }
  64. }
  65. withDrawalMoney() {
  66. console.log("money");
  67. if (this._selectedMoneyItemIndex > -1) {
  68. } else {
  69. utils.showMsg("请选择要提现的金额!");
  70. }
  71. }
  72. // update() {
  73. // if (this._dataDirty) {
  74. // this._dataDirty = false;
  75. // this._updatePanel();
  76. // }
  77. // }
  78. _updatePanel() {
  79. utils.postRecommentShowData(this._location);
  80. this._initWidget();
  81. return;
  82. }
  83. public init(YzRedBagInfo: YzRedBagInfo) {
  84. }
  85. public show() {
  86. this.node.active = true;
  87. }
  88. public hide() {
  89. let self = this;
  90. // this._panel.runAction(cc.sequence(cc.moveTo(0.3, CompatibleTool.position(-this._panel.getContentSize().width, 0)).easing(cc.easeQuadraticActionOut()), cc.callFunc(() => {
  91. self.node.active = false;
  92. // })));
  93. // if (!PlatUtils.IsNativeAndroid) {
  94. // utils.adManager.ShowBanner(BannerLocation.Home);
  95. // }
  96. }
  97. public onCloseBtnHandler(event: any, data: any) {
  98. this.hide();
  99. }
  100. }