Withdrawal.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { _decorator, Component, Node, Label } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { Http } from '../core/net/Http';
  4. import { WindowSystem } from '../core/ui/window/WindowSystem';
  5. import { UserData } from '../data/UserData';
  6. const { ccclass, property, requireComponent } = _decorator;
  7. /**神台提现面板 */
  8. @ccclass('Withdrawal')
  9. @requireComponent(Http)
  10. export class Withdrawal extends Component {
  11. @property({ tooltip: "可提现余额", type: Label })
  12. public moneyLabel: Label;
  13. private userData: UserData;
  14. start() {
  15. this.userData = DataSystem.getData(UserData);
  16. this.moneyLabel.string = (this.userData.contribution / 10000).toFixed(2) + '元';
  17. }
  18. update() {
  19. DataSystem.watch(UserData, 'contribution') && (this.moneyLabel.string = (this.userData.contribution / 10000).toFixed(2) + '元');
  20. }
  21. /**
  22. * 贡献提现
  23. */
  24. public async onWithdrawal() {
  25. if (DataSystem.getData(UserData).contribution < 3000) {
  26. WindowSystem.showTips('提现金额小于0.3元,不能提现');
  27. return;
  28. }
  29. let result = await this.getComponent(Http).send("/api/user/Withdraw", { type: 1 });
  30. if (result && result.code && result.code > 0) {
  31. WindowSystem.showTips('提现失败,错误码:' + [result.code]);
  32. } else {
  33. if (result.message) {
  34. WindowSystem.showTips(result.message);
  35. }
  36. else {
  37. WindowSystem.showTips("提现成功,72小时内到账");
  38. DataSystem.getData(UserData).contribution = 0;
  39. }
  40. }
  41. }
  42. }