Commit b4faa5d88d9ddb7ba3308b10e410a3c43d0ccec5
1 parent
a87097a9
首页的js 定时器拼团,公用方法
Showing
2 changed files
with
37 additions
and
2 deletions
pages/index/index/index.js
| ... | ... | @@ -46,6 +46,12 @@ Page({ |
| 46 | 46 | banner_index:0, |
| 47 | 47 | flash_index:0, |
| 48 | 48 | pt_index:0, |
| 49 | + | |
| 50 | + pt_timer_item:null, | |
| 51 | + pt_timer_arr:null, | |
| 52 | + pt_timer:null, | |
| 53 | + pt_timer_active:0, | |
| 54 | + | |
| 49 | 55 | }, |
| 50 | 56 | onLoad: function () { |
| 51 | 57 | var th = this; |
| ... | ... | @@ -62,16 +68,34 @@ Page({ |
| 62 | 68 | }else{ |
| 63 | 69 | await this.init_fir(); |
| 64 | 70 | } |
| 71 | + | |
| 72 | + //--正再拼团中的处理-- | |
| 73 | + var url="/api/weshop/order/pageTuan?pt_status=1&is_pt=1&store_id="+os.stoid+"&pageSize=6&page=1" | |
| 74 | + await getApp().request.promiseGet(url,{}).then(res=>{ | |
| 75 | + if(res.data.code==0 && res.data.data && res.data.data.pageData){ | |
| 76 | + th.data.pt_timer_arr=res.data.data.pageData; | |
| 77 | + } | |
| 78 | + }) | |
| 79 | + if(th.data.pt_timer_arr && th.data.pt_timer_arr.length>0){ | |
| 80 | + for(var i in th.data.pt_timer_arr){ | |
| 81 | + var p_item=th.data.pt_timer_arr[i]; | |
| 82 | + await getApp().request.promiseGet("/api/weshop/users/get/"+os.stoid+"/"+p_item.user_id,{1:1}).then(res=>{ | |
| 83 | + th.data.pt_timer_arr[i].head_pic=res.data.data.head_pic; | |
| 84 | + }) | |
| 85 | + } | |
| 86 | + th.Interval_pt(); | |
| 87 | + } | |
| 88 | + | |
| 65 | 89 | }, |
| 66 | 90 | |
| 67 | 91 | //当隐藏的时候就关闭计时器 |
| 68 | 92 | onHide:function(){ |
| 69 | 93 | this.data.is_timer=0; |
| 94 | + clearInterval(this.data.pt_timer) | |
| 70 | 95 | }, |
| 71 | 96 | |
| 72 | 97 | //同步初始加载 |
| 73 | 98 | async init_load(){ |
| 74 | - | |
| 75 | 99 | var th=this; |
| 76 | 100 | await getApp().get_isbuy(); |
| 77 | 101 | this.setappdata(getApp().globalData.wxapp_buy_obj); |
| ... | ... | @@ -467,7 +491,17 @@ Page({ |
| 467 | 491 | ptSwiperChange:function (e) { |
| 468 | 492 | var index=e.detail.current; |
| 469 | 493 | this.setData({pt_index:index}); |
| 470 | - } | |
| 494 | + }, | |
| 471 | 495 | |
| 496 | + Interval_pt() { | |
| 497 | + var th=this; | |
| 498 | + this.data.pt_timer=setInterval(function () { | |
| 499 | + var item=ut.get_rand_item(th.data.pt_timer_arr); | |
| 500 | + th.setData({pt_timer_active:1,pt_timer_item:item}); | |
| 501 | + setTimeout(function () { | |
| 502 | + th.setData({pt_timer_active:0}); | |
| 503 | + },1000) | |
| 504 | + },3000); | |
| 505 | + } | |
| 472 | 506 | |
| 473 | 507 | }); |
| 474 | 508 | \ No newline at end of file | ... | ... |