DiamondWithItem.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { _decorator, Component, Node, RichText, Label, Sprite, SpriteFrame, Button, EventHandler, game } from 'cc';
  2. import InfiniteCell from '../core/InfiniteList/InfiniteCell';
  3. import { Http } from '../core/net/Http';
  4. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  5. import { OpenWindow } from '../core/ui/window/OpenWindow';
  6. import { WindowManager } from '../core/ui/window/WindowManager';
  7. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  8. import { ConfigData } from '../Data/ConfigData';
  9. import { g } from '../Data/g';
  10. import { platform } from '../Data/platform';
  11. import { LoginWaitWin } from '../Windows/LoginWaitWin';
  12. import { NoviceWindow } from '../Windows/NoviceWindow';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('DiamondWithItem')
  15. export class DiamondWithItem extends InfiniteCell {
  16. @property({ tooltip: "神石消耗文本", type: RichText }) public diamond: RichText;
  17. @property({ tooltip: "兑换金额文本", type: Label }) public money: Label;
  18. @property({ tooltip: "提现按钮", type: Node }) public withBtn: Node;
  19. @property({ tooltip: "提现图标", type: Node }) public withIcon: Node;
  20. @property({ tooltip: "已提现图标", type: Node }) public withendIcon: Node;
  21. @property({ tooltip: "http服务", type: Http }) public http: Http;
  22. public withdrawGrade = 0;//提现档次
  23. public needDiamond = 0;//兑换所需消耗神石
  24. public backFun: EventHandler;
  25. start() {
  26. g.gameData.isPlayVideo = false;
  27. }
  28. /**
  29. * 界面初始化
  30. * @param data item数据
  31. */
  32. public UpdateContent(data: any) {
  33. this.diamond.string = "<color=#681515>消耗</color><color=#FC8354>" + data.needDiamond + "</color><color=#681515>神石</color>";
  34. this.money.string = data.needDiamond / ConfigData.configMap.get("systemConfig").moneyRate + "元";
  35. this.withdrawGrade = data.grade;
  36. this.needDiamond = data.needDiamond;
  37. this.backFun = data.backFun;
  38. if (g.gameData.diamondWithdrawGrade == (this.withdrawGrade - 1)) {
  39. this.withIcon.active = true;
  40. this.withendIcon.active = false;
  41. if (g.userData.diamond >= data.needDiamond) {
  42. this.withBtn.getComponent(Button).interactable = true;
  43. this.withIcon.getComponent(Sprite).grayscale = false;//置灰
  44. } else {
  45. this.withBtn.getComponent(Button).interactable = false;
  46. this.withIcon.getComponent(Sprite).grayscale = true;//置灰
  47. }
  48. } else if (g.gameData.diamondWithdrawGrade < (this.withdrawGrade - 1)) {
  49. this.withBtn.getComponent(Button).interactable = false;
  50. this.withIcon.active = true;
  51. this.withendIcon.active = false;
  52. this.withIcon.getComponent(Sprite).grayscale = true;//置灰
  53. } else {
  54. this.withBtn.getComponent(Button).interactable = false;
  55. this.withIcon.active = false;
  56. this.withendIcon.active = true;
  57. }
  58. }
  59. public isSend = false;
  60. /**
  61. * 神石提现
  62. */
  63. public async with() {
  64. if (g.gameData.diamondWithdrawGrade == (this.withdrawGrade - 1)) {
  65. if (g.gameData.isPlayVideo) {
  66. return;
  67. }
  68. g.gameData.isPlayVideo = true;
  69. //#region 打开加载等待界面
  70. // let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
  71. //#endregion
  72. let date = await this.http.send("/api/wealth/Withdraw", { type: 3, grade: this.withdrawGrade });
  73. // _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
  74. if (date.code === 0 && !date.message) {
  75. //提现成功
  76. if (NoviceWindow.isNovicing) {
  77. NoviceWindow.isNovicing = false;
  78. }
  79. g.gameData.diamondWithdrawGrade = date.grade;
  80. g.userData.diamond -= this.needDiamond;
  81. platform.volcanicReport('withdrawForDiamond');
  82. WindowManager.showTips("提现成功,72小时内到账");
  83. this.backFun.emit([]);
  84. } else if (date.message) {
  85. WindowManager.showTips(date.message);
  86. } else {
  87. WindowManager.showTips("网络异常,请稍候再试");
  88. }
  89. g.gameData.isPlayVideo = false;
  90. } else {
  91. WindowManager.showTips("当前不可领取");
  92. }
  93. }
  94. }