| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import { _decorator, Node, Label, ProgressBar } from 'cc';
- import InfiniteCell from '../core/InfiniteList/InfiniteCell';
- import { Http } from '../core/net/Http';
- import { BitmapFont } from '../core/ui/BitmapFont';
- import { WindowManager } from '../core/ui/window/WindowManager';
- import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
- const { ccclass, property } = _decorator;
- @ccclass('DayPrizeItem')
- export class DayPrizeItem extends InfiniteCell {
- @property({ type: ProgressBar, tooltip: "看视屏完成度进度条" })
- public progressBar: ProgressBar = null;
- @property({ type: BitmapFont, tooltip: "进度条百分比" })
- public barText: BitmapFont = null;
- @property({ type: BitmapFont, tooltip: "中央金币文本" })
- public moneyText: BitmapFont = null;
- @property({ type: BitmapFont, tooltip: "左金币文本" })
- public moneyText2: BitmapFont = null;
- @property({ type: Node, tooltip: "提现节点" })
- public button: Node = null;
- @property({ type: Node, tooltip: "未领取节点" })
- public unGet: Node = null;
- //子项对应金币
- private money: number;
- private http: Http;
- private progress = 0;
- start() {
- this.http = this.node.getComponent(Http);
- }
- /**
- * 数据更新
- * @param data
- */
- UpdateContent(data: any): void {
- this.progress = data.value;
- this.setProgress(data.value);
- this.money = data.money;
- this.moneyText.string = data.money + "元";
- this.moneyText2.string = data.money + "元";
- }
- /**
- * 进度设值
- */
- private setProgress(progress: number) {
- if (progress < 1) {
- this.progressBar.progress = progress;
- this.button.active = false;
- } else {
- this.progressBar.progress = 1;
- this.button.active = true;
- // this.barText.string = "100%";
- }
- this.barText.string = (progress * 100).toFixed(2) + "%";
- this.unGet.active = !this.button.active;
- }
- /**
- * 提现
- */
- async onWithdraw() {
- //向服务器发起提现,响应成功后进度清零
- let result = await this.http.send("/api/user/withdraw", { type: 2, index: this.dataIndex });
- if (result.code === 0 && !result.message) {
- //提现成功
- WindowManager.open("Prefabs/DayPrize/DayPrizeTips", WindowOpenMode.NotCloseAndAdd, null);
- this.setProgress(this.progress - 1);
- if (this.progress < 1) {
- this.button.active = false;
- }
- } else if (result.message) {
- WindowManager.showTips(result.message);
- }
- else {
- WindowManager.showTips("网络异常,请稍候再试");
- }
- this.unGet.active = !this.button.active;
- }
- }
|