index.js 2.43 KB
var app = getApp(), os = app.globalData.setting;

Component({
	data:{		
		fontcolor:'#6e6d6b',
		fontcolor_sele:'#f23030',
		backgroundColor:'#ffffff',	
		active:-1,	
		list:app.def_list,		
		cartGoodsNum:0,
	},
	

	lifetimes: {
	  attached: function() {
		   var th=this;
	     
		   getApp().promiseGet("/api/weshop/storeDistribut/get/"+os.stoid,{}).then(rs=>{
		   	  var dis=rs.data.data;	
		   	  if( dis && dis.switch==0){
		   		   th.setData({is_no_distri:1})
		   	  }	   				  
		   })	
		   
		   getApp().promiseGet("/store/storemoduleendtime/page?store_id=" +os.stoid + "&type=5",{}).then(res=>{
			    if(res.data.code==0){
					  var arr = res.data.data.pageData;
					  if (arr.length > 0) {
						   var item=arr[0];
						   if(item.is_sy==0){
							   var now = Date.parse(new Date());now = now / 1000;
							   if(item.end_time<now) th.setData({is_no_distri:1})
						   }
					  }
				} 
		   })
		   
		  	  
	       //购物车显示商品金额
		   this.setData({cartGoodsNum:getApp().globalData.cartGoodsNum}); 	  
		   var th=this;
		   		 	 	  
		   var is_read=getApp().globalData.is_read;
		   var custum_data=getApp().globalData.custum_data;		   
		   if(is_read){
			    if(custum_data){
					 this.set_list(custum_data);
				}								
		   }else{
			 var stoid=os.stoid
			 getApp().request.promiseGet("/api/weshop/storeFooter/get/"+stoid, {
			 }).then(res => {
			     getApp().globalData.is_read=true;
			     var e = res;
			     if(e.data.code != -1){			       			         
					 var itemList = e.data.data.data;
			         itemList = JSON.parse(itemList)			 
			         //如果是有定义自定义导航的小程序链接
			         if(itemList[0].weappurl && itemList[0].weappurl!=""){						 
						 getApp().globalData.custum_data=e.data.data;
						 var custum_data=e.data.data;	
						 th.set_list(custum_data);									             
			         }
					
			     }			 
			    
			 })  
		   }		  
	  },
  }, 
  

  methods: {
		//设置自定义页面的列表
		set_list:function(data){			
			var itemList = data.data;
			itemList = JSON.parse(itemList);			
			this.setData({
				list:itemList,
				backgroundColor: data.bkcolor,
				fontcolor_sele: data.fontcolor_sele,
				fontcolor:data.fontcolor,
				is_custum:1
			})
						
		},
		
		nav_goto:function(e){
			var url=e.currentTarget.dataset.url;
			if(!url) return false;
			if(url[0]!='/') url='/'+url;
			//wx.switchTab({url:url,})			
			getApp().goto(url);		
		}
		
  }
  
	
})