full_screen.js 2.16 KB
// components/userqy_pop_up/userqy_pop_up.js
var  o = getApp().globalData.setting
Component({
  /**
   * 页面的初始数据
   */
  data: {
    control: 1,
	is_full_screen_show:0,  //全屏显示
	sec_show:3,    //倒计时的秒数
	full_ad:null,  //全屏广告
	url:o.imghost,
	full_screen:0,
  },
  
  pageLifetimes:{
    //要处理一下,游客登录后的界面的变化,主要还该是改变会员
    show: function () {
		var th=this;
		th.setData({sec_show:3});	
		//--如果有全屏广告的时候--
		if(this.data.is_full_screen_show){
			 //--定时关闭--
			 th.data.full_screen=setInterval(function(){
			 	 if(!th.data.sec_show) {
			 		  clearInterval(th.data.full_screen);
			 		  th.close_full_screen();
			 		  return false;
			 	 }
			 	 th.data.sec_show--;
			 	 th.setData({sec_show:th.data.sec_show});		 
			 },1000)
		}						
    },
	hide: function() {
        // 页面被隐藏
		clearInterval(this.data.full_screen);
	},
  },
 
  properties: {
  
  },
  ready: function () {
    this.get_the_full_screen();
  },
  methods: {
    close_full_screen(){
    	this.setData({is_full_screen_show:0,sec_show:0});
    },
    //-- 跳转到满屏广告的链接 --
    go_full_ad(){
    	if(!this.data.full_ad) return false;
    	if(!this.data.full_ad.ad_weapplink) return false;
    	getApp().goto(this.data.full_ad.ad_weapplink);
		this.setData({is_full_screen_show:0});
    },   
    get_the_full_screen(){		
    	var th=this;
    	//获取全屏的广告
    	getApp().request.promiseGet("/api/weshop/ad/page?pid=1001&store_id=" + o.stoid,{
    		data: { enabled: 1 }
    	}).then(res=>{
             //判断是不是有全屏广告 	
    		 if(res.data.code==0 && res.data.data.pageData && res.data.data.pageData.length>0){
    			 th.setData({
    				 is_full_screen_show:1,
    				 full_ad:res.data.data.pageData[0]
    			 })
				 
				 //--定时关闭--
				 th.data.full_screen=setInterval(function(){
				 	 if(!th.data.sec_show) {
				 		  clearInterval(th.data.full_screen);
				 		  th.close_full_screen();
				 		  return false;
				 	 }
				 	 th.data.sec_show--;
				 	 th.setData({sec_show:th.data.sec_show});		 
				 },1000)
    		 }				
    	})
    }
  },
 
})