Commit 957c2e4b36026625aa4745059e9b1d7fba187115
1 parent
3152bb36
购物车 再调用券的时候,不等券的调用,让商品能够显示
Showing
2 changed files
with
118 additions
and
128 deletions
pages/cart/cart2/cart2.js
... | ... | @@ -113,11 +113,7 @@ Page({ |
113 | 113 | onShow: function() { |
114 | 114 | var th=this; |
115 | 115 | if (th.data.isclose==0){ |
116 | - /*--- | |
117 | - wx.navigateTo({ | |
118 | - url: "/pages/user/index/index" | |
119 | - //url: "/pages/index/index/index" | |
120 | - })---*/ | |
116 | + | |
121 | 117 | wx.switchTab({ |
122 | 118 | url: "/pages/index/index/index" |
123 | 119 | }) |
... | ... | @@ -131,7 +127,7 @@ Page({ |
131 | 127 | th.setData({user_addr: ie }); |
132 | 128 | var going=0; |
133 | 129 | |
134 | - //使用计算器,避免空现象 | |
130 | + //使用计时器,避免空现象 | |
135 | 131 | var jishi= setInterval(function () { |
136 | 132 | if (th.data.is_b_now == 1 && going==0) { |
137 | 133 | if(th.data.bn_goods) { |
... | ... | @@ -243,7 +239,7 @@ Page({ |
243 | 239 | data: { |
244 | 240 | user_id: to.globalData.user_id, selected:1, |
245 | 241 | store_id: oo.stoid, pageSize: 600 }, |
246 | - success: async function (su) { | |
242 | + success:function (su) { | |
247 | 243 | //按门店分类的数组 |
248 | 244 | var arr = new Array(); |
249 | 245 | var carr = su.data.data.pageData; |
... | ... | @@ -305,74 +301,13 @@ Page({ |
305 | 301 | arr.push(ie); |
306 | 302 | } |
307 | 303 | } |
308 | - | |
309 | - //------------开始计算使用优惠券相关------------ | |
310 | - for(var ind in arr){ | |
311 | - var ep=arr[ind]; | |
312 | - var goodlist=ep.goods; | |
313 | - | |
314 | - //--更优惠券抵用有关,立即购买的,如果是购物车,如果有等级价还有考虑等级价的东西 | |
315 | - //就要把相应的值,写入cartlist数组中-- | |
316 | - var ckeck_quan_price=0, | |
317 | - check_quan_price_list='', | |
318 | - check_quan_ware_list=''; | |
319 | - | |
320 | - for(var i in goodlist){ | |
321 | - var gd=goodlist[i]; | |
322 | - //--如果是秒杀就跳出-- | |
323 | - if(gd.prom_type==1){ continue; } | |
324 | - var item_price=gd.goods_price*gd.goods_num; | |
325 | - ckeck_quan_price+=item_price; | |
326 | - | |
327 | - //--组装价格list-- | |
328 | - if (check_quan_price_list) { | |
329 | - check_quan_price_list += "," +item_price; | |
330 | - } else { | |
331 | - check_quan_price_list = item_price; | |
332 | - } | |
333 | - //--组装商品的线下erpwareid-- | |
334 | - if (check_quan_ware_list) { | |
335 | - check_quan_ware_list += "," +gd['erpwareid']; | |
336 | - } else { | |
337 | - check_quan_ware_list = gd['erpwareid']; | |
338 | - } | |
339 | - } | |
340 | - | |
341 | - arr[ind].ckeck_quan_price=ckeck_quan_price; | |
342 | - arr[ind].check_quan_ware_list=check_quan_ware_list; | |
343 | - arr[ind].check_quan_price_list=check_quan_price_list; | |
344 | - | |
345 | - //是否关闭使用优惠券 | |
346 | - if (th.data.is_close_quan != 1) { | |
347 | - //调用接口,获取优惠券的列表 | |
348 | - var url="/api/weshop/couponList/getUseCouponList"; | |
349 | - await app.request.promiseGet(url,{ | |
350 | - data:{storeId:oo.stoid,userId:app.globalData.user_id,BuySum:ckeck_quan_price,WareIds:check_quan_ware_list,pageSize:100} | |
351 | - }).then(res=>{ | |
352 | - if(res.data.code==0) | |
353 | - arr[ind].quan_list=res.data.data.pageData; | |
354 | - }) | |
355 | - | |
356 | - var frozenQuan=null; | |
357 | - var url0="/api/weshop/users/frozenQuan/listFrozenQuan/"+app.globalData.user_id; | |
358 | - await app.request.promiseGet(url0,{1:1}).then(res=>{ | |
359 | - if(res.data.code==0){ | |
360 | - frozenQuan=res.data.data; | |
361 | - } | |
362 | - }) | |
363 | - | |
364 | - if (frozenQuan && arr[ind].quan_list){ | |
365 | - arr[ind].quan_list=th.check_is_frozenQuan(arr[ind].quan_list,frozenQuan); | |
366 | - } | |
367 | - | |
368 | - } | |
369 | - } | |
370 | - | |
371 | 304 | th.setData({ |
372 | 305 | cartlist: arr, |
373 | 306 | }), |
374 | 307 | |
375 | 308 | th.calculatePrice(); |
309 | + //--- 获取一下看有没有优惠券 ---- | |
310 | + th.get_cart_quan(); | |
376 | 311 | } |
377 | 312 | }); |
378 | 313 | }, |
... | ... | @@ -381,7 +316,6 @@ Page({ |
381 | 316 | get_buy_goods: function (e){ |
382 | 317 | var th=this; |
383 | 318 | var gg = to.get_b_now(); |
384 | - | |
385 | 319 | //--------如果goods_id一样,就是要立即购买----- |
386 | 320 | if(e==gg.goods_id){ |
387 | 321 | a.get("/api/weshop/goods/get/" + oo.stoid+"/"+e, { |
... | ... | @@ -408,7 +342,6 @@ Page({ |
408 | 342 | } |
409 | 343 | } |
410 | 344 | |
411 | - | |
412 | 345 | switch (gd.prom_type){ |
413 | 346 | case 0: |
414 | 347 | case 2: |
... | ... | @@ -419,46 +352,21 @@ Page({ |
419 | 352 | //--此时开始计算商品的使用券相关,如果有等级价还要计算和等级价相关的, |
420 | 353 | // 如果有优惠促销,还要把促销的部分计算在内,因为促销还有不能使用优惠券-- |
421 | 354 | t.data.data.shop_price=gg.goods_price; |
422 | - | |
423 | 355 | th.data.ckeck_quan_price=t.data.data.shop_price*gg.goods_num; |
424 | 356 | th.data.check_quan_price_list=t.data.data.shop_price*gg.goods_num+""; |
425 | 357 | th.data.check_quan_ware_list=t.data.data.erpwareid+""; |
426 | 358 | |
427 | - var quanlist=null; | |
428 | - | |
429 | - if (th.data.is_close_quan != 1) { | |
430 | - var url="/api/weshop/couponList/getUseCouponList"; | |
431 | - await app.request.promiseGet(url,{ | |
432 | - data:{storeId:oo.stoid,userId:app.globalData.user_id,BuySum:th.data.ckeck_quan_price,WareIds:th.data.check_quan_ware_list,pageSize:100} | |
433 | - }).then(res=>{ | |
434 | - if(res.data.code==0) | |
435 | - quanlist=res.data.data.pageData; | |
436 | - | |
437 | - | |
438 | - }) | |
439 | - } | |
440 | - | |
441 | - var frozenQuan=null; | |
442 | - var url0="/api/weshop/users/frozenQuan/listFrozenQuan/"+app.globalData.user_id; | |
443 | - await app.request.promiseGet(url0,{1:1}).then(res=>{ | |
444 | - if(res.data.code==0){ | |
445 | - frozenQuan=res.data.data; | |
446 | - } | |
447 | - }) | |
448 | - | |
449 | - if (frozenQuan && quanlist){ | |
450 | - quanlist=th.check_is_frozenQuan(quanlist,frozenQuan); | |
451 | - } | |
452 | - | |
453 | 359 | t.data.data.prom_id = 0; |
454 | 360 | t.data.data.prom_type = 0; |
455 | 361 | |
456 | 362 | th.setData({ |
457 | 363 | bn_goods: t.data.data, bn_pickname: gg.pick_name, bn_exp_type: et,index:m_wind, |
458 | - bn_pick: gg.pick_id, bn_t_exp_t: distr_t,selected_quan_list:quanlist | |
364 | + bn_pick: gg.pick_id, bn_t_exp_t: distr_t | |
459 | 365 | }); |
460 | 366 | //计算价格 |
461 | 367 | th.calculatePrice2(); |
368 | + //获取优惠券 | |
369 | + th.get_buy_now_quan(); | |
462 | 370 | |
463 | 371 | break; |
464 | 372 | case 1: //---秒杀----- |
... | ... | @@ -474,37 +382,16 @@ Page({ |
474 | 382 | th.data.ckeck_quan_price=t.data.data.shop_price*gg.goods_num; |
475 | 383 | th.data.check_quan_price_list=t.data.data.shop_price*gg.goods_num+""; |
476 | 384 | th.data.check_quan_ware_list=t.data.data.erpwareid+""; |
477 | - | |
478 | - if (th.data.is_close_quan != 1) { | |
479 | - | |
480 | - var url="/api/weshop/couponList/getUseCouponList"; | |
481 | - await app.request.promiseGet(url,{ | |
482 | - data:{storeId:oo.stoid,userId:app.globalData.user_id,BuySum:th.data.ckeck_quan_price,WareIds:th.data.check_quan_ware_list,pageSize:100} | |
483 | - }).then(res=>{ | |
484 | - if(res.data.code==0) | |
485 | - quanlist=res.data.data.pageData; | |
486 | - }) | |
487 | - | |
488 | - var frozenQuan=null; | |
489 | - var url0="/api/weshop/users/frozenQuan/listFrozenQuan/"+app.globalData.user_id; | |
490 | - await app.request.promiseGet(url0,{1:1}).then(res=>{ | |
491 | - if(res.data.code==0){ | |
492 | - frozenQuan=res.data.data; | |
493 | - } | |
494 | - }) | |
495 | - | |
496 | - if (frozenQuan && quanlist){ | |
497 | - quanlist=th.check_is_frozenQuan(quanlist,frozenQuan); | |
498 | - } | |
499 | - } | |
500 | 385 | } |
501 | 386 | |
502 | 387 | th.setData({ |
503 | 388 | bn_goods: t.data.data, bn_pickname: gg.pick_name, bn_exp_type: et,index:m_wind, |
504 | - bn_pick: gg.pick_id, bn_t_exp_t: distr_t,selected_quan_list:quanlist | |
389 | + bn_pick: gg.pick_id, bn_t_exp_t: distr_t | |
505 | 390 | }); |
506 | 391 | //计算价格 |
507 | 392 | th.calculatePrice2(); |
393 | + //获取优惠券 | |
394 | + th.get_buy_now_quan(); | |
508 | 395 | } |
509 | 396 | }); |
510 | 397 | |
... | ... | @@ -1397,7 +1284,9 @@ Page({ |
1397 | 1284 | |
1398 | 1285 | //--验证是否已经冻结-- |
1399 | 1286 | check_is_frozenQuan:function(quanlist,frozenQuan){ |
1400 | - console.log("券列表",quanlist); | |
1287 | + console.log("券列表",quanlist); | |
1288 | + if(!quanlist) return null; | |
1289 | + if(!frozenQuan) return quanlist; | |
1401 | 1290 | var arr=[]; |
1402 | 1291 | for(var i=0;i<quanlist.length;i++){ |
1403 | 1292 | var item=quanlist[i]; |
... | ... | @@ -1519,7 +1408,99 @@ Page({ |
1519 | 1408 | } |
1520 | 1409 | } |
1521 | 1410 | },500); |
1522 | - } | |
1411 | + }, | |
1412 | + //-----获取购物车进来的劵------- | |
1413 | + get_cart_quan:function () { | |
1414 | + var arr=this.data.cartlist,th=this; | |
1415 | + //------------开始计算使用优惠券相关------------ | |
1416 | + for(var ind in arr){ | |
1417 | + var ep=arr[ind]; | |
1418 | + var goodlist=ep.goods; | |
1419 | + //--更优惠券抵用有关,立即购买的,如果是购物车,如果有等级价还有考虑等级价的东西 | |
1420 | + //就要把相应的值,写入cartlist数组中-- | |
1421 | + var ckeck_quan_price=0, | |
1422 | + check_quan_price_list='', | |
1423 | + check_quan_ware_list=''; | |
1424 | + | |
1425 | + for(var i in goodlist){ | |
1426 | + var gd=goodlist[i]; | |
1427 | + //--如果是秒杀就跳出-- | |
1428 | + if(gd.prom_type==1){ continue; } | |
1429 | + var item_price=gd.goods_price*gd.goods_num; | |
1430 | + ckeck_quan_price+=item_price; | |
1431 | + | |
1432 | + //--组装价格list-- | |
1433 | + if (check_quan_price_list) { | |
1434 | + check_quan_price_list += "," +item_price; | |
1435 | + } else { | |
1436 | + check_quan_price_list = item_price; | |
1437 | + } | |
1438 | + //--组装商品的线下erpwareid-- | |
1439 | + if (check_quan_ware_list) { | |
1440 | + check_quan_ware_list += "," +gd['erpwareid']; | |
1441 | + } else { | |
1442 | + check_quan_ware_list = gd['erpwareid']; | |
1443 | + } | |
1444 | + } | |
1523 | 1445 | |
1446 | + arr[ind].ckeck_quan_price=ckeck_quan_price; | |
1447 | + arr[ind].check_quan_ware_list=check_quan_ware_list; | |
1448 | + arr[ind].check_quan_price_list=check_quan_price_list; | |
1524 | 1449 | |
1450 | + //是否关闭使用优惠券 | |
1451 | + if (th.data.is_close_quan != 1) { | |
1452 | + var frozenQuan=null; | |
1453 | + var url0="/api/weshop/users/frozenQuan/listFrozenQuan/"+app.globalData.user_id; | |
1454 | + app.request.promiseGet(url0,{1:1}).then(res=>{ | |
1455 | + if(res.data.code==0){ frozenQuan=res.data.data; } | |
1456 | + //--调用接口,获取优惠券的列表,3秒钟内控制接口请求-- | |
1457 | + var url="/api/weshop/couponList/getUseCouponList"; | |
1458 | + app.request.time_limit_get(6,url,{ | |
1459 | + data:{storeId:oo.stoid,userId:app.globalData.user_id,BuySum:ckeck_quan_price,WareIds:check_quan_ware_list,pageSize:100}, | |
1460 | + success:function (res) { | |
1461 | + if (res.data.code == 0) { | |
1462 | + arr[ind].quan_list = res.data.data.pageData; | |
1463 | + arr[ind].quan_list = th.check_is_frozenQuan(arr[ind].quan_list, frozenQuan); | |
1464 | + th.setData({cartlist:arr }) | |
1465 | + } | |
1466 | + } | |
1467 | + }) | |
1468 | + }) | |
1469 | + } | |
1470 | + } | |
1471 | + }, | |
1472 | + //------ 获取立即购买的购物车的劵 -------- | |
1473 | + get_buy_now_quan:function () { | |
1474 | + var quanlist=null,th=this,frozenQuan = null; | |
1475 | + if(th.data.is_close_quan != 1) | |
1476 | + { | |
1477 | + var url0 = "/api/weshop/users/frozenQuan/listFrozenQuan/" + app.globalData.user_id; | |
1478 | + var url="/api/weshop/couponList/getUseCouponList"; | |
1479 | + app.request.promiseGet(url0, {1: 1}).then(res => { | |
1480 | + if (res.data.code == 0) { | |
1481 | + frozenQuan = res.data.data; | |
1482 | + } | |
1483 | + app.request.time_limit_get(6, url, { | |
1484 | + data: { | |
1485 | + storeId: oo.stoid, | |
1486 | + userId: app.globalData.user_id, | |
1487 | + BuySum: th.data.ckeck_quan_price, | |
1488 | + WareIds: th.data.check_quan_ware_list, | |
1489 | + pageSize: 100 | |
1490 | + }, | |
1491 | + success: function (res) { | |
1492 | + if (res.data.code == 0) { | |
1493 | + quanlist = res.data.data.pageData; | |
1494 | + if (quanlist) { | |
1495 | + quanlist = th.check_is_frozenQuan(quanlist, frozenQuan); | |
1496 | + th.setData({selected_quan_list:quanlist }) | |
1497 | + } | |
1498 | + } | |
1499 | + } | |
1500 | + | |
1501 | + }) | |
1502 | + }) | |
1503 | + | |
1504 | + } | |
1505 | + } | |
1525 | 1506 | }); | ... | ... |
utils/request.js
... | ... | @@ -8,7 +8,8 @@ module.exports = { |
8 | 8 | //"content-type": "application/texts" |
9 | 9 | }, s = "GET" != (e = e.toUpperCase()) && o.data ? t.json2Form(o.data) : o.data; |
10 | 10 | i = this.modifyUrl(i, o), o.isShowLoading = void 0 === o.isShowLoading || o.isShowLoading, |
11 | - o.isShowLoading && this.showLoading(), console.log("app.request", i, o), wx.request(Object.assign({}, o, { | |
11 | + o.isShowLoading && this.showLoading(); | |
12 | + var req=wx.request(Object.assign({}, o, { | |
12 | 13 | url: i, |
13 | 14 | method: e, |
14 | 15 | data: s, |
... | ... | @@ -20,9 +21,10 @@ module.exports = { |
20 | 21 | o.isShowLoading && n.hideLoading(), n.doFail(o, t); |
21 | 22 | } |
22 | 23 | })); |
24 | + return req; | |
23 | 25 | }, |
24 | 26 | get: function (t, e) { |
25 | - this.request("GET", t, e); | |
27 | + return this.request("GET", t, e); | |
26 | 28 | }, |
27 | 29 | post: function (t, e) { |
28 | 30 | this.request("POST", t, e); |
... | ... | @@ -202,6 +204,13 @@ module.exports = { |
202 | 204 | fail(err) { data.isShowLoading && th.hideLoading(); reject(err); } |
203 | 205 | }) |
204 | 206 | }) |
207 | + }, | |
208 | + //--------具有时间限制的读取接口---------- | |
209 | + time_limit_get(time,url,data){ | |
210 | + var req=this.get(url,data); | |
211 | + setTimeout(function () { | |
212 | + req.abort(); | |
213 | + },time*1000) | |
205 | 214 | } |
206 | 215 | |
207 | 216 | }; |
208 | 217 | \ No newline at end of file | ... | ... |