DayPrizeItem.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { _decorator, Node, Label, ProgressBar } from 'cc';
  2. import InfiniteCell from '../core/InfiniteList/InfiniteCell';
  3. import { Http } 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. const { ccclass, property } = _decorator;
  8. @ccclass('DayPrizeItem')
  9. export class DayPrizeItem extends InfiniteCell {
  10. @property({ type: ProgressBar, tooltip: "看视屏完成度进度条" })
  11. public progressBar: ProgressBar = null;
  12. @property({ type: BitmapFont, tooltip: "进度条百分比" })
  13. public barText: BitmapFont = null;
  14. @property({ type: BitmapFont, tooltip: "中央金币文本" })
  15. public moneyText: BitmapFont = null;
  16. @property({ type: BitmapFont, tooltip: "左金币文本" })
  17. public moneyText2: BitmapFont = null;
  18. @property({ type: Node, tooltip: "提现节点" })
  19. public button: Node = null;
  20. @property({ type: Node, tooltip: "未领取节点" })
  21. public unGet: Node = null;
  22. //子项对应金币
  23. private money: number;
  24. private http: Http;
  25. private progress = 0;
  26. start() {
  27. this.http = this.node.getComponent(Http);
  28. }
  29. /**
  30. * 数据更新
  31. * @param data
  32. */
  33. UpdateContent(data: any): void {
  34. this.progress = data.value;
  35. this.setProgress(data.value);
  36. this.money = data.money;
  37. this.moneyText.string = data.money + "元";
  38. this.moneyText2.string = data.money + "元";
  39. }
  40. /**
  41. * 进度设值
  42. */
  43. private setProgress(progress: number) {
  44. if (progress < 1) {
  45. this.progressBar.progress = progress;
  46. this.button.active = false;
  47. } else {
  48. this.progressBar.progress = 1;
  49. this.button.active = true;
  50. // this.barText.string = "100%";
  51. }
  52. this.barText.string = (progress * 100).toFixed(2) + "%";
  53. this.unGet.active = !this.button.active;
  54. }
  55. /**
  56. * 提现
  57. */
  58. async onWithdraw() {
  59. //向服务器发起提现,响应成功后进度清零
  60. let result = await this.http.send("/api/user/withdraw", { type: 2, index: this.dataIndex });
  61. if (result.code === 0 && !result.message) {
  62. //提现成功
  63. WindowManager.open("Prefabs/DayPrize/DayPrizeTips", WindowOpenMode.NotCloseAndAdd, null);
  64. this.setProgress(this.progress - 1);
  65. if (this.progress < 1) {
  66. this.button.active = false;
  67. }
  68. } else if (result.message) {
  69. WindowManager.showTips(result.message);
  70. }
  71. else {
  72. WindowManager.showTips("网络异常,请稍候再试");
  73. }
  74. this.unGet.active = !this.button.active;
  75. }
  76. }