Commit fea35349c806d945e0a0f7a70fffcd0827f5b207
Merge branch 'dev' into 'test'
购物车 再调用券的时候,不等券的调用,让商品能够显示 See merge request !218
Showing
2 changed files
with
118 additions
and
128 deletions
pages/cart/cart2/cart2.js
| @@ -113,11 +113,7 @@ Page({ | @@ -113,11 +113,7 @@ Page({ | ||
| 113 | onShow: function() { | 113 | onShow: function() { |
| 114 | var th=this; | 114 | var th=this; |
| 115 | if (th.data.isclose==0){ | 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 | wx.switchTab({ | 117 | wx.switchTab({ |
| 122 | url: "/pages/index/index/index" | 118 | url: "/pages/index/index/index" |
| 123 | }) | 119 | }) |
| @@ -131,7 +127,7 @@ Page({ | @@ -131,7 +127,7 @@ Page({ | ||
| 131 | th.setData({user_addr: ie }); | 127 | th.setData({user_addr: ie }); |
| 132 | var going=0; | 128 | var going=0; |
| 133 | 129 | ||
| 134 | - //使用计算器,避免空现象 | 130 | + //使用计时器,避免空现象 |
| 135 | var jishi= setInterval(function () { | 131 | var jishi= setInterval(function () { |
| 136 | if (th.data.is_b_now == 1 && going==0) { | 132 | if (th.data.is_b_now == 1 && going==0) { |
| 137 | if(th.data.bn_goods) { | 133 | if(th.data.bn_goods) { |
| @@ -243,7 +239,7 @@ Page({ | @@ -243,7 +239,7 @@ Page({ | ||
| 243 | data: { | 239 | data: { |
| 244 | user_id: to.globalData.user_id, selected:1, | 240 | user_id: to.globalData.user_id, selected:1, |
| 245 | store_id: oo.stoid, pageSize: 600 }, | 241 | store_id: oo.stoid, pageSize: 600 }, |
| 246 | - success: async function (su) { | 242 | + success:function (su) { |
| 247 | //按门店分类的数组 | 243 | //按门店分类的数组 |
| 248 | var arr = new Array(); | 244 | var arr = new Array(); |
| 249 | var carr = su.data.data.pageData; | 245 | var carr = su.data.data.pageData; |
| @@ -305,74 +301,13 @@ Page({ | @@ -305,74 +301,13 @@ Page({ | ||
| 305 | arr.push(ie); | 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 | th.setData({ | 304 | th.setData({ |
| 372 | cartlist: arr, | 305 | cartlist: arr, |
| 373 | }), | 306 | }), |
| 374 | 307 | ||
| 375 | th.calculatePrice(); | 308 | th.calculatePrice(); |
| 309 | + //--- 获取一下看有没有优惠券 ---- | ||
| 310 | + th.get_cart_quan(); | ||
| 376 | } | 311 | } |
| 377 | }); | 312 | }); |
| 378 | }, | 313 | }, |
| @@ -381,7 +316,6 @@ Page({ | @@ -381,7 +316,6 @@ Page({ | ||
| 381 | get_buy_goods: function (e){ | 316 | get_buy_goods: function (e){ |
| 382 | var th=this; | 317 | var th=this; |
| 383 | var gg = to.get_b_now(); | 318 | var gg = to.get_b_now(); |
| 384 | - | ||
| 385 | //--------如果goods_id一样,就是要立即购买----- | 319 | //--------如果goods_id一样,就是要立即购买----- |
| 386 | if(e==gg.goods_id){ | 320 | if(e==gg.goods_id){ |
| 387 | a.get("/api/weshop/goods/get/" + oo.stoid+"/"+e, { | 321 | a.get("/api/weshop/goods/get/" + oo.stoid+"/"+e, { |
| @@ -408,7 +342,6 @@ Page({ | @@ -408,7 +342,6 @@ Page({ | ||
| 408 | } | 342 | } |
| 409 | } | 343 | } |
| 410 | 344 | ||
| 411 | - | ||
| 412 | switch (gd.prom_type){ | 345 | switch (gd.prom_type){ |
| 413 | case 0: | 346 | case 0: |
| 414 | case 2: | 347 | case 2: |
| @@ -419,46 +352,21 @@ Page({ | @@ -419,46 +352,21 @@ Page({ | ||
| 419 | //--此时开始计算商品的使用券相关,如果有等级价还要计算和等级价相关的, | 352 | //--此时开始计算商品的使用券相关,如果有等级价还要计算和等级价相关的, |
| 420 | // 如果有优惠促销,还要把促销的部分计算在内,因为促销还有不能使用优惠券-- | 353 | // 如果有优惠促销,还要把促销的部分计算在内,因为促销还有不能使用优惠券-- |
| 421 | t.data.data.shop_price=gg.goods_price; | 354 | t.data.data.shop_price=gg.goods_price; |
| 422 | - | ||
| 423 | th.data.ckeck_quan_price=t.data.data.shop_price*gg.goods_num; | 355 | th.data.ckeck_quan_price=t.data.data.shop_price*gg.goods_num; |
| 424 | th.data.check_quan_price_list=t.data.data.shop_price*gg.goods_num+""; | 356 | th.data.check_quan_price_list=t.data.data.shop_price*gg.goods_num+""; |
| 425 | th.data.check_quan_ware_list=t.data.data.erpwareid+""; | 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 | t.data.data.prom_id = 0; | 359 | t.data.data.prom_id = 0; |
| 454 | t.data.data.prom_type = 0; | 360 | t.data.data.prom_type = 0; |
| 455 | 361 | ||
| 456 | th.setData({ | 362 | th.setData({ |
| 457 | bn_goods: t.data.data, bn_pickname: gg.pick_name, bn_exp_type: et,index:m_wind, | 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 | th.calculatePrice2(); | 367 | th.calculatePrice2(); |
| 368 | + //获取优惠券 | ||
| 369 | + th.get_buy_now_quan(); | ||
| 462 | 370 | ||
| 463 | break; | 371 | break; |
| 464 | case 1: //---秒杀----- | 372 | case 1: //---秒杀----- |
| @@ -474,37 +382,16 @@ Page({ | @@ -474,37 +382,16 @@ Page({ | ||
| 474 | th.data.ckeck_quan_price=t.data.data.shop_price*gg.goods_num; | 382 | th.data.ckeck_quan_price=t.data.data.shop_price*gg.goods_num; |
| 475 | th.data.check_quan_price_list=t.data.data.shop_price*gg.goods_num+""; | 383 | th.data.check_quan_price_list=t.data.data.shop_price*gg.goods_num+""; |
| 476 | th.data.check_quan_ware_list=t.data.data.erpwareid+""; | 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 | th.setData({ | 387 | th.setData({ |
| 503 | bn_goods: t.data.data, bn_pickname: gg.pick_name, bn_exp_type: et,index:m_wind, | 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 | th.calculatePrice2(); | 392 | th.calculatePrice2(); |
| 393 | + //获取优惠券 | ||
| 394 | + th.get_buy_now_quan(); | ||
| 508 | } | 395 | } |
| 509 | }); | 396 | }); |
| 510 | 397 | ||
| @@ -1397,7 +1284,9 @@ Page({ | @@ -1397,7 +1284,9 @@ Page({ | ||
| 1397 | 1284 | ||
| 1398 | //--验证是否已经冻结-- | 1285 | //--验证是否已经冻结-- |
| 1399 | check_is_frozenQuan:function(quanlist,frozenQuan){ | 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 | var arr=[]; | 1290 | var arr=[]; |
| 1402 | for(var i=0;i<quanlist.length;i++){ | 1291 | for(var i=0;i<quanlist.length;i++){ |
| 1403 | var item=quanlist[i]; | 1292 | var item=quanlist[i]; |
| @@ -1519,7 +1408,99 @@ Page({ | @@ -1519,7 +1408,99 @@ Page({ | ||
| 1519 | } | 1408 | } |
| 1520 | } | 1409 | } |
| 1521 | },500); | 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,7 +8,8 @@ module.exports = { | ||
| 8 | //"content-type": "application/texts" | 8 | //"content-type": "application/texts" |
| 9 | }, s = "GET" != (e = e.toUpperCase()) && o.data ? t.json2Form(o.data) : o.data; | 9 | }, s = "GET" != (e = e.toUpperCase()) && o.data ? t.json2Form(o.data) : o.data; |
| 10 | i = this.modifyUrl(i, o), o.isShowLoading = void 0 === o.isShowLoading || o.isShowLoading, | 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 | url: i, | 13 | url: i, |
| 13 | method: e, | 14 | method: e, |
| 14 | data: s, | 15 | data: s, |
| @@ -20,9 +21,10 @@ module.exports = { | @@ -20,9 +21,10 @@ module.exports = { | ||
| 20 | o.isShowLoading && n.hideLoading(), n.doFail(o, t); | 21 | o.isShowLoading && n.hideLoading(), n.doFail(o, t); |
| 21 | } | 22 | } |
| 22 | })); | 23 | })); |
| 24 | + return req; | ||
| 23 | }, | 25 | }, |
| 24 | get: function (t, e) { | 26 | get: function (t, e) { |
| 25 | - this.request("GET", t, e); | 27 | + return this.request("GET", t, e); |
| 26 | }, | 28 | }, |
| 27 | post: function (t, e) { | 29 | post: function (t, e) { |
| 28 | this.request("POST", t, e); | 30 | this.request("POST", t, e); |
| @@ -202,6 +204,13 @@ module.exports = { | @@ -202,6 +204,13 @@ module.exports = { | ||
| 202 | fail(err) { data.isShowLoading && th.hideLoading(); reject(err); } | 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 | \ No newline at end of file | 217 | \ No newline at end of file |