myGiftDetails.js 12.8 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 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
// packageA//pages/myGiftDetails/myGiftDetails.js
const app = getApp();
let self = null;
var os = app.globalData.setting;
var ut = require("../../../utils/util.js");
var t_pay = require("../../../utils/pay2.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
	  qr_code_object: {
		  val: "12121",
		  content: "当前核销码仅限当面使用!"
	  },
		showBtn: true,
		isClick: false,
	  is_summit_ing: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  //定义第一次进入
	  this.data.fir_in=1;

	  self = this;
		
		// 如果从商品详情页点击促销栏里的礼包跳转过来的话,不显示底部按钮
		// showBtn 控制按钮是否显示
		let showBtn = this.data.showBtn;
		if(options.btn == 0) {
			showBtn = false;
		}
		
		this.setData({
			options: options,
			id: options.id,
			index: options.index,
			showBtn: showBtn,
		})

	  getApp().getConfig2(function (e) {
		  var json_d = JSON.parse(e.switch_list);
		  self.setData({
			  bconfig: e,
			  is_retail_price: json_d.is_retail_price || 0
		  });
	  })

		// console.log('options', options);
		app.isLogin().then(function(data) {//进入页面前已经授权登录成功
			self.setData({
				userInfo: data,
			});
		});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

	  this.data.is_summit_ing=0;
	  var th=this;
      //判断是不是第一次进入
	  if(this.data.fir_in){
		  this.data.fir_in=0;
	  }else{
		  ut.fy_back('',0)
		  t_pay.set_fir();

		  //-- 通联的第三方支付的返回优化 --
		  ut.is_pay_ok(th.data.ok_order_sn,"/packageA/pages/libao_payment/payment?type=2","none",function (){
			  console.log('is_pay_ok');
			  console.log(th.data.ok_order_sn);
			  if(!th.data.ok_order_sn) return false;

			  var b_url="/api/weshop/libao/libaoFormvip/page";
			  var rq_data={
				  store_id: app.globalData.setting.stoid,
				  user_id: app.globalData.user_id,
				  number: th.data.ok_order_sn
			  };

			  getApp().request.promiseGet(b_url,
				  {data:rq_data}).then(res=>{

				  console.log('is_pay_ok2');
				  console.log('1111111');

				  if(ut.ajax_ok(res)){

					  var item=res.data.data.pageData[0];
					  if(item.fbillstate==1){
						  //支付支付,返回首页
						  ut.m_toast('支付成功');
						  setTimeout(()=>{
							  getApp().goto("/packageA/pages/libao_payment/payment?type=2");
						  },1000)

					  }else{
						  //支付支付,返回首页
						  ut.m_toast('支付失败');
						  setTimeout(()=>{
							  getApp().goto("/pages/index/index/index");
						  },1000)
					  }
				  }
			  })
		  });

	  }

        getApp().check_can_share();
		if(app.globalData.userInfo) {
			if(!this.data.isLogin) {
				this.setData({
					userInfo: app.globalData.userInfo,
					imghost: app.globalData.setting.imghost,
					isLogin: true,
				});
				
				let url = '';
				// let data = {
				// 	store_id: app.globalData.setting.stoid,
				// 	user_id: app.globalData.user_id,
				// };
				//购买的时候是0,购买后是1
				if(this.data.index == 0) {
					// data.lbid = this.data.id;
					// 请求数据
					app.request.promiseGet('/api/weshop/libao/libaoForm/page', {
						data: {
							store_id: app.globalData.setting.stoid,
							id: this.data.id,
						},
						isShowLoading: true,
					}).then(function(res) {

						if(res.data.code==0 &&  res.data.data  &&  res.data.data.pageData &&  res.data.data.pageData.length>0){
							var da= res.data.data.pageData[0]
                            self.setData({ details:da, });

							//活动还未开始
							if(da.startime>ut.gettimestamp()){
                                self.setData({ is_not_start:1, });
							}



							console.log(da);
							//礼包有俩种类型
							if(da.lbtype==1){
                                app.request.promiseGet('/api/weshop/libao/libaoList/page', {
                                    data: {
                                        store_id: app.globalData.setting.stoid,
                                        lbid: self.data.id,pageSize:500
                                    },
                                    isShowLoading: true,
                                }).then(function(res) {
                                    self.setData({
                                        list: res.data.data.pageData,
                                    });
                                });
							}else{
                                app.request.promiseGet('/api/weshop/libao/libaoList/listLQ', {
                                    data: {
                                        store_id: app.globalData.setting.stoid,
                                        lbid: self.data.id,
                                    },
                                    isShowLoading: true,
                                }).then(function(res) {
									console.log(res);
                                	if(res.data.code==0){
                                        self.setData({
                                            list: res.data.data,
                                        });
									}
                                });
							}

						}
					});

				} else if(this.data.index == 1) {
					app.request.promiseGet('/api/weshop/libao/libaoFormvip/page', {
						data: {
							store_id: app.globalData.setting.stoid,
							user_id: app.globalData.user_id,
							id: this.data.id
						},
						isShowLoading: true,
					}).then(function(res) {
						// console.log('res3-->', res);
						if(res.data.code==0  && res.data.data && res.data.data.pageData && res.data.data.pageData.length>0){

							var da= res.data.data.pageData[0]
							self.setData({
								details:da,
							});

							if(da.lbtype==1){
                                app.request.promiseGet('/api/weshop/libao/libaoListvip/page', {
                                    data: {
                                        store_id: app.globalData.setting.stoid,
                                        lbvipid: self.data.id,pageSize:500
                                    },
                                    isShowLoading: true,
                                }).then(function(res) {
                                    // console.log('res4-->', res);
                                    if(res.data.code==0  && res.data.data && res.data.data.pageData && res.data.data.pageData.length>0) {
                                        var list_arr=res.data.data.pageData;
                                        for(var i in list_arr){
                                            list_arr[i].alsonum= list_arr[i]['goods_num'] - list_arr[i]['usenum'];//剩余次数
                                        }
                                        self.setData({
                                            list: res.data.data.pageData,
                                        });
                                    }
                                });
							}else{
                                app.request.promiseGet('/api/weshop/libao/libaoListvip/listLQ', {
                                    data: {
                                        store_id: app.globalData.setting.stoid,
                                        lbvipid: self.data.id,
                                        user_id:app.globalData.user_id
                                    },
                                    isShowLoading: true,
                                }).then(function(res) {
									console.log(res);
                                    // console.log('res4-->', res);
                                    if(res.data.code==0  && res.data.data) {
                                        self.setData({
                                            list: res.data.data,
                                        });
                                    }
                                });
							}

						}
					});
				};
			};
		};
  },

	/**
   * 用户点击右上角分享
   */
   onShareAppMessage: function () {   	  getApp().globalData.no_clear=1

  },

	//-- 礼包购买 --
	GetBuyPrice: function(e) {

	    if(this.data.is_summit_ing) return false;
		this.data.is_summit_ing=1;

		var th = this,that=th;
		var item=th.data.details;
		var id = item.id; //活动id
		var my_confirm = th.selectComponent("#my_confirm"); //组件的id
		var user=getApp().globalData.userInfo;

		my_confirm.open(
			"是否确定购买该礼包",
			"取消",
			"确定",
			function() {
				my_confirm.open_cancel(0);
			},
			function() {
				my_confirm.open_cancel(0);
				var json = {
					"lbid": id, //活动Id
					"paytype": 2, //1=积分兑换 2=购买
					"store_id": os.stoid, //商家Id
					"user_id": user.user_id, //用户ID
				};

				t_pay.set_pay_url("/api/weshop/libao/libaoFormvip/libaoOrder");
				t_pay.pay(json,function (){
					getApp().my_warnning("支付成功", 1, th);
					setTimeout(function (){
						getApp().goto("/packageA/pages/libao_payment/payment?type=2");
					},1000)
				},function (msg){
					th.data.is_summit_ing=0;
					getApp().my_warnning(msg, 0, th);
				},th)

				// var url = "/api/weshop/libao/libaoFormvip/libaoOrder";
				// getApp().request.post(url,
				// 	{
				// 		data:json,
				// 		success:function(res) {
				// 			if (res.data.code == 0 && res.data.data) {
				// 				res = res.data.data;
				//
				// 				getApp().globalData.no_clear=1;
				//
				// 				wx.requestPayment({
				// 					timeStamp: String(res.timeStamp),
				// 					nonceStr: res.nonceStr,
				// 					package: res.packageValue,
				// 					signType: res.signType,
				// 					paySign: res.paySign,
				// 					success: function(res) {
				// 						getApp().my_warnning("支付成功", 1, th);
				// 						setTimeout(function (){
				// 							getApp().goto("/packageA/pages/libao_payment/payment?type=2");
				// 						},1000)
				// 					},
				// 					fail: function(res) {
				// 						getApp().my_warnning("取消支付", 0, th);
				// 					}
				// 				});
				// 			} else {
				// 				getApp().my_warnning(res.data.msg, 0, th);
				// 			}
				// 		}
				// 	})
			})
	},

	//-- 积分兑换 --
	GetBuyIntegral: function(e) {
		var th = this,that=th;
		var item=th.data.details;

		var id = item.id; //活动id
		var my_confirm = th.selectComponent("#my_confirm"); //组件的id
		var user=getApp().globalData.userInfo;
		my_confirm.open(
			"是否确定兑换该礼包",
			"取消",
			"确定",
			function() {
				my_confirm.open_cancel(0);
			},
			function() {
				my_confirm.open_cancel(0);
				var json = {
					"lbid": id, //活动Id
					"paytype": 1, //1=积分兑换 2=购买
					"store_id": os.stoid, //商家Id
					"user_id": user.user_id, //用户ID
				};
				var url = "/api/weshop/libao/libaoFormvip/libaoOrder";
				getApp().request.post(url,{
					data:json,
					success:function(res) {
						if (res.data.code == 0) {
							getApp().my_warnning("兑换成功!", 1, th);
							setTimeout(function (){
								getApp().goto("/packageA/pages/libao_payment/payment?type=1");
							},1000)
						} else {
							getApp().my_warnning(res.data.msg, 0, th);
						}
					},
				})

			})
	},

	//显示二维码,进行核销
	show_hxm:function (e){
  	   var th=this;
  	   var type=e.currentTarget.dataset.type;
  	   var data={};
	   data.store_id=os.stoid;
  	   data.user_id=getApp().globalData.user_id;

  	   if(type && parseInt(type)==1){
		   data.id=this.data.id;
		   data.type=1;
	   }else{
		   var index=e.currentTarget.dataset.index;
		   var item=this.data.list[index];
		   data.id=item.id;
		   data.type=2;
	   }

  	   //获取二维码
  	   getApp().request.get("/api/weshop/libao/libaoListvip/getLibaoCode",{
  	   	   data:data,
		   success:function (res){
			   console.log(res);
               if(res.data.code==0){
				   th.data.qr_code_object.val=res.data.data;
				   var qc_com = th.selectComponent("#qrcode"); //组件的id
				   qc_com.open(th.data.qr_code_object)
			   }else{
				   wx.showToast({
					   title: res.data.msg,
					   icon: 'none',
					   duration: 2000
				   })
				   
			   }
		   }
	   })

	},

	//一键领取券
    show_get_quan:function (e) {
			if(this.data.isClick) return false;
			if(!this.data.isClick) {
					this.data.isClick = true;
					let th=this;
				  let json = {
				      store_id:os.stoid,
				      user_id:getApp().globalData.user_id,
							id:this.data.id
				  };
				  let url = "/api/weshop/libao/libaoFormvip/saveLibaoQuan";
				  getApp().request.post(url,{
				      data:json,
				      success:function(res) {
				          if (res.data.code == 0) {
				              th.setData({'details.isget':1});
				          } else {
				              wx.showToast({
				                  title: res.data.msg,
				                  icon: 'none',
				                  duration: 2000
				              })
											th.data.isClick = false;
				          }
									
				      },
				  });
					
			}
				

    }


})