jfbuy.js 10.3 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
// packageA//pages/goods_share/goods_share.js
var app=getApp(),oo = app.globalData.setting,os=oo,ut = require("../../../utils/util.js");
var regeneratorRuntime = require('../../../utils/runtime.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
		// tab
		tab: ['全部','价格','销量','积分值'],
		currentIndex: 1,
		//促销页tab
		// tab2: ['订单促销','搭配促销','优惠促销'],
		// currentIndex2: 0,
		//秒杀和拼单底部tab
		// currentIndex3: 0,
		// 控制价格
		active1: false,
		// 控制佣金
		active2: false,
		url: oo.imghost,	
		h5_url:oo.h5_url,	
		//popup
		hiddenPopup: true,
		// 排序
		isUp: false,
		//控制滚动条至顶部时开启下拉刷新
		// open: false,
		requestData: null,
		
		list:[],
		is_load:0,     //是否正在加载
		is_no_data:0,  //没有数据
		is_no_more:0,  //没有更多数据
		key_str:'',
		pattern:0,      //分成的方式
		pageSize:10,
		currentPage:1,  //当前的页码
		
		// canvasHidden: 1, //-- 隐藏画布 --
		// dis_switch:0,    //-- 分销开关 --
		// pattern:0,       //-- 分成的方式 --
		// share_hidden:1,  //-- 分享的按钮隐藏 --
		// share_good:null, //--- 要分享的商品 --- 
		
		// timer:0,
		// hui_active:null, //优惠活动分享
		
		//点击活动详情的时候的响应
		list2:[],
		is_load2:0,
		is_no_data2:0,    //没有数据
		is_no_more2:0,    //没有更多数据
		currentPage2:1,   //页码
		prom_goods:null,  //优惠活动的条件
	
	
		triggered: false,
		isPullDownRefresh: false,
		
		
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	    var th=this;
	    this.data.requestData={
			store_id:oo.stoid,
			stype:1,
			stypeup:1,
			page:th.data.currentPage2,
			pageSize:th.data.pageSize			
		};
		
		var clientHeight = wx.getSystemInfoSync().windowHeight;
		var clientWidth = wx.getSystemInfoSync().windowWidth;
		this.data.clientHeight=clientHeight;
		this.data.clientWidth=clientWidth;
		
	  
		this.request_list(this.data.requestData);
     // var th=this;
     // //接受有没有导购的参数
     // var first_leader=options.first_leader;
     // if(first_leader){
     // 	  //--  user_id代过来免登录 --
     //      getApp().globalData.user_id=first_leader;
     // 	  getApp().getUserFir();
     //  }
			
      // this.requestGoodsList();	        
      //-- 自定义海报 --
      // getApp().request.promiseGet("/api/weshop/goods/poster/page",{	
      // 	data:{store_id:os.stoid, type:1, is_use:1 }
      // }).then(res=>{
      // 	if(res.data.code==0){
      		
      // 		var poster_data=res.data.data.pageData[0];
      // 		var json_str=poster_data.jsonStr;
      		
      // 		if(json_str){
      // 			var json_data=JSON.parse(json_str);		
      // 			if(json_data.bg_img){
      				
      // 				//-- 把图片那到本地 --
      // 				wx.getImageInfo({
      // 				  src:json_data.bg_img,
      // 				  success: function(res) {
      // 				    var path= res.path;
      // 					th.setData({share_b_img:path})
      // 				  },
      // 				  fail: function(res) {}
      // 				});
      // 			}		
      					
      // 			th.setData({poster:json_data})				
      							
      // 		}			
      // 	}
      // })	
      
      //获取分销的配置
   //    getApp().request.promiseGet("/api/weshop/storeDistribut/get/"+oo.stoid,{}).then(res=>{
		 // if(res.data.code==0){
			// th.setData({dis_switch:res.data.data.switch,pattern:res.data.data.pattern});
		 // }  
   //    })
	  
	  //获取用户设备信息,屏幕宽度
	  // wx.getSystemInfo({
	  //   success: res => {
	  //     th.setData({
	  //       screenWidth: res.screenWidth
	  //     })
	  //   }
	  // });
	 
	  //-- ---秒杀和拼团都要有定时器--- 
	  // if(!options.currentIndex || options.currentIndex<=1){
		 // //设置全局定时器
		 // th.data.timer=setInterval(function () {
		 //    th.countDown();
		 // },1000);
	  // }
	  
	  
	  //-- 判断有没有自定义的广告图片 --
	  getApp().request.get("/api/weshop/ad/page?pid=501&store_id=" + os.stoid, {
	    data: {
	      enabled: 1
	    },
		success:function(res){
			if(res.data.code==0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length>0){
				var a = res.data.data.pageData;
				var tt = {
				  'ad_code': os.imghost + a[0].ad_code,	
				};
				th.setData({ad:tt})			
			}
		}
	  })
	  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
	  //--清理定时器--
	  // clearInterval(this.timer);
  },
  /**e
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
		
	},

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
	 //  var th = this;	  
	 //  //礼包的转发
	 //  if(th.data.currentIndex==3){
		//   var lbid=th.data.hui_active.lbId;
		//   var url="pages/giftpack/giftpacklist/giftpacklist?lbId="+lbid+"&isBuy=1";
		//   if(getApp().globalData.user_id){
		//       url+="&first_leader="+getApp().globalData.user_id;
		//   }	 		  
		//   var img=this.data.share_img;	
		//   var title=th.data.hui_active.giftTitle;
		  
		//   var ob={
		//     title:title,
		//     path:url,
		//     imageUrl: img,
		//   };	
		//   th.setData({share_hidden:1});	  			 
		//   return ob;		  
		  
	 //  }else{
		//   //---秒杀,拼团,促销---  
		//   var item=this.data.share_good;
		//   if(item){
		// 	  var price = item.shop_price;
		// 	  var title= item.goods_name;		
		// 	  var img=this.data.url+item.original_img;		  
		// 	  var url="/pages/goods/goodsInfo/goodsInfo?goods_id=" + th.data.gid;
		// 	  if(getApp().globalData.user_id){
		// 	    url+="&first_leader="+getApp().globalData.user_id;
		// 	  }	  
		// 	  var ob={
		// 	    title: price + "元  " +title,
		// 	    path:url,
		// 	    imageUrl: img,
		// 	  };	
		// 	  th.setData({share_hidden:1,share_good:null});	  			 
		// 	  return ob;
		//   }else{
		// 	  var url="/pages/index/index/index";
		// 	  if(getApp().globalData.user_id){
		// 	      url+="?first_leader="+getApp().globalData.user_id;
		// 	  }	  
		// 	  var hui_active=this.data.hui_active;		  
		// 	  var title=hui_active.name;
		// 	  if(!title) title=hui_active.main_goods_name;
		// 	  if(!title) title=hui_active.giftTitle;
			  
		// 	  var ob={
		// 	    title: title,
		// 	    path:url,
		// 	  };	
		// 	  th.setData({share_hidden:1,share_good:null});	  			 
		// 	  return ob;				
		//   }		
	 //  }
	  
  // },
	

	//-- 点击tab --
	clickTab(e) {
		var th=this;
		var psize=th.data.curr
	
		this.setData({
			is_no_data2:0,
			is_no_more2:0,
			list2:[],
			is_load2: 0,
			currentPage2:1,
			pageSize:psize
		});
		var data = {
			store_id:oo.stoid,
			stype:e.target.dataset.index,
			stypeup:1,
			page:th.data.currentPage2,
			pageSize:psize
		};
		
	
		if(this.data.currentIndex!=e.target.dataset.index){
			this.setData({
				currentIndex: e.target.dataset.index,
				isUp: false,
			});

		} else {
			console.log('第2次点击');
			this.setData({
				isUp: !this.data.isUp
			});
		};
		
		if(this.data.isUp) {
			data.stypeup = 0;
		} else {
			data.stypeup = 1;
		};
		
		// this.data.requestData = data;
		this.setData({
			requestData: data
		})
		
		this.request_list(data);
	},
	

	
	
	request_list: function(data, callback){	
		// console.log('触发上拉刷新');
		
		var th = this;
		if(this.data.is_load2) return false;    //-- 正在加载
		if(this.data.is_no_data2) return false; //-- 没有数据
		if(this.data.is_no_more2) return false; //-- 没有更多
		
		// 开启加载状态
		this.data.is_load2=1;
		
		
		
		// var req_data = {
		// 	page:th.data.currentPage2
		// }

		app.request.promiseGet("/api/weshop/integralbuy/pageIntegralBuyGoodsList", {	
			data: data
		}).then(res=>{
			// 关闭加载状态
			th.data.is_load2=0;
			// 请求成功
			if(res.data.code==0 && res.data.data  && res.data.data.pageData) {
				if(res.data.data.pageData.length>0) {
					th.data.currentPage2++;
					var data = res.data.data.pageData;
					// 判断有无更多数据可以加载,如果大于则没有更多数据,反之则有
					if(res.data.data.page*res.data.data.pageSize > res.data.data.total){th.setData({is_no_more2:1});}		  									 
					var list=th.data.list2;
					list=list.concat(data);
					th.setData({list2:list});
				} else {
					if(th.data.currentPage==1){
						th.setData({is_no_data2:1});
					} else {
						th.setData({is_no_more2:1});
					}
				}	
				if(callback) callback();
			} else {
				wx.showToast({
				  title: res.data.msg,
				  icon: 'none',
				  duration: 2000
				})
			}
			console.log('xx',res);
		})	
	},
	
	//-- 滚动到底部 --
    request_list_lower:function(){		
	    var data=this.data.requestData;
		data.page=this.data.currentPage2;
		this.setData({
			requestData: data
		})
		this.request_list(data);
		
	},

  
	
	
	//---图片失败,默认图片---
	bind_bnerr2: function (e) {
	    var _errImg = e.target.dataset.errorimg;	
	    var _errObj = {};
	    _errObj[_errImg] ="/miniapp/images/default_g_img.gif";
	    this.setData(_errObj); //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
			// this.setData({['list2[0].original_img']:/miniapp/images/default_g_img.gif}); 
	},	 
	//-- ---更多加载---- 
	refresh:function(){
		this.request_list(this.data.requestData);
	},

	 
	 
	 // 页面滚动
	 onPageScroll (e) {
		 console.log(e);
	 	if(e.scrollTop == 0) {
	 		this.setData({open: true });
	 	} else {
	 		this.setData({open: false});
	 	}
	 },
		
	// 下拉刷新
	onPullDownRefresh() {
		var th = this;
		var data = this.data.requestData;
		
		if(this.isPullDownRefresh) return;
		// 触发下拉刷新开启
		this.isPullDownRefresh = true;

		this.setData({
			list2: [],
			currentPage2: 1,
			is_no_more2: 0
		});
		
		this.request_list(data, function() {
			th.setData({
				triggered: false,
			});
			th.isPullDownRefresh = false;
		});
	},
	
	// 点击查看
	viewItemDetails:function(e){
		 var index=e.currentTarget.dataset.index;
		 var item=this.data.list2[index];
		 var url="/pages/goods/goodsInfo/goodsInfo?goods_id="+item.goods_id;
		 getApp().goto(url);
	},
	
	
	imageLoad:function(e){
		var imgwidth = e.detail.width;
		var imgheight = e.detail.height;
		//宽高比
		var ratio = imgwidth / imgheight;
		//计算的高度值
		var viewHeight = this.data.clientWidth / ratio;
		var con_heihgt=this.data.clientHeight-viewHeight;
		this.setData({con_heihgt:con_heihgt})
	
	}
})