LuckDrawModel.ts
3.66 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import AppSdk from "./AppSdk";
import DateUtils from "../uitl/DateUtils";
import ObjectInstance from "../uitl/ObjectInstance";
/**转盘 获取转盘机会的 */
export default class LuckDrawModel {
private _data: LuckDrawData;
private propRemove: number = 0;
private propChange: number = 0;
async init() {
this._data = await this.initData();
AppSdk.I.putData('luckDrawProp', JSON.stringify({ remove: 0, change: 0 }))
AppSdk.I.putData('LuckDrawToSign', JSON.stringify({ istoSignin: 0 }))
}
async initData() {
let data = new LuckDrawData;
let lastTime = Laya.LocalStorage.getItem('LuckDrawLastTime') || '0';
data.luckDrawLastTime = parseInt(lastTime);
let last = DateUtils.timeDay(data.luckDrawLastTime);
let today = DateUtils.today;
if (last != today) {
lastTime = DateUtils.nowTime.toString();
Laya.LocalStorage.setItem('LuckDrawLastTime', lastTime);
data.luckDrawLastTime = parseInt(lastTime);
/**初始化数据
* 1 签到
* 2 视频
* 3 摇一摇
* 4 红包
*/
data.list = [];
let list = [];
for (let index = 0; index < 4; index++) {
let item = new LuckDrawVo;
item.type = index + 1;
item.num = 0;
item.isUse = 0;
item.useNum = 0;
list.push(item);
}
data.list = list;
} else {
let luckDrawData: any = await AppSdk.I.getData('LuckDrawData');
data.list = luckDrawData.data.list;
}
// UtilTool.log('------LuckDrawData--update init -data----' + JSON.stringify(data))
AppSdk.I.putData('LuckDrawData', JSON.stringify(data))
this._data = data;
return data;
}
get data(): LuckDrawData {
return this._data;
}
updateData(index: number, addNum: number = 1) {
this.data.list[index].num += addNum;
AppSdk.I.putData('LuckDrawData', JSON.stringify(this.data))
}
async getPropData() {
// AppSdk.I.putData('luckDrawProp', JSON.stringify({remove:3,change:2}))
let luckDrawProp: any = await AppSdk.I.getData('luckDrawProp');
// let luckDrawProp = { code: 0, data: { remove: 3, change: 2 } }
this.propRemove = Number(luckDrawProp.data.remove);
this.propChange = Number(luckDrawProp.data.change);
if (this.propRemove > 0) {
this.updateRemoveProp();
} else {
this.updateChangeProp();
}
return luckDrawProp;
}
async updateRemoveProp() {
if (this.propRemove > 0) {
// ViewManager.I.openPopwin(ReceivePropsPopwin, BoosterType.Remove, this.propRemove, true);
// ViewManager.I.openPopwin(GetpropPopwin,PropType.hammer,1)
this.propRemove = 0;
AppSdk.I.putData('luckDrawProp', JSON.stringify({ remove: 0, change: this.propChange }));
}
}
updateChangeProp() {
if (this.propChange > 0) {
// ViewManager.I.openPopwin(ReceivePropsPopwin, BoosterType.Change, this.propChange);
// ViewManager.I.openPopwin(GetpropPopwin,PropType.refresh,1)
this.propChange = 0;
AppSdk.I.putData('luckDrawProp', JSON.stringify({ remove: this.propRemove, change: 0 }));
}
}
static get I(): LuckDrawModel {
return ObjectInstance.get(LuckDrawModel) as LuckDrawModel;
}
}
class LuckDrawData {
list: LuckDrawVo[];
luckDrawLastTime: number;
}
class LuckDrawVo {
type: number;
num: number;
isUse: number;
useNum: number;
}