WithdrawItem.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { _decorator, Component, Node, Label, Button, RichText, Sprite } from 'cc';
  2. import InfiniteCell from '../core/InfiniteList/InfiniteCell';
  3. import { Http, HttpResponseCode } from '../core/net/Http';
  4. import { BitmapFont } from '../core/ui/BitmapFont';
  5. import { WindowManager } from '../core/ui/window/WindowManager';
  6. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  7. import { Utils } from '../core/utils/Utils';
  8. import { g } from '../Data/g';
  9. import { platform } from '../Data/platform';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('WithdrawItem')
  12. export class WithdrawItem extends InfiniteCell {
  13. @property({ type: Http, tooltip: "HTTP网络请求" })
  14. public http: Http = null;
  15. @property({ type: BitmapFont, tooltip: "金额" })
  16. public money: BitmapFont = null;
  17. @property({ type: BitmapFont, tooltip: "红包券" })
  18. public redbagNum: BitmapFont = null;
  19. @property({ type: Sprite, tooltip: "已经领取按钮" })
  20. public geted: Sprite = null;
  21. @property({ type: Button, tooltip: "领取按钮" })
  22. public get: Button = null;
  23. @property({ type: Button, tooltip: "领取按钮" })
  24. public exchange: Button = null;
  25. @property({ type: Button, tooltip: "不可领取按钮" })
  26. public unget: Button = null;
  27. public itemMoney = 0;
  28. public itemRedbag = 0;
  29. private cashCode = "";
  30. //子项数据注入
  31. UpdateContent(data: any): void {
  32. this.money.string = data.money + "元";
  33. this.redbagNum.string = `${data.needBonus}`;
  34. this.state = data.state;
  35. this.itemMoney = data.money;
  36. this.itemRedbag = data.needBonus;
  37. if (data.cashCode) {
  38. this.cashCode = data.cashCode;
  39. }
  40. }
  41. set state(state: ButtonState) {
  42. this.get.node.active = this.unget.node.active = this.geted.node.active = this.exchange.node.active = false;
  43. switch (state) {
  44. case ButtonState.canget:
  45. this.get.node.active = true;
  46. break;
  47. case ButtonState.geted:
  48. this.geted.node.active = true;
  49. break;
  50. case ButtonState.unget:
  51. this.unget.node.active = true;
  52. break;
  53. case ButtonState.exchange:
  54. this.exchange.node.active = true;
  55. break;
  56. }
  57. }
  58. /**
  59. * 提现点击
  60. */
  61. async onWithdrawClick() {
  62. let result = await this.http.send("/api/user/withdraw", { type: this.dataIndex != 0 ? 3 : 4, index: this.dataIndex });
  63. if (result.code === 0 && !result.message) {
  64. platform.reportThinking("envelope_decrease", JSON.stringify({ previous_number: g.userData.bonus, decrease_number: this.itemRedbag, current_number: g.userData.bonus - this.itemRedbag, reasons: "withdraw" }));
  65. g.userData.bonus -= this.itemRedbag;
  66. if (result.cashCode != "") {
  67. this.cashCode = result.cashCode;
  68. this.onExchangeButton();
  69. } else {
  70. WindowManager.open("Prefabs/DayPrize/DayPrizeTips", WindowOpenMode.NotCloseAndAdd, null);
  71. }
  72. platform.reportThinking("ad_init", JSON.stringify({ ad_id: "withDraw", ad_time: Utils.formatDate(new Date()), id: g.userData.id, role_name: g.userData.nickName, level: g.userData.getLevel() }));
  73. platform.showRewardVideoAD();
  74. } else if (result.message) {
  75. WindowManager.showTips(result.message);
  76. }
  77. else if (result.code != HttpResponseCode.KeyError) {
  78. WindowManager.showTips("网络异常,请稍候再试");
  79. }
  80. }
  81. public onExchangeButton(): void {
  82. WindowManager.open("Prefabs/Withdraw/GZHWithdrawWindow", WindowOpenMode.NotCloseAndAdd, this.cashCode);
  83. }
  84. }
  85. export enum ButtonState {
  86. unget,
  87. canget,
  88. geted,
  89. exchange
  90. }