wish.js
7.87 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import {
getBindtapData,
getObjByListKeyValue
} from '../../utils/util';
import {
productMap
} from '../../const/custom-data';
let app = getApp();
Page({
data: {
isOverShare: true, //自定义分享
tipsRuleVisible: false,
tipsPirzeVisible: false,
userInfo: {},
wishInfo: {},
wishList: [],
helperInfo: {},
curWish: {},
status: 1, // 1正常(有库存) 2无库存
animationThumbData: [], // 进度条动画
animationFlagData: [], // 旗帜画库
guideIndex: 0, // 指引索引
},
onShareAppMessage(res) {
if (res.from === 'button') {
// 来自页面内转发按钮
console.log(res.target)
let userInfo = app.globalData.userInfo;
let billCode = app.globalData.indexInfo.wishBillCode;
let title = `${userInfo.nickname}正在参加丸美眼霜节心愿单活动,需要你的倾情相助!`;
let path = `/pages/coop/coop?code=${billCode}&s=share`
return {
title,
path,
imageUrl: 'https://kdcdn.oss-cn-shenzhen.aliyuncs.com/weapp/marubi/wish-list/share.png'
}
} else {
//分享配置
return {
title: '弹弹弹 看你有多弹',
path: 'pages/index/index',
imageUrl: 'https://kdcdn.oss-cn-shenzhen.aliyuncs.com/weapp/marubi/wish-list/share.png'
};
}
},
onLoad(options) {},
onShow() {
this.initData();
},
initData() {
app.queryIndex().then((result) => {
this.setData({
userInfo: app.globalData.userInfo
})
this.queryWishbillDetail().then((result) => {
this.playAnimation();
});
this.queryWishbillHelpers();
// this.pageScrollToBottom();
this.checkFirst();
})
},
/**
* 是否第一次进入当前页面
*/
checkFirst() {
let isFirst = app.store.getItem("wish-first");
if (!isFirst) {
this.setData({
guideIndex: 1
})
}
},
/**
* 滚动到页面底部
*/
pageScrollToBottom() {
wx.createSelectorQuery().select('#page').boundingClientRect(function (rect) {
// 使页面滚动到底部
wx.pageScrollTo({
scrollTop: rect.bottom + 5000,
duration: 300
})
}).exec()
},
// 播放动画
playAnimation() {
let wishList = this.data.wishList;
let animationThumbData = [];
let animationFlayData = [];
let animationFlagData = [];
wishList.forEach((element, index) => {
// 进度条动画
var animation1 = wx.createAnimation({
duration: 600,
delay: 600 * index + 1000
});
animation1.width(element.progress + "%").step()
let curAniData1 = animation1.export()
animationThumbData.push(curAniData1);
// 旗帜动画
var animation2 = wx.createAnimation({
duration: 600,
delay: 600 * index + 1000
});
animation2.left(element.progressLeft + "rpx").step()
let curAniData2 = animation2.export()
animationFlagData.push(curAniData2);
});
this.setData({
animationThumbData,
animationFlagData
})
},
/**
* 领取我的奖品
*/
onGetGiftHandler(evt) {
let curData = getBindtapData(evt);
console.log("curData:", curData);
app.post({
url: app.api.wishbillGiftAccept,
data: {
instanceCode: curData.instanceCode
}
}).then((result) => {
curData = Object.assign(curData, result);
this.setData({
curWish: curData,
tipsPirzeVisible: true,
status: curData.status
})
app.globalData.giftData = curData;
// 再查看奖品
// app.post({
// url: app.api.wishbillGiftQuery,
// data: {
// instanceCode: curData.instanceCode
// }
// }).then((result) => {
// curData = Object.assign(curData, result);
// this.setData({
// curWish: curData,
// tipsPirzeVisible: true,
// status: curData.status
// })
// app.globalData.giftData = curData;
// console.log("app.globalData.giftData 222:", app.globalData.giftData);
// console.log(JSON.stringify(app.globalData.giftData));
// })
});
},
/**
* 查看我的奖品
* 点击领取
*/
onCheckGiftHandler(evt) {
let curData = getBindtapData(evt);
// console.log("curData:", curData);
app.post({
url: app.api.wishbillGiftQuery,
data: {
instanceCode: curData.instanceCode
}
}).then((result) => {
curData = Object.assign(curData, result);
this.setData({
curWish: curData,
status: curData.status
})
app.globalData.giftData = curData;
console.log("app.globalData.giftData 111:", app.globalData.giftData);
console.log(JSON.stringify(app.globalData.giftData));
// 领取状态
// 领取类型:0=未提交;1=邮寄(填写邮寄信息);2=自提(填门店预约信息)
let acceptType = curData.order.acceptType;
if (acceptType == 0) {
// 未提交,显示领取选择
this.setData({
tipsPirzeVisible: true,
})
} else if (acceptType == 1) {
// 已经选择邮寄
// 判断是否已经填写邮寄信息
app.router.push({
path: "userTable"
})
} else if (acceptType == 2) {
// 已经选择自提
app.router.push({
path: "prizeDetail",
})
}
// 查看是否已经预约
})
},
// 显示规则页面
onShowRuleHandler() {
this.setData({
tipsRuleVisible: true
})
},
// 显示我的卡券
onMyCardHandler() {
app.router.push({
path: "myCard"
})
},
// 显示海报图
onCreatePosterHandler() {
app.globalData.posterWishList = this.data.wishList;
app.router.push({
path: "poster"
})
},
// 查看排行榜
onRankHandler() {
app.router.push({
path: "rank"
})
},
// 分享
onShareHandler() {
},
// 点击蒙层指引
onGuideHandler() {
let guideIndex = this.data.guideIndex;
guideIndex++;
if (guideIndex > 4) {
guideIndex = 0;
wx.pageScrollTo({
scrollTop: 0,
duration: 300
})
app.store.setItem("wish-first", "true");
}
if (guideIndex == 4) {
this.pageScrollToBottom();
}
this.setData({
guideIndex
})
},
// 获取心愿单详情
queryWishbillDetail() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.wishbillDetail,
data: {
billCode: app.globalData.indexInfo.wishBillCode
}
}).then((result) => {
let wishList = result.wishGifts;
wishList.forEach(element => {
let product = productMap[element.prizeDefineCode + ""];
element = Object.assign(element, product);
let progress = element.elasticValue / element.conditionElasticValue * 100;
if (progress > 100) progress = 100;
// 直接计算坐标
let progressLeft = progress * 2.2 - 51;
element.progress = progress;
element.progressLeft = progressLeft;
});
this.setData({
wishInfo: result,
wishList: wishList
});
resolve();
})
});
},
// 获取助力列表
queryWishbillHelpers() {
return new Promise((resolve, reject) => {
app.post({
url: app.api.wishbillHelpers,
data: {
billCode: app.globalData.indexInfo.wishBillCode,
page: 1,
size: 50
}
}).then((result) => {
this.setData({
helperInfo: result
})
})
});
},
hideMask() {
// console.log("1111");
this.setData({
tipsRuleVisible: false,
tipsPirzeVisible: false,
})
},
// 子组件事件
evtcomp(evt) {
let {
name,
data
} = evt.detail;
switch (name) {
case "_evt_hide_mask":
this.hideMask();
break;
default:
break;
}
},
})