diy_public.js
18.1 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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
// var e = function(e) {
// return e && e.__esModule ? e : {
// default: e
// };
// }(require("../../utils/LoadMore3.js")),
// n = new e.default(),
var t = getApp(),
a = t.request,
o = t.globalData.setting,
os = o,
i = require("../../utils/util.js"),
ut = i,
s = require("../../utils/common.js");
var regeneratorRuntime = require('../../utils/runtime.js');
Component({
properties: {
// 这里定义了innerText属性,属性值可以在组件使用时指定
object: {
type: Object,
value: null,
},
goods_array: {
type: Array,
value: []
},
newTime: {
type: Number,
value: 0
},
prom_type:{
type:Number,
value:0
}
},
data: {
// 这里是一些组件内部数据
yc: false,
someData: null,
ylp_img: "https://mshopimg.yolipai.net/",
imghost: os.imghost,
timer: null,
user_id:0,
img_width:100,
img_height:100,
swiperHeight:0,
prom_text:"已秒",
kttypeArr:['','商家','会员','阶梯'],
imgobj:{
'1':"/miniapp/images/component/seckill.png",
'2':"/miniapp/images/component/pingd/pingd.png",
'6':"/miniapp/images/component/pingd/pingd.png",
'8':"/miniapp/images/component/presale.png",
'9':"/miniapp/images/component/luckyactivity_new1.png",
// '9':"/images/luckyactivity_new.png",
},
nav1:'/packageH/pages/goodsInfo/goodsInfo?',
nav2:'/pages/goods/goodsInfo/goodsInfo?',
add_purchase:false,
},
pageLifetimes: {
//要处理一下,游客登录后的界面的变化,主要还该是改变会员
show: function () {
//会员身份变化
var th = this;
var g_id = this.data.object;
//只有再会员登陆之后,才重新调用接口
// console.log('秒杀组件------------');
// if(this.data.user_id!=getApp().globalData.user_id){
// this.data.user_id=getApp().globalData.user_id
// this.init(g_id);
// }
setTimeout(function () {
if (th.data.goods_array && th.data.goods_array.length > 0) {
th.data.timer = setInterval(function () {
th.countDown2(th);
}, 1000);
}
},600)
},
hide:function () {
// 页面被被销毁的时候,清除定时器
clearInterval(this.data.timer);
}
},
ready: function () {
if (this.data.prom_type==6) { //天天拼单
this.setData({
prom_text:'已团',
nav1:'/packageA/pages/serviceCard_pd/goodsInfo/goodsInfo?',
nav2:'/pages/goods/goodsInfo/goodsInfo?'
})
}
if (this.data.prom_type==2) { //团购
this.setData({
prom_text:'已团',
nav1:'/packageG/pages/group_buy/goodsInfo/goodsInfo?',
nav2:'/pages/goods/goodsInfo/goodsInfo?'
})
}
if (this.data.prom_type==8) { //预售
this.setData({
prom_text:'已售',
nav1:'/packageC/pages/presell/cardInfo/goodsInfo?',
nav2:'/packageC/pages/presell/goodsInfo/goodsInfo?'
})
}
if (this.data.prom_type==9) { //幸运购
this.setData({
prom_text:'已售',
nav1:'/packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo?',
nav2:'/packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo?'
})
}
var g_id = this.data.object;
this.init(g_id);
this.data.user_id=getApp().globalData.user_id;
},
detached() {
// 页面被被销毁的时候,清除定时器
clearInterval(this.data.timer);
},
methods: {
// 这里是一个自定义方法
customMethod: function () { },
init: function (g_id) {
var th = this;
this.loadImg(g_id)
getApp().getConfig2(function (e) {
var swithc_list = e.switch_list;
var sw_arr = JSON.parse(swithc_list);
if(sw_arr.is_retail_price){
th.setData({is_retail_price:1});
}
})
var app = getApp(), goodsidlist = "", idlist = "",new_idlist="";
if (g_id.data_type == 2) {
if (g_id.data && g_id.data.length > 0) {
//--先把商品ID串起来--
g_id.data.forEach(function (val, ind) {
var item = {};
goodsidlist += val.goodsid + ",";
idlist += val.flashid + ",";
if (val.idlist) {
new_idlist += val.idlist + ",";
}
})
goodsidlist = ut.sub_last(goodsidlist);
idlist = ut.sub_last(idlist);
if (new_idlist) {
new_idlist = ut.sub_last(new_idlist);
}
var user_id=getApp().globalData.user_id;
if(!user_id){ user_id=0;}
//--调用接口,读取秒杀--
// var gUrl = "/api/ms/flash_sale/getGoodsList?store_id=" + os.stoid + "&goodsidlist=" + goodsidlist+"&user_id="+user_id+"&type=1";
let gUrl = "/api/ms/flash_sale/getGoodsList?store_id=" + os.stoid + "&idlist=" + idlist + "&user_id="+user_id+"&type=1";
if (th.data.prom_type==6) { //天天拼单
if (new_idlist) {
gUrl="/api/weshop/teamlist/getGoodsList?store_id="
+os.stoid+"&isnew=1&idlist="+new_idlist;
}else{
gUrl="/api/weshop/teamlist/getGoodsList?store_id="
+os.stoid+"&goodsidlist="+goodsidlist;
}
}
if (th.data.prom_type==2) { //团购
gUrl="/api/weshop/goods/groupBuy/getGoodsList?isnew=1&store_id="
+os.stoid+"&aidlist="+goodsidlist + "&user_id="+user_id;
}
if (th.data.prom_type==8) { //预售
if (new_idlist) {
gUrl="/api/weshop/marketing/marketingPresellList/page?store_id="
+os.stoid+"&isnew=1&idlist="+new_idlist + "&user_id="+user_id+'&is_end=0&timetype=3&isuse=1';
// gUrl+="&isnew=1&idlist="+new_idlist
}else{
gUrl="/api/weshop/marketing/marketingPresellList/page?store_id="
+os.stoid+"&goodsidlist="+goodsidlist + "&user_id="+user_id+'&is_end=0&timetype=3&isuse=1';
}
}
if (th.data.prom_type==9) { //幸运购
gUrl="/api/weshop/prom/luckyActivity/getGoodsList?store_id="
+os.stoid+"&goodsidlist="+goodsidlist + "&user_id="+user_id+'&is_end=0&timetype=1&type=1';
}
app.request.promiseGet(gUrl, {}).then(res => {
//如果秒杀的数组为空的时候
var goodslist = res.data.data;
if (th.data.prom_type==8) { //预售
goodslist = res.data.data ? res.data.data.pageData : []
}
//就算是添加的活动已经过期,就要用最新的进行中活动
if (goodslist && goodslist.length > 0) {
th.set_goods_list(g_id.data, goodslist);
}
});
}
} else {
th.no_gid_set();
}
},
//当是默认的情况
no_gid_set() {
var user_id=getApp().globalData.user_id;
if(!user_id){ user_id=0;}
let req={ store_id: os.stoid, is_end: 0, is_show: 1, timetype: 2,user_id:user_id};
let gUrl="/api/ms/flash_sale/spikepage?page=1&pageSize=9"
if (this.data.prom_type==6) { //天天拼单
gUrl="/api/weshop/teamlist/pageteam/2?page=1&pageSize=9"
req={
store_id:os.stoid,
is_end: 0,
is_show: 1,
user_id:user_id,
}
}
if (this.data.prom_type==2) { //团购
gUrl="/api/weshop/goods/groupBuy/page?page=1&pageSize=9"
req={
store_id:os.stoid,
is_end: 0,
is_show: 1,
user_id:user_id,
timetype: 2,
}
}
if (this.data.prom_type==8) { //预售
gUrl="/api/weshop/marketing/marketingPresellList/page?page=1&pageSize=9"
req={
store_id:os.stoid,
is_end:0,
timetype:3,
isuse:1,
page:1,
user_id:user_id,
pageSize:9
}
}
if (this.data.prom_type==9) { //幸运购
gUrl="/api/weshop/prom/luckyActivity/page"
req={
store_id:os.stoid,
is_end:0,
timetype:1,
user_id:user_id,
// isuse:1,
// page:1,
// pageSize:9
}
}
getApp().request.promiseGet(gUrl,
{ isShowLoading: 1, data:req }
).then(res => {
if (res.data.code == 0 && res.data.data.pageData && res.data.data.pageData.length > 0) {
var goodsidlist = res.data.data.pageData;
this.set_goods_list(null, goodsidlist);
}
});
},
//就算是添加的活动已经过期,就要用最新的活动
set_goods_list(g_id, goodslist) {
let prom_type=this.data.prom_type
goodslist.forEach(function (vy, indy) {
if(!vy.id) vy.id=vy.prom_id;
if(vy.title && !vy.goods_name) vy.goods_name=vy.title;
})
// 判断火热,预热
var newTime = ut.gettimestamp(), all_array = [], th = this;
th.setData({ newTime: newTime });
if (g_id) {
goodslist.forEach(function (vy, indy) {
all_array.push(vy);
})
} else {
all_array = goodslist;
}
if (all_array.length == 0) {
all_array = goodslist;
}
for(let i in all_array){
let item=all_array[i];
if(item.user_price) item.price=item.user_price;
if(item.start_time > newTime) {
item.status = 0; //活动没开始
} else if(item.end_time > newTime) {
item.status = 1; // 活动进行中
};
}
var promisies = [];
if (th.data.prom_type !=8 && th.data.prom_type !=9) {
for (const key in all_array) {
if (Object.hasOwnProperty.call(all_array, key)) {
const val = all_array[key];
promisies[key] = getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" +
os.stoid + "/"+prom_type+"/" + val.id,
{}
).then(res => {
if (res.data.code == 0) {
if (res.data.data <= 0) all_array[key].status = 2;//已售完
};
});
}
}
}
Promise.all(promisies).then(() => {
// 判断活动是否结束
let empty=[]
for(let i in all_array){
let item=all_array[i];
if(newTime > item.end_time) {
all_array[i].status = 3; //活动结束
};
// let price=all_array[i].price.toFixed(2)
let price=all_array[i].price + ''
if (th.data.prom_type==8) { //预售
price = all_array[i].presell_price + ''
if (all_array[i].status ===0) {
all_array[i].goods_num=all_array[i].presell_sumqty*1 + all_array[i].virtual_qty*1
all_array[i].buy_num=all_array[i].buy_goodnum
}else{
all_array[i].goods_num=all_array[i].presell_sumqty*1 + all_array[i].virtual_qty*1
all_array[i].buy_num=all_array[i].buy_goodnum + all_array[i].virtual_qty*1
}
}
if (th.data.prom_type==9) { //幸运购
price = (all_array[i].group_price / 100) + ''
// all_array[i].buy_num = all_array[i].group_joined
all_array[i].buy_num = all_array[i].goods_num*1 - all_array[i].actLen*1
// all_array[i].goods_name = all_array[i].title
}
if (th.data.prom_type==2) { //团购
// price = (all_array[i].group_price / 100) + ''
// all_array[i].buy_num = all_array[i].group_joined
all_array[i].buy_num =all_array[i].buy_num + all_array[i].virtual_num*1
// all_array[i].goods_name = all_array[i].title
}
if (price && price.indexOf('.') > -1) {
let priceArr = price.split(".")
all_array[i].price_n = priceArr[0]
all_array[i].price_xs = priceArr[1]
}else{
all_array[i].price_n = price
}
all_array[i].residue=all_array[i].goods_num*1 - all_array[i].buy_num*1
all_array[i].residue = (all_array[i].residue >= 0) ? all_array[i].residue : 0
if (th.data.prom_type==9) { //幸运购
all_array[i].residue= all_array[i].actLen
}
if (th.data.prom_type==2) { //团购
all_array[i].residue += all_array[i].virtual_num*1
}
// console.error(all_array[i].residue);
if (all_array[i].residue && all_array[i].residue > 0 && all_array[i].status !=2) {
empty.push(all_array[i])
}
}
//控制已售罄是否显示
if (!th.data.object.hide_sold_out_items) {
all_array=empty
}
var arr = new Array();
if (th.data.object.style==7) {
//--三个三个一组---
for (var i = 0; i < all_array.length; i += 2) {
arr.push(all_array.slice(i, i + 2));
}
}else{
//--三个三个一组---
for (var i = 0; i < all_array.length; i += 3) {
arr.push(all_array.slice(i, i + 3));
}
}
/*--熏染到前台--*/
th.setData({ goods_array: arr });
if (th.data.object.style==6) {
th.setSwiper_h()
}
});
th.data.timer = setInterval(function () {
th.countDown2(th);
}, 1000);
},
setSwiper_h(){
var th=this
wx.createSelectorQuery().in(this).select('.swiper_h').boundingClientRect(rect => {
if (rect && rect.height) {
var sumHeigth=(rect.height+13)+'px'
th.setData({
swiperHeight: sumHeigth
})
}
}).exec();
// const query = this.createSelectorQuery()
// query.select('.swiper_h').boundingClientRect()
// query.exec( (res)=> {
// console.log(res)
// console.log(res[0].height)
// console.log(res[0].height * data.t.length)
// let sumHeigth = res[0].height * data.t.length;
// console.error('组件高度');
// console.log(sumHeigth);
// th.setData({
// swiperHeight: sumHeigth
// })
// })
},
//---小于10的格式化函数----
timeFormat: function (param) {
return param < 10 ? '0' + param : param;
},
//----秒杀倒计时函数-----
countDown2: function (ob) {
if (ob == undefined) return false;
var ee = ob;
// 获取当前时间,同时得到活动结束时间数组
var newTime = ut.gettimestamp();
this.setData({ newTime: newTime });
var List = ee.data.goods_array;
if (List.length == 0) return false;
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 (newTime < o.start_time) endTime = o.start_time;
let obj = null;
// 如果活动未结束,对时间进行处理
if (endTime - newTime > 0) {
let time = (endTime - newTime);
// 获取天、时、分、秒
let day = parseInt(time / (60 * 60 * 24));
let hou = parseInt(time % (60 * 60 * 24) / 3600);
let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
let 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'
}
}
let txt = "goods_array[" + j + "][" + i + "].djs";
if (!o.status && obj.day=='00' && obj.hou=='00' && obj.min=='00' && obj.sec=='01') {
let t1="goods_array[" + j + "][" + i + "].status";
ee.setData({
[t1]:1
})
}
ee.setData({
[txt]: obj
});
}
}
},
//图片失败,默认图片
bind_bnerr3: function (e) {
var _errImg = e.target.dataset.errorimg;
var _errObj = {};
_errObj[_errImg] = "/public/images/default_goods_image_240.gif";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
go_to: function () {
let url= "/pages/activity/seckill_list/seckill_list"
if (this.data.prom_type==6) { //天天拼单
url="/pages/activity/pind_list/pind_list"
}
if (this.data.prom_type==2) { //团购
url="/packageC/pages/group_list/group_list";
}
if (this.data.prom_type==8) { //预售
url="/packageC/pages/presell/list/list";
}
if (this.data.prom_type==9) { //幸运购
url="/packageC/pages/luckyGo/luckyGo_activityList/luckyGo_activityList";
}
wx.navigateTo({
url
});
},
//加入购物车
shoppingCart(){
console.log('加入购物车');
},
loadImg(g_id){
if (g_id.style==1) {
let w=''
switch (g_id.picture_scale) {
case 1:
w=`width:calc(100%-${g_id.page_margins*2}px);height:calc(100%-${g_id.page_margins*2}px)`
break;
default:
break;
}
}
},
// 加购方法show
addPurchase(even){
this.setData({
add_purchase:true
})
let gid = even.currentTarget.dataset.gid
let prom_id = even.currentTarget.dataset.prom_id
let prom_type = even.currentTarget.dataset.prom_type
let add_purchase = this.selectComponent("#add_purchase");
if (add_purchase) {
add_purchase.init(gid,prom_type,prom_id)
}
},
// 加购方法 hide
hide_add_purchase(){
setTimeout(()=>{
this.setData({
add_purchase:false
})
},1000)
}
},
})