task_assistance.js
13.6 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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
var auth = require("../../../utils/auth.js"),
rq = require("../../../utils/request.js");
var e = getApp(),
app = e,
i = require("../../../utils/util.js"),
ut = i,
s = e.globalData.setting,
os = s,
app_d = e.globalData;
var regeneratorRuntime = require('../../../utils/runtime.js');
Page({
/**
* 页面的初始数据
*/
data: {
sw_index: 0, //轮播的下标控制
url: s.url, //接口网址
iurl: s.imghost,
is_task: 0, //判断标题名是任务1还是2
activity_data: "25:20:59", //活动剩余时间
task_number: 12, //任务数
is_task: 0, //历史记录与任务
aitem: "", //活动的轮播图
switch_head: 0, //0:我的任务,1:记录
help_id: "", //活动的id canvasHidden: 0, //分享图片是否已经生成
is_share: 0, //是否显示画布
shareImgPath: [], //生成的图片
screenWidth: "", //用户的屏幕宽度
gid: "",
images: ["miniapp/images/friendhelp/help.png", "miniapp/images/friendhelp/background.png", "miniapp/images/friendhelp/gift.png", "miniapp/images/friendhelp/no_check.png",
"miniapp/images/friendhelp/check.png", "miniapp/images/friendhelp/check.png", "miniapp/images/friendhelp/unfinished.png", "miniapp/images/friendhelp/gift.png"
]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var help_id = options.help_id;
console.log("是什么鬼", help_id);
var th = this;
th.setData({
help_id: help_id
});
if (options.gid != undefined) {
th.setData({
gid: options.gid
})
}
th.close();
th.syinfo();
th.imageinfo();
},
// 轮播图点击左边
click_pre: function() {
var index = this.data.sw_index;
index--;
if (index < 0) return;
this.setData({
sw_index: index
})
},
//轮播图点击右边
click_next: function() {
var index = this.data.sw_index;
index++;
if (index >= this.data.aitem.length) return;
this.setData({
sw_index: index
})
},
//任务领取
onlicke: function() {
var th = this;
th.shareFrends();
th.setData({
is_share:1
})
getApp().my_warnning("任务领取成功", 1, th);
},
//我的任务和帮拆记录的替换
switch_head: function(e) {
var th = this;
var index = e.currentTarget.dataset.index; //获取当前选择的是任务还是活动说明
var switch_head = th.data.switch_head; //0任务,1活动说明
if (index != switch_head) {
th.setData({
switch_head: index,
is_task: index
})
}
},
//划动的时候监听
onSli: function(e) {
var ind = e.detail.current;
this.setData({
sw_index: ind
})
},
//导航球
close: function() {
var th = this;
var nav_b = th.selectComponent("#nav_b"); //组件的id
nav_b.close_box();
nav_b.set_name("助力", "");
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
var th = this;
var help_id = th.data.help_id;
/*-----统计-----*/
rq.get("/api/weshop/marketing/help/help/task/page", {
data: {
helpId: help_id,
storeId: os.stoid
},
success: function(su) {
var data = su.data;
console.log('waitlist5555555555' + data.code);
if (data.code != 0) {
getApp().my_warnning(data.msg, 0, th);
return false;
}
if (data.code == 0) {
//轮播图的数据
var data_aissa = data.data.pageData;
//当前时间戳
var nt = ut.gettimestamp();
data_aissa.forEach(function(val, ind) {
console.log(nt, "当前时间", "结束时间", val.end_time, "开始时间");
//已开始
if (val.start_time < nt && val.end_time > nt) data_aissa[ind].status = 0;
//未开始
else if (val.start_time > nt && val.end_time > nt) data_aissa[ind].status = 1;
//已结束
else if (val.start_time < nt && val.end_time < nt) data_aissa[ind].status = 2;
});
th.setData({
aitem: data_aissa
});
}
}
})
setTimeout(function() {
th.shareFrends();
}, 1000)
},
//----助力任务-----
countDown() {
if (!this.data.is_timer) return false;
var th = this;
// 获取当前时间,同时得到活动结束时间数组
var newTime = ut.gettimestamp();
var List = this.data.aitem;
for (var j = 0; j < List.length; j++) {
var endTimeList = List[j];
// 对结束时间进行处理渲染到页面
for (var i = 0; i < endTimeList.length; i++) {
var o = endTimeList[i];
var endTime = o.end_time
if (o.status == 0) endTime = o.start_time
var obj = null;
// 如果活动未结束,对时间进行处理
if (endTime - newTime > 0) {
var time = (endTime - newTime);
// 获取天、时、分、秒
var day = parseInt(time / (60 * 60 * 24));
var hou = parseInt(time % (60 * 60 * 24) / 3600);
var min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
var sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
obj = {
day: this.timeFormat(day),
hou: this.timeFormat(hou),
min: this.timeFormat(min),
sec: this.timeFormat(sec)
}
} else {
//活动已结束,全部设置为'00'
obj = {
day: '00',
hou: '00',
min: '00',
sec: '00'
}
}
var txt = "aitem[" + j + "][" + i + "].djs";
th.setData({
[txt]: obj
});
}
}
setTimeout(th.countDown, 1000);
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
},
shareFrends: function(e) {
var th = this;
var scene = th.data.gid;
///二微码
// var path3 = os.url + "/api/wx/open/app/user/getWeAppEwm/" +
// a.stoid + "?sceneValue=" + scene + "&pageValue=pages/goods/goodsInfo/goodsInfo";
var iurl = th.data.iurl; //图片地址前缀
const ctx = wx.createCanvasContext('share_id'); //绘图上下文
var unit = th.data.screenWidth / 750 * 1.35;
var numsize = 20 * unit; //几人助力字体大小
var size = 15 * unit;
var num = 10;
var q_num = 6;
var already = num.toString().length + 1; //已有几位好友助力
var lack = q_num.toString().length + 1; //还差几位好友助力
var imagesize = 40 * unit; //助力人的图片大小
var left = 74 * unit; //助力人头像跟左边的距离
var spacing = 12 * unit; //助力人图片间距
var images = th.data.images;
ctx.drawImage(images[0], 0, 0, 445 * unit, 700 * unit); //分享的背景图片
ctx.drawImage(images[1], 37 * unit, 185 * unit, 370 * unit, 377 * unit); //分享的背景图片
ctx.drawImage(images[2], 90 * unit, 231 * unit, 266 * unit, 160 * unit); //分享的背景图片
ctx.setFillStyle("rgb(221,153,116)");
ctx.setFontSize(size)
ctx.fillText("已有", 77 * unit, 430 * unit);
ctx.setFillStyle("#FF4746");
ctx.setFontSize(numsize)
ctx.fillText(num + "位", 108 * unit, 430 * unit);
ctx.setFillStyle("rgb(221,153,116)");
ctx.setFontSize(size)
ctx.fillText("好友助力,还差", 114 * unit + already * numsize * unit, 430 * unit);
ctx.setFillStyle("#FF4746");
ctx.setFontSize(numsize);
ctx.fillText(q_num + "位", 220 * unit + already * numsize * unit, 430 * unit);
ctx.setFillStyle("rgb(221,153,116)");
ctx.setFontSize(size);
ctx.fillText("达成助力", 248 * unit + lack * numsize * unit + already * numsize - numsize * 2, 430 * unit);
var c = q_num / num;
ctx.drawImage(images[3], 65 * unit, 445 * unit, 320 * unit, 12 * unit);
ctx.drawImage(images[4], 65 * unit, 445 * unit, 320 * unit * c, 12 * unit);
for (var i = 0; i < 6; i++) {
if (i == 0) {
ctx.save();
ctx.beginPath(); //开始绘制
ctx.arc(left + imagesize / 2, 505 * unit, imagesize/2, 0, 2 * Math.PI);
ctx.setLineWidth(4 * unit);
ctx.setStrokeStyle('red');
ctx.setFillStyle("white");
ctx.fill();
ctx.clip();
ctx.drawImage(images[6], left, 505 * unit - imagesize/2, imagesize, imagesize);
ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制
} else {
// 助力人的头像
ctx.drawImage(images[6], left, 505 * unit - imagesize / 2, imagesize, imagesize); //分享的背景图片
}
left += imagesize + spacing;
}
ctx.setFillStyle("rgb(255,255,255)");
ctx.setFontSize(size);
ctx.fillText("优惠乐翻天,精彩就在你身边!", 37 * unit, 595 * unit);
ctx.setFillStyle("rgb(255,255,255)");
ctx.setFontSize(size);
ctx.fillText("2019.06.26 - 2019.07.02!", 37 * unit, 620 * unit);
ctx.setFillStyle("rgb(255,255,255)");
ctx.setFontSize(size);
ctx.fillText("长按识别二维码,可帮我助力!", 37 * unit, 660 * unit);
ctx.drawImage(images[7], 325 * unit, 595 * unit, 77 * unit, 77 * unit); //分享的背景图片
ctx.save();
//读取文件成功则OK--
// wx.getImageInfo({
// src: path3,
// success: function (res) {
//把画板内容绘制成图片,并回调 画板图片路径
ctx.draw(false, function() {
setTimeout(function() {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 300,
height: 500,
destWidth: 400 * 2,
destHeight: 720 * 2,
canvasId: 'share_id',
success: function(res) {
wx.hideLoading();
var shareImgPath = th.data.shareImgPath;
shareImgPath[0] = res.tempFilePath;
th.setData({
shareImgPath: shareImgPath,
canvasHidden: 1,
is_share: 1
})
if (!res.tempFilePath) {
wx.showModal({
title: '提示',
content: '图片绘制中,请稍后重试',
showCancel: false
})
return false;
}
},
fail(r) {
}
}, 500)
})
})
// }
// })
},
preview: function() {
var th = this;
var shareImgPath = th.data.shareImgPath;
wx.previewImage({
url: shareImgPath[0],
urls: shareImgPath
})
},
//关闭分享显示
close_share: function() {
var th = this;
th.setData({
is_share: 0
})
},
syinfo: function() {
var th = this;
//获取用户设备信息,屏幕宽度
wx.getSystemInfo({
success: res => {
th.setData({
screenWidth: res.screenWidth
})
}
})
},
imageinfo: function() {
var th = this;
var images = th.data.images;
var iurl = th.data.iurl;
wx.getImageInfo({
src: iurl + images[0],
success: function(res) {
console.log(res + i);
//res.path是网络图片的本地地址
images[0] = res.path;
},
fail: function(res) {
console.log(res.toString() + "" + i);
}
});
wx.getImageInfo({
src: iurl + images[1],
success: function(res) {
console.log(res + i);
//res.path是网络图片的本地地址
images[1] = res.path;
},
fail: function(res) {
console.log(res.toString() + "" + i);
}
});
wx.getImageInfo({
src: iurl + images[2],
success: function(res) {
console.log(res + i);
//res.path是网络图片的本地地址
images[2] = res.path;
},
fail: function(res) {
console.log(res.toString() + "" + i);
}
});
wx.getImageInfo({
src: iurl + images[3],
success: function(res) {
console.log(res + i);
//res.path是网络图片的本地地址
images[3] = res.path;
},
fail: function(res) {
console.log(res.toString() + "" + i);
}
});
wx.getImageInfo({
src: iurl + images[4],
success: function(res) {
console.log(res + i);
//res.path是网络图片的本地地址
images[4] = res.path;
},
fail: function(res) {
console.log(res.toString() + "" + i);
}
});
wx.getImageInfo({
src: iurl + images[5],
success: function(res) {
console.log(res + i);
//res.path是网络图片的本地地址
images[5] = res.path;
},
fail: function(res) {
console.log(res.toString() + "" + i);
}
});
wx.getImageInfo({
src: iurl + images[6],
success: function(res) {
console.log(res + i);
//res.path是网络图片的本地地址
images[6] = res.path;
},
fail: function(res) {
console.log(res.toString() + "" + i);
}
});
wx.getImageInfo({
src: iurl + images[7],
success: function(res) {
console.log(res + i);
//res.path是网络图片的本地地址
images[7] = res.path;
},
fail: function(res) {
console.log(res.toString() + "" + i);
}
})
th.setData({
images: images
})
}
})