redPacket.js
3.4 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import {
request
} from "../../request/index.js"
const a = getApp()
var isClick = true;
Page({
data: {
imagesUrl: a.globalData.baseUrl,
currentT: 1,
way: 1,
redPacket: [],
myPacket: [],
totalFen: '',
red_id: '',
msg: '',
isLing: true,
txtpopUp: false
},
onLoad: function (options) {
},
onReady: function () {
},
onShow: function () {
this.getredPacket()
this.getmyPacket()
},
clickNum(e) {
this.setData({
currentT: e.target.dataset.num,
way: e.target.dataset.num
})
// console.log(this.data.way, "way");
if (e.target.dataset.num == 1) {
this.getredPacket()
} else {
this.getmyPacket()
}
},
allPopup(e) {
let that = this
let it = e.currentTarget.dataset.id
let list = that.data.redPacket
list.forEach((item, index) => {
if (it == item.id) {
if (item.txtpopUp == true) {
list[index].txtpopUp = false
} else {
list[index].txtpopUp = true
}
}
});
that.setData({
redPacket: list
})
},
clickPopup(e) {
let that = this
let it = e.currentTarget.dataset.id
let list = that.data.myPacket
list.forEach((item, index) => {
if (it == item.id) {
if (item.is_cloose == true) {
list[index].is_cloose = false
} else {
list[index].is_cloose = true
}
}
});
that.setData({
myPacket: list
})
},
async getredPacket() {
let that = this
try {
const {
data: {
data
}
} = await request({
url: 'api/red/lingRed',
})
// // console.log(data);
data.forEach(item => {
item.txtpopUp = false
});
that.setData({
redPacket: data
})
} catch (err) {
that.setData({
msg: err.msg
})
that.popMaskTest()
}
},
async receive(e) {
let that = this
if (isClick) {
isClick = false;
try {
const {
data
} = await request({
url: 'api/red/ling',
data: {
red_id: e.currentTarget.dataset.red_id
}
})
that.setData({
msg: data.msg,
})
that.popSuccessTest()
setTimeout(() => {
that.getredPacket()
}, 1300);
setTimeout(function () {
isClick = true;
}, 3000); //一秒内不能重复点击
} catch (err) {
// console.log(err);
a.popTest(err.msg)
}
} else {
return;
}
},
async getmyPacket() {
let that = this
try {
const {
data: {
data
}
} = await request({
url: 'api/red/myRed',
})
// // console.log(data, "api/red/myRed ");
data.forEach(item => {
item.is_cloose = false
})
that.setData({
myPacket: data,
})
} catch (err) {
// console.log(err);
a.popTest(err.msg)
}
},
popMaskTest() {
wx.showToast({
title: this.data.msg,
duration: 2000,
icon: 'none',
mask: true //是否有透明蒙层,默认为false
//如果有透明蒙层,弹窗的期间不能点击文档内容
})
},
popSuccessTest() {
wx.showToast({
title: this.data.msg,
icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
duration: 2000, //停留时间
})
},
})