RedDrawal.ts
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import RedpacketModel from "./sdk/model/RedpacketModel";
import { EventCenter } from "./event/EventCenter";
import { EventEnum } from "./event/EventEnum";
/**
* 主界面 金币金额
*/
export default class RedDrawal extends Laya.Script {
/** @prop {name:coinlab, tips:"金币", type:Node}*/
coinlab: Laya.Label;
/** @prop {name:tiplab, tips:"提示", type:Node}*/
tiplab: Laya.Label;
private totalCoin: number = 110;
constructor() { super(); }
onStart() {
this.updateStar();
// this.tiplab.visible = false;
}
onEnable() {
EventCenter.add(EventEnum.APP_SHOW, this, this.updateStar);
EventCenter.add(EventEnum.UPDATE_COIN, this, this.updateStar);
}
onDisable() {
EventCenter.remove(EventEnum.APP_SHOW, this, this.updateStar);
EventCenter.remove(EventEnum.UPDATE_COIN, this, this.updateStar);
}
async updateStar() {
let coin = await RedpacketModel.I.getTotalCoin();
// let coin = 1000
this.totalCoin = coin;
this.coinlab.text = '' + coin;
let str = '可提现';
/**更新下下一次提现的额度 */
let nextDrawal = await RedpacketModel.I.minWithDrawal();
if (this.totalCoin > 0) {
let leftCoin = nextDrawal - this.totalCoin;
if (leftCoin > 0)
str = `还差${(leftCoin / 10000).toFixed(3)}金额可提现`;
}
this.tiplab.text = str;
this.tiplab.visible = Boolean(nextDrawal);
}
}