Commit b4faa5d88d9ddb7ba3308b10e410a3c43d0ccec5

Authored by F5VT98DI7XY4X12\Administrator
1 parent a87097a9

首页的js 定时器拼团,公用方法

pages/index/index/index.js
@@ -46,6 +46,12 @@ Page({ @@ -46,6 +46,12 @@ Page({
46 banner_index:0, 46 banner_index:0,
47 flash_index:0, 47 flash_index:0,
48 pt_index:0, 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 onLoad: function () { 56 onLoad: function () {
51 var th = this; 57 var th = this;
@@ -62,16 +68,34 @@ Page({ @@ -62,16 +68,34 @@ Page({
62 }else{ 68 }else{
63 await this.init_fir(); 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 onHide:function(){ 92 onHide:function(){
69 this.data.is_timer=0; 93 this.data.is_timer=0;
  94 + clearInterval(this.data.pt_timer)
70 }, 95 },
71 96
72 //同步初始加载 97 //同步初始加载
73 async init_load(){ 98 async init_load(){
74 -  
75 var th=this; 99 var th=this;
76 await getApp().get_isbuy(); 100 await getApp().get_isbuy();
77 this.setappdata(getApp().globalData.wxapp_buy_obj); 101 this.setappdata(getApp().globalData.wxapp_buy_obj);
@@ -467,7 +491,17 @@ Page({ @@ -467,7 +491,17 @@ Page({
467 ptSwiperChange:function (e) { 491 ptSwiperChange:function (e) {
468 var index=e.detail.current; 492 var index=e.detail.current;
469 this.setData({pt_index:index}); 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 \ No newline at end of file 508 \ No newline at end of file
utils/util.js
@@ -345,5 +345,6 @@ module.exports = { @@ -345,5 +345,6 @@ module.exports = {
345 sub_last: sub_last,//去掉末尾一个字符 345 sub_last: sub_last,//去掉末尾一个字符
346 measureText: measureText,//画布需要的函数 346 measureText: measureText,//画布需要的函数
347 check_mobile: check_mobile,//验证手机 347 check_mobile: check_mobile,//验证手机
  348 + get_rand_item:get_rand_item, //随机获取元素
348 349
349 }; 350 };