Commit 87358ad0950ef022dec32f76c9a8b17a30925982

Authored by yvan.ni
1 parent a9e09ab7

搭配购商品 的优化

components/cart_collect_temp/cart_collect_temp.js
  1 +var regeneratorRuntime = require('../../utils/runtime.js');
  2 +var os = getApp().globalData.setting
1 Component({ 3 Component({
2 properties: { 4 properties: {
3 // 这里定义了数据列表属性,列表显示数据 5 // 这里定义了数据列表属性,列表显示数据
@@ -14,6 +16,15 @@ Component({ @@ -14,6 +16,15 @@ Component({
14 cart_index: { 16 cart_index: {
15 type: Number, 17 type: Number,
16 value: 0 18 value: 0
  19 + },
  20 +
  21 + sales_rules: {
  22 + type: Number,
  23 + value: 1
  24 + },
  25 + pick:{
  26 + type: Number,
  27 + value: 1
17 } 28 }
18 29
19 }, 30 },
@@ -22,7 +33,8 @@ Component({ @@ -22,7 +33,8 @@ Component({
22 imgUrl: getApp().globalData.setting.imghost, 33 imgUrl: getApp().globalData.setting.imghost,
23 }, 34 },
24 methods: { 35 methods: {
25 - select_coll(e) { 36 + async select_coll(e) {
  37 + var th=this;
26 var index = e.currentTarget.dataset.index; 38 var index = e.currentTarget.dataset.index;
27 var itr = this.properties.all_collocation_list[index]; 39 var itr = this.properties.all_collocation_list[index];
28 var ob = { 40 var ob = {
@@ -35,6 +47,23 @@ Component({ @@ -35,6 +47,23 @@ Component({
35 ob.cart_index =this.properties.cart_index; 47 ob.cart_index =this.properties.cart_index;
36 } 48 }
37 49
  50 +
  51 + if(th.data.sales_rules>1){
  52 + var isok = 1;
  53 + await th.check_store_num(itr.goods_id, th.data.pick, 1, function (res){
  54 + isok = res;
  55 + })
  56 + if(!isok){
  57 + wx.showToast({
  58 + title: itr.goods_name+"商品库存不足",
  59 + icon: 'none',
  60 + duration: 2000
  61 + })
  62 + return false;
  63 + }
  64 + }
  65 +
  66 +
38 var txt = "all_collocation_list[" + index + "].selected" 67 var txt = "all_collocation_list[" + index + "].selected"
39 68
40 this.setData({[txt]: ob.selected}) 69 this.setData({[txt]: ob.selected})
@@ -53,5 +82,66 @@ Component({ @@ -53,5 +82,66 @@ Component({
53 }, 82 },
54 83
55 84
  85 + //---确认线下门店的数量足不足---
  86 + async check_store_num(goods_id, pick, goods_num, func) {
  87 + var lock = 0, pick_no, plist, erpwareid;
  88 +
  89 + var lock_rq={ store_id: os.stoid, wareId: goods_id, storageId: pick, pageSize: 1000 };
  90 + if(this.data.sales_rules==3){
  91 + lock_rq.appoint_pick_keyid=this.data.appoint_pick_keyid;
  92 + delete lock_rq.storageId
  93 + }
  94 + //先读取门店的lock
  95 + await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", {
  96 + data: lock_rq
  97 + }).then(res => {
  98 + if (res.data.code == 0 && res.data.data.total > 0) {
  99 + for (var i in res.data.data.pageData)
  100 + lock += res.data.data.pageData[i].outQty;
  101 + }
  102 + })
  103 +
  104 + if(this.data.sales_rules==2) {
  105 + //先获取门店的编号
  106 + await getApp().request.promiseGet("/api/weshop/pickup/get/" + os.stoid + "/" + pick, {
  107 + }).then(res => {
  108 + if (res.data.code == 0) {
  109 + pick_no = res.data.data.pickup_no;
  110 + }
  111 + })
  112 + }
  113 +
  114 + //先获取商品的线下库存
  115 + await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + goods_id, {
  116 + }).then(res => {
  117 + if (res.data.code == 0) {
  118 + erpwareid = res.data.data.erpwareid;
  119 + }
  120 + })
  121 +
  122 +
  123 + var sto_rq={ storageNos: pick_no, wareIds: encodeURIComponent(erpwareid), storeId: os.stoid, pageSize: 2000 };
  124 + if(this.data.sales_rules==3){
  125 + sto_rq.storageIds=this.data.appoint_pick_keyid;
  126 + delete sto_rq.storageNos
  127 + }
  128 +
  129 + //读取线下的门店库存
  130 + await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", {
  131 + data: sto_rq
  132 + }).then(res => {
  133 + if (res.data.code == 0 && res.data.data.total > 0) {
  134 + plist = res.data.data.pageData[0];
  135 + }
  136 + })
  137 +
  138 + var isok = 1;
  139 + if (!plist || goods_num > plist.CanOutQty - lock) {
  140 + isok = 0;
  141 + }
  142 + func(isok);
  143 + },
  144 +
  145 +
56 } 146 }
57 }) 147 })
58 \ No newline at end of file 148 \ No newline at end of file
packageA/pages/prom_list/prom_list.js
@@ -273,17 +273,26 @@ Page({ @@ -273,17 +273,26 @@ Page({
273 //调用接口判断订单优惠, 273 //调用接口判断订单优惠,
274 getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + ee.data.gid + "/2"+"/"+user_id, {}).then(res => { 274 getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + ee.data.gid + "/2"+"/"+user_id, {}).then(res => {
275 if (res.data.code == 0) { 275 if (res.data.code == 0) {
276 - var r_data = res.data.data;  
277 -  
278 -  
279 - th.data.is_coupon = r_data.collocationPromList.is_coupon;  
280 -  
281 - 276 +
  277 + var r_data = res.data.data;
  278 +
  279 + th.data.is_coupon = r_data.collocationPromList.is_coupon;
  280 +
282 th.loop_promise(0, r_data.collocationList, function () { 281 th.loop_promise(0, r_data.collocationList, function () {
283 - // 设置搭配购是否使用优惠卷 282 +
  283 + var set_data=JSON.parse(JSON.stringify(r_data.collocationList));
  284 +
  285 + //如果是线上的时候,过滤掉线上库存未0的商品
  286 + if(th.data.sales_rules==1){
  287 + set_data=set_data.filter(function (e){
  288 + return e.store_count>0;
  289 + })
  290 + }
  291 +
  292 + //设置搭配购是否使用优惠卷
284 ee.setData({ 293 ee.setData({
285 collocationGoods: r_data.collocationPromList, 294 collocationGoods: r_data.collocationPromList,
286 - collocationList: r_data.collocationList, 295 + collocationList: set_data,
287 }) 296 })
288 }) 297 })
289 } 298 }
@@ -297,7 +306,7 @@ Page({ @@ -297,7 +306,7 @@ Page({
297 //--等待某个值只运行---,这里有可能因为导航的时间太久,而不能计算门店库存 306 //--等待某个值只运行---,这里有可能因为导航的时间太久,而不能计算门店库存
298 getApp().waitfor2(that, "wait_for_user_store", "fir_def_store", function () { 307 getApp().waitfor2(that, "wait_for_user_store", "fir_def_store", function () {
299 308
300 - debugger 309 +
301 310
302 if (th.data.fir_def_store && th.data.fir_def_store.pickup_id) { 311 if (th.data.fir_def_store && th.data.fir_def_store.pickup_id) {
303 var lock = 0,plist = null; 312 var lock = 0,plist = null;
@@ -386,6 +395,8 @@ Page({ @@ -386,6 +395,8 @@ Page({
386 //------------加入购物车-------------- 395 //------------加入购物车--------------
387 addCart: function(t) { 396 addCart: function(t) {
388 var th = this; 397 var th = this;
  398 + if(this.data.lding) return false;
  399 + th.setData({lding:1})
389 th.add_cart_func(t); 400 th.add_cart_func(t);
390 401
391 }, 402 },
@@ -393,6 +404,7 @@ Page({ @@ -393,6 +404,7 @@ Page({
393 add_cart_func: function(t) { 404 add_cart_func: function(t) {
394 var i = getApp().request; 405 var i = getApp().request;
395 if (oo.user_id == null) { 406 if (oo.user_id == null) {
  407 + th.setData({lding:0})
396 return s.my_warnning("还未登录!", 0, this); 408 return s.my_warnning("还未登录!", 0, this);
397 } 409 }
398 var e = this, 410 var e = this,
@@ -401,7 +413,7 @@ Page({ @@ -401,7 +413,7 @@ Page({
401 o = this.data.data; 413 o = this.data.data;
402 a = o.goods_id; 414 a = o.goods_id;
403 //----------添加到购物车时,要判断限购数量,-------- 415 //----------添加到购物车时,要判断限购数量,--------
404 - e.get_buy_num(o, function(ee) { 416 + e.get_buy_num(o, async function(ee) {
405 //---判断商品是否超出限购--- 417 //---判断商品是否超出限购---
406 if (th.data.g_buy_num != null && th.data.data.viplimited > 0) { 418 if (th.data.g_buy_num != null && th.data.data.viplimited > 0) {
407 if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.data.goods_id) > th.data.data.viplimited) { 419 if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.data.goods_id) > th.data.data.viplimited) {
@@ -409,6 +421,7 @@ Page({ @@ -409,6 +421,7 @@ Page({
409 title: '提示', 421 title: '提示',
410 content: '超出商品限购' 422 content: '超出商品限购'
411 }); 423 });
  424 + th.setData({lding:0})
412 return false; 425 return false;
413 } 426 }
414 } 427 }
@@ -419,16 +432,23 @@ Page({ @@ -419,16 +432,23 @@ Page({
419 title: '提示', 432 title: '提示',
420 content: '超出商品活动限购' 433 content: '超出商品活动限购'
421 }); 434 });
  435 + th.setData({lding:0})
422 return false; 436 return false;
423 } 437 }
424 } 438 }
425 439
426 - if (th.data.goodsInputNum <= 0) return s.my_warnning("商品数量不能为0", 0, th); 440 + if (th.data.goodsInputNum <= 0){
  441 + th.setData({lding:0})
  442 + return s.my_warnning("商品数量不能为0", 0, th);
  443 + }
427 if (th.data.sto_sele_name == null || th.data.sto_sele_name == undefined) 444 if (th.data.sto_sele_name == null || th.data.sto_sele_name == undefined)
428 this.setData({ 445 this.setData({
429 sto_sele_name: "" 446 sto_sele_name: ""
430 }); 447 });
431 - if (th.data.sto_sele_name == "") return s.my_warnning("请选择门店", 0, th); 448 + if (th.data.sto_sele_name == ""){
  449 + th.setData({lding:0})
  450 + return s.my_warnning("请选择门店", 0, th);
  451 + }
432 452
433 //--------------此时操作的数据------------ 453 //--------------此时操作的数据------------
434 var newd = { 454 var newd = {
@@ -478,12 +498,13 @@ Page({ @@ -478,12 +498,13 @@ Page({
478 498
479 //-----如果是秒杀,团购,积分购,拼团----- 499 //-----如果是秒杀,团购,积分购,拼团-----
480 if (th.data.data.prom_type != 5) { 500 if (th.data.data.prom_type != 5) {
  501 + th.setData({lding:0})
481 return s.my_warnning("商品不是搭配活动!", 0, th); 502 return s.my_warnning("商品不是搭配活动!", 0, th);
482 }else{ 503 }else{
483 //---如果是线下门店销售的时候--- 504 //---如果是线下门店销售的时候---
484 if(th.data.sales_rules>=2){ 505 if(th.data.sales_rules>=2){
485 - var pick=th.get_pick_from_list(th.data.sto_sele_id)  
486 506
  507 + var pick=th.get_pick_from_list(th.data.sto_sele_id)
487 508
488 var dw_rq={storageNos:pick.pickup_no,wareIds:encodeURIComponent(th.data.data.erpwareid),storeId:os.stoid,pageSize:2000}; 509 var dw_rq={storageNos:pick.pickup_no,wareIds:encodeURIComponent(th.data.data.erpwareid),storeId:os.stoid,pageSize:2000};
489 if(th.data.sales_rules == 3){ 510 if(th.data.sales_rules == 3){
@@ -499,6 +520,7 @@ Page({ @@ -499,6 +520,7 @@ Page({
499 if(res.data.data.pageData.length>0){ 520 if(res.data.data.pageData.length>0){
500 var CanOutQty=res.data.data.pageData[0].CanOutQty; 521 var CanOutQty=res.data.data.pageData[0].CanOutQty;
501 if(CanOutQty<e.data.goodsInputNum){ 522 if(CanOutQty<e.data.goodsInputNum){
  523 + th.setData({lding:0})
502 return s.my_warnning("库存不足!", 0, th); 524 return s.my_warnning("库存不足!", 0, th);
503 } 525 }
504 526
@@ -520,6 +542,7 @@ Page({ @@ -520,6 +542,7 @@ Page({
520 } 542 }
521 543
522 if(CanOutQty<=lock){ 544 if(CanOutQty<=lock){
  545 + th.setData({lding:0})
523 return s.my_warnning("库存不足!", 0, th); 546 return s.my_warnning("库存不足!", 0, th);
524 } 547 }
525 th.add_cart_next(e,t,a,o,newd,CanOutQty-lock); 548 th.add_cart_next(e,t,a,o,newd,CanOutQty-lock);
@@ -529,6 +552,7 @@ Page({ @@ -529,6 +552,7 @@ Page({
529 } 552 }
530 }) 553 })
531 }else{ 554 }else{
  555 + th.setData({lding:0})
532 return s.my_warnning("库存不足!", 0, th); 556 return s.my_warnning("库存不足!", 0, th);
533 } 557 }
534 558
@@ -536,8 +560,14 @@ Page({ @@ -536,8 +560,14 @@ Page({
536 } 560 }
537 }) 561 })
538 }else{ 562 }else{
539 - if (o.store_count <= 0) return s.my_warnning("库存已为空!", 0, th);  
540 - if (o.store_count <e.data.goodsInputNum) return s.my_warnning("库存不足!", 0, th); 563 + if (o.store_count <= 0) {
  564 + th.setData({lding:0})
  565 + return s.my_warnning("库存已为空!", 0, th);
  566 + }
  567 + if (o.store_count <e.data.goodsInputNum) {
  568 + th.setData({lding:0})
  569 + return s.my_warnning("库存不足!", 0, th);
  570 + }
541 th.add_cart_next(e,t,a,o,newd); //加入购物车下一步 571 th.add_cart_next(e,t,a,o,newd); //加入购物车下一步
542 } 572 }
543 } 573 }
@@ -545,39 +575,63 @@ Page({ @@ -545,39 +575,63 @@ Page({
545 }, 575 },
546 576
547 //---加入购物车的最后一步--- 577 //---加入购物车的最后一步---
548 - add_cart_next(e,t,a,o,newd,CanOutQty){  
549 - var th=this;  
550 - //---如果商品不是积分购和拼团,要判断一个是否要进行等级价的判断------  
551 - if(o.prom_type!=1 && o.prom_type!=6){  
552 - var conf=th.data.bconfig;  
553 - if (conf.switch_list && getApp().globalData.userInfo['card_field']){  
554 - var s_list=JSON.parse(conf.switch_list);  
555 - var now=ut.gettimestamp();  
556 - var str = getApp().globalData.userInfo['card_expiredate'].replace(/-/g, '/');  
557 - var end = new Date(str);  
558 - end = Date.parse(end) / 1000;  
559 -  
560 - //--如果后台有开启等级价的功能,而且会员的等级没有过期的情况下--  
561 - if(parseInt(s_list.rank_switch)==2 && end>now){  
562 - var card_price=o[getApp().globalData.userInfo['card_field']];  
563 - //如果会员有等级价  
564 - if(getApp().globalData.userInfo['card_field']!=undefined && getApp().globalData.userInfo['card_field']!=null  
565 - && getApp().globalData.userInfo['card_field']!="" && card_price>0){  
566 - newd.goods_price=card_price;  
567 - }  
568 - }  
569 - }  
570 - } 578 + add_cart_next(e, t, a, o, newd, CanOutQty) {
  579 + var th = this;
  580 + //---如果商品不是积分购和拼团,要判断一个是否要进行等级价的判断------
  581 + if (o.prom_type != 1 && o.prom_type != 6) {
  582 + var conf = th.data.bconfig;
  583 + if (conf.switch_list && getApp().globalData.userInfo['card_field']) {
  584 + var s_list = JSON.parse(conf.switch_list);
  585 + var now = ut.gettimestamp();
  586 + var str = getApp().globalData.userInfo['card_expiredate'].replace(/-/g, '/');
  587 + var end = new Date(str);
  588 + end = Date.parse(end) / 1000;
  589 +
  590 + //--如果后台有开启等级价的功能,而且会员的等级没有过期的情况下--
  591 + if (parseInt(s_list.rank_switch) == 2 && end > now) {
  592 + var card_price = o[getApp().globalData.userInfo['card_field']];
  593 + //如果会员有等级价
  594 + if (getApp().globalData.userInfo['card_field'] != undefined && getApp().globalData.userInfo['card_field'] != null
  595 + && getApp().globalData.userInfo['card_field'] != "" && card_price > 0) {
  596 + newd.goods_price = card_price;
  597 + }
  598 + }
  599 + }
  600 + }
571 601
572 - newd['pick_name'] = th.data.sto_sele_name;  
573 - newd['pick_dis'] = th.data.sto_sele_distr;  
574 - newd["collocation_goods"]=th.data.sele_collocation; 602 + newd['pick_name'] = th.data.sto_sele_name;
  603 + newd['pick_dis'] = th.data.sto_sele_distr;
575 604
576 - newd["is_coupon"] = th.data.is_coupon; 605 + this.check_sele_collocation(function (collocationGoods) {
  606 + var is_ok = 1;
  607 + if (th.data.sales_rules > 1) {
577 608
578 - th.buyNow(newd); 609 + for (let j = 0; j < collocationGoods.length; j++) {
  610 + var item = collocationGoods[j];
  611 + if (item.CanOutQty<=0) {
  612 + is_ok=0;
  613 + wx.showToast({
  614 + title: item.goods_name+ "库存不足",
  615 + icon: 'none',
  616 + duration: 2000
  617 + })
579 618
580 - }, 619 + break;
  620 + }
  621 + }
  622 + }
  623 +
  624 + if(!is_ok){
  625 + th.setData({lding:0})
  626 + return false;
  627 + }
  628 +
  629 + newd["collocation_goods"] = collocationGoods;
  630 + newd["is_coupon"] = th.data.is_coupon;
  631 + th.buyNow(newd);
  632 + })
  633 +
  634 + },
581 635
582 //----------立即购买----------- 636 //----------立即购买-----------
583 buyNow: function(e) { 637 buyNow: function(e) {
@@ -849,7 +903,6 @@ Page({ @@ -849,7 +903,6 @@ Page({
849 e.his_cate_num=his_cate_num; 903 e.his_cate_num=his_cate_num;
850 904
851 905
852 - debugger  
853 906
854 //如果有开启距离的功能,没有设置默认门店,要用最近的门店作为默认门店 907 //如果有开启距离的功能,没有设置默认门店,要用最近的门店作为默认门店
855 if(dd.lat && !th.data.def_pick_store && th.data.bconfig && th.data.bconfig.is_sort_storage){ 908 if(dd.lat && !th.data.def_pick_store && th.data.bconfig && th.data.bconfig.is_sort_storage){
@@ -1509,44 +1562,59 @@ Page({ @@ -1509,44 +1562,59 @@ Page({
1509 }else{ 1562 }else{
1510 1563
1511 1564
1512 - var lock_rq={store_id:os.stoid,wareId:goodsinfo.goods_id,storageId:item.pickup_id,pageSize:1000};  
1513 - //-- 指定门店销售的时候 --  
1514 - if(th.data.sales_rules == 3){  
1515 - lock_rq.appoint_pick_keyid = encodeURIComponent(th.data.appoint_pick_keyid);  
1516 - delete lock_rq.storageId  
1517 - }  
1518 -  
1519 - //先读取门店的lock  
1520 - await getApp().request.promiseGet("/api/weshop/order/ware/lock/page",{  
1521 - data:lock_rq  
1522 - }).then(res=>{  
1523 - if(res.data.code==0 && res.data.data.total>0){  
1524 - for(var i in res.data.data.pageData )  
1525 - lock+=res.data.data.pageData[i].outQty;  
1526 - }  
1527 - }) 1565 + // var lock_rq={store_id:os.stoid,wareId:goodsinfo.goods_id,storageId:item.pickup_id,pageSize:1000};
  1566 + // //-- 指定门店销售的时候 --
  1567 + // if(th.data.sales_rules == 3){
  1568 + // lock_rq.appoint_pick_keyid = encodeURIComponent(th.data.appoint_pick_keyid);
  1569 + // delete lock_rq.storageId
  1570 + // }
  1571 + //
  1572 + // //先读取门店的lock
  1573 + // await getApp().request.promiseGet("/api/weshop/order/ware/lock/page",{
  1574 + // data:lock_rq
  1575 + // }).then(res=>{
  1576 + // if(res.data.code==0 && res.data.data.total>0){
  1577 + // for(var i in res.data.data.pageData )
  1578 + // lock+=res.data.data.pageData[i].outQty;
  1579 + // }
  1580 + // })
  1581 + //
  1582 + // var dw_rq={storageNos:item.pickup_no,wareIds:encodeURIComponent(erpwareid),storeId:os.stoid,pageSize:2000};
  1583 + // if(th.data.sales_rules == 3){
  1584 + // dw_rq.storageIds = encodeURIComponent(th.data.appoint_pick_keyid)
  1585 + // delete dw_rq.storageNos
  1586 + // }
  1587 + //
  1588 + // //读取线下的门店库存
  1589 + // await getApp().request.promiseGet("/api/weshop/goods/getWareStorages",{
  1590 + // data:dw_rq
  1591 + // }).then(res=>{
  1592 + // if(res.data.code==0 && res.data.data.total>0){
  1593 + // plist=res.data.data.pageData[0];
  1594 + // }
  1595 + // })
  1596 + //
  1597 + // if(plist && plist.CanOutQty-lock>0){
  1598 + // item.CanOutQty=plist.CanOutQty-lock;
  1599 + // func();
  1600 + // return false;
  1601 + // }
  1602 + // getApp().my_warnning(item.pickup_name+"库存不足!", 0, th);
  1603 +
  1604 + this.check_CanOutQty(goodsinfo, item, function (CanOutQty) {
  1605 + // let str = item.pickup_name + '库存不足!';
  1606 + if (!CanOutQty) {
  1607 + wx.showToast({
  1608 + title: item.pickup_name + '库存不足!',
  1609 + icon: 'none',
  1610 + });
  1611 + return false;
  1612 + }
  1613 + item.CanOutQty = CanOutQty;
  1614 + func();
1528 1615
1529 - var dw_rq={storageNos:item.pickup_no,wareIds:encodeURIComponent(erpwareid),storeId:os.stoid,pageSize:2000};  
1530 - if(th.data.sales_rules == 3){  
1531 - dw_rq.storageIds = encodeURIComponent(th.data.appoint_pick_keyid)  
1532 - delete dw_rq.storageNos  
1533 - } 1616 + });
1534 1617
1535 - //读取线下的门店库存  
1536 - await getApp().request.promiseGet("/api/weshop/goods/getWareStorages",{  
1537 - data:dw_rq  
1538 - }).then(res=>{  
1539 - if(res.data.code==0 && res.data.data.total>0){  
1540 - plist=res.data.data.pageData[0];  
1541 - }  
1542 - })  
1543 -  
1544 - if(plist && plist.CanOutQty-lock>0){  
1545 - item.CanOutQty=plist.CanOutQty-lock;  
1546 - func();  
1547 - return false;  
1548 - }  
1549 - getApp().my_warnning(item.pickup_name+"库存不足!", 0, th);  
1550 1618
1551 } 1619 }
1552 }, 1620 },
@@ -1787,20 +1855,90 @@ Page({ @@ -1787,20 +1855,90 @@ Page({
1787 }, 1855 },
1788 1856
1789 //递归获取商品 1857 //递归获取商品
1790 - loop_promise:function(x,arr,func){ 1858 + loop_promise: function(x,arr,func){
1791 var th=this; 1859 var th=this;
1792 - getApp().request.promiseGet("/api/weshop/goods/get/" + o.stoid + "/" + arr[x].goods_id, {}).then(res => {  
1793 - arr[x].goods_spec=res.data.data.goods_spec;  
1794 - arr[x].goods_color=res.data.data.goods_color;  
1795 - arr[x].original_img=res.data.data.original_img;  
1796 - arr[x].shop_price=res.data.data.shop_price;  
1797 - if(x==arr.length-1){  
1798 - func(arr); //循环再最后  
1799 - }else{  
1800 - ++x;  
1801 - th.loop_promise(x,arr,func);  
1802 - } 1860 + var g_data=null;
  1861 + getApp().request.promiseGet("/api/weshop/goods/get/" + o.stoid + "/" + arr[x].goods_id, {}).then(res => {
  1862 + if(res.data.code==0 && res.data.data){
  1863 + g_data=res.data.data;
  1864 + if(g_data){
  1865 + arr[x].goods_spec=g_data.goods_spec;
  1866 + arr[x].goods_color=g_data.goods_color;
  1867 + arr[x].original_img=g_data.original_img;
  1868 + arr[x].shop_price=g_data.shop_price;
  1869 + arr[x].store_count=g_data.store_count;
  1870 + }
  1871 + }
  1872 +
  1873 + if(x==arr.length-1){
  1874 + func(arr); //循环再最后
  1875 + }else{
  1876 + ++x;
  1877 + th.loop_promise(x,arr,func);
  1878 + }
1803 }) 1879 })
  1880 +
  1881 + },
  1882 +
  1883 +
  1884 + //线下的时候判断库存
  1885 + async check_sele_collocation(func){
  1886 + var th=this;
  1887 + var pick =this.get_pick_from_list(th.data.sto_sele_id);
  1888 + var collocationGoods= this.data.sele_collocation;
  1889 + if(this.data.sales_rules>1){
  1890 + for (let j = 0; j < collocationGoods.length; j++) {
  1891 +
  1892 + var goodsinfo=collocationGoods[j];
  1893 + var sales_rules = this.data.sales_rules;
  1894 + var lock_rq = {
  1895 + store_id: os.stoid,
  1896 + wareId: goodsinfo.goods_id,
  1897 + pageSize: 1000
  1898 + };
  1899 +
  1900 + if (sales_rules == 2) {
  1901 + lock_rq.storageId =pick.pickup_id
  1902 + } else {
  1903 + lock_rq.appoint_pick_keyid = encodeURIComponent(this.data.appoint_pick_keyid)
  1904 + }
  1905 +
  1906 + var lock = 0;var CanOutQty = 0;var plist = null;
  1907 + //先读取门店的lock
  1908 + await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", {
  1909 + data: lock_rq
  1910 + }).then(res => {
  1911 + if (res.data.code == 0 && res.data.data.total > 0) {
  1912 + for (var i in res.data.data.pageData)
  1913 + lock += res.data.data.pageData[i].outQty;
  1914 + }
  1915 + })
  1916 +
  1917 + var sto_req = {
  1918 + wareIds: encodeURIComponent(goodsinfo.erpwareid),
  1919 + storeId: os.stoid
  1920 + }
  1921 + if (sales_rules == 2) {
  1922 + sto_req.storageNos = item.pickup_no
  1923 + } else {
  1924 + sto_req.storageIds = encodeURIComponent(this.data.appoint_pick_keyid)
  1925 + }
  1926 +
  1927 + //读取线下的门店库存
  1928 + await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", {
  1929 + data: sto_req
  1930 + }).then(res => {
  1931 + if (res.data.code == 0 && res.data.data.total > 0) {
  1932 + plist = res.data.data.pageData[0];
  1933 + }
  1934 + })
  1935 + if (plist && plist.CanOutQty - lock > 0) {
  1936 + CanOutQty = plist.CanOutQty - lock;
  1937 + }
  1938 + collocationGoods[j].CanOutQty=CanOutQty;
  1939 + }
  1940 + }
  1941 + func(collocationGoods);
1804 }, 1942 },
1805 1943
1806 //图片失败,默认图片 1944 //图片失败,默认图片
@@ -1884,7 +2022,64 @@ Page({ @@ -1884,7 +2022,64 @@ Page({
1884 choice_sort_store: 0 2022 choice_sort_store: 0
1885 }); 2023 });
1886 }, 2024 },
1887 - 2025 +
  2026 + //统一一下获取线下库存的函数
  2027 + async check_CanOutQty(goodsinfo, item, func,pickup_id) {
  2028 +
  2029 + var sales_rules = this.data.sales_rules;
  2030 +
  2031 + var lock_rq = {
  2032 + store_id: os.stoid,
  2033 + wareId: goodsinfo.goods_id,
  2034 + pageSize: 1000
  2035 + };
  2036 +
  2037 + if (sales_rules == 2) {
  2038 + lock_rq.storageId =item?item.pickup_id:pickup_id
  2039 + } else {
  2040 + lock_rq.appoint_pick_keyid = encodeURIComponent(this.data.appoint_pick_keyid)
  2041 + }
  2042 +
  2043 + var lock = 0;
  2044 + var CanOutQty = 0;
  2045 + var plist = null;
  2046 + //先读取门店的lock
  2047 + await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", {
  2048 + data: lock_rq
  2049 + }).then(res => {
  2050 + if (res.data.code == 0 && res.data.data.total > 0) {
  2051 + for (var i in res.data.data.pageData)
  2052 + lock += res.data.data.pageData[i].outQty;
  2053 + }
  2054 + })
  2055 +
  2056 + var sto_req = {
  2057 + wareIds: encodeURIComponent(goodsinfo.erpwareid),
  2058 + storeId: os.stoid
  2059 + }
  2060 + if (sales_rules == 2) {
  2061 + sto_req.storageNos = item.pickup_no
  2062 + } else {
  2063 + sto_req.storageIds = encodeURIComponent(this.data.appoint_pick_keyid)
  2064 + }
  2065 +
  2066 +
  2067 + //读取线下的门店库存
  2068 + await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", {
  2069 + data: sto_req
  2070 + }).then(res => {
  2071 + if (res.data.code == 0 && res.data.data.total > 0) {
  2072 + plist = res.data.data.pageData[0];
  2073 + }
  2074 + })
  2075 +
  2076 + if (plist && plist.CanOutQty - lock > 0) {
  2077 + CanOutQty = plist.CanOutQty - lock;
  2078 + }
  2079 +
  2080 + if (func) func(CanOutQty);
  2081 +
  2082 + },
1888 2083
1889 2084
1890 }); 2085 });
packageA/pages/prom_list/prom_list.wxml
@@ -143,17 +143,17 @@ @@ -143,17 +143,17 @@
143 <view class="spec-cart-btns"> 143 <view class="spec-cart-btns">
144 <!-- 根本就找不到门店 --> 144 <!-- 根本就找不到门店 -->
145 <block wx:if="{{!only_pk && !def_pickpu_list}}"> 145 <block wx:if="{{!only_pk && !def_pickpu_list}}">
146 - <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999;">库存不足1</view> 146 + <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999;">库存不足</view>
147 </block> 147 </block>
148 <block wx:else> 148 <block wx:else>
149 149
150 150
151 <block wx:if="{{only_pk.length && !only_pk.length}}"> 151 <block wx:if="{{only_pk.length && !only_pk.length}}">
152 - <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999;">库存不足2</view> 152 + <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999;">库存不足</view>
153 </block> 153 </block>
154 <block wx:else> 154 <block wx:else>
155 <block wx:if="{{def_pickpu_list && !def_pickpu_list.length}}"> 155 <block wx:if="{{def_pickpu_list && !def_pickpu_list.length}}">
156 - <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">库存不足3</view> 156 + <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">库存不足</view>
157 </block> 157 </block>
158 <block wx:else> 158 <block wx:else>
159 <block wx:if="{{!def_pick_store}}"> 159 <block wx:if="{{!def_pick_store}}">
@@ -164,26 +164,26 @@ @@ -164,26 +164,26 @@
164 <block wx:if="{{sales_rules>=2}}"> 164 <block wx:if="{{sales_rules>=2}}">
165 165
166 <block wx:if="{{!def_pick_store.CanOutQty}}"> 166 <block wx:if="{{!def_pick_store.CanOutQty}}">
167 - <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">库存不足4</view> 167 + <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">库存不足</view>
168 </block> 168 </block>
169 <block wx:else> 169 <block wx:else>
170 <view bindtap="addCart" data-openSpecModal_ind="2" 170 <view bindtap="addCart" data-openSpecModal_ind="2"
171 - class="spec-cart-btn spec-buy" data-action="buy">立即购买</view> 171 + class="spec-cart-btn spec-buy {{lding?'graying':''}} " data-action="buy">立即购买</view>
172 </block> 172 </block>
173 </block> 173 </block>
174 <!-- 线上销售 --> 174 <!-- 线上销售 -->
175 <block wx:else> 175 <block wx:else>
176 <block wx:if="{{data.store_count<=0}}"> 176 <block wx:if="{{data.store_count<=0}}">
177 - <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">库存不足5</view> 177 + <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">库存不足</view>
178 </block> 178 </block>
179 179
180 <block wx:elif="{{def_pick_store && def_pick_store.is_no_dis}}"> 180 <block wx:elif="{{def_pick_store && def_pick_store.is_no_dis}}">
181 - <view class="spec-cart-btn fs32" data-action="add" style="background-color: #dcdcdc;color: #999">立即购买</view> 181 + <view class="spec-cart-btn fs32 {{lding?'graying':''}} " data-action="add" style="background-color: #dcdcdc;color: #999">立即购买</view>
182 </block> 182 </block>
183 183
184 <block wx:else> 184 <block wx:else>
185 <view bindtap="addCart"data-openSpecModal_ind="2" 185 <view bindtap="addCart"data-openSpecModal_ind="2"
186 - class="spec-cart-btn spec-buy" data-action="buy">立即购买</view> 186 + class="spec-cart-btn spec-buy {{lding?'graying':''}} " data-action="buy">立即购买</view>
187 </block> 187 </block>
188 </block> 188 </block>
189 189
packageA/pages/prom_list/prom_list.wxss
@@ -360,4 +360,5 @@ @@ -360,4 +360,5 @@
360 width: 58%; background-color: #adadad; 360 width: 58%; background-color: #adadad;
361 } 361 }
362 .no_store{color:#d60021; font-size: 26rpx;} 362 .no_store{color:#d60021; font-size: 26rpx;}
363 -.gray{color: #ccc;}  
364 \ No newline at end of file 363 \ No newline at end of file
  364 +.gray{color: #ccc;}
  365 +.graying{ background-color: gainsboro }
365 \ No newline at end of file 366 \ No newline at end of file
pages/cart/cart2/cart2.js
@@ -3911,13 +3911,13 @@ Page({ @@ -3911,13 +3911,13 @@ Page({
3911 await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", { 3911 await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", {
3912 data: sto_rq 3912 data: sto_rq
3913 }).then(res => { 3913 }).then(res => {
3914 - if (res.data.code == 0) { 3914 + if (res.data.code == 0 && res.data.data.total > 0) {
3915 plist = res.data.data.pageData[0]; 3915 plist = res.data.data.pageData[0];
3916 } 3916 }
3917 }) 3917 })
3918 3918
3919 var isok = 1; 3919 var isok = 1;
3920 - if (goods_num > plist.CanOutQty - lock) { 3920 + if (!plist || goods_num > plist.CanOutQty - lock) {
3921 isok = 0; 3921 isok = 0;
3922 } 3922 }
3923 func(isok); 3923 func(isok);
pages/cart/cart2/cart2.wxml
@@ -109,7 +109,7 @@ @@ -109,7 +109,7 @@
109 </view> 109 </view>
110 110
111 <!-- 使用搭配 --> 111 <!-- 使用搭配 -->
112 - <cart_collect_temp bind:childFun="select_coll" 112 + <cart_collect_temp bind:childFun="select_coll" sales_rules="{{sales_rules}}" pick="{{item.pickup_id}}"
113 is_cart="1" cart_index="{{index}}" 113 is_cart="1" cart_index="{{index}}"
114 all_collocation_list="{{item.collocationList}}" /> 114 all_collocation_list="{{item.collocationList}}" />
115 115
@@ -377,7 +377,7 @@ @@ -377,7 +377,7 @@
377 </block> 377 </block>
378 378
379 <!-- 使用搭配 --> 379 <!-- 使用搭配 -->
380 - <cart_collect_temp bind:childFun="select_coll" all_collocation_list="{{all_collocation_list}}" /> 380 + <cart_collect_temp bind:childFun="select_coll" all_collocation_list="{{all_collocation_list}}" sales_rules="{{sales_rules}}" pick="{{bn_pick}}" />
381 381
382 382
383 <!-- 如果是等级卡的商品,会员没有注册,要提醒注册 --> 383 <!-- 如果是等级卡的商品,会员没有注册,要提醒注册 -->