Commit 570ac6b70fe702294373bd1ab078e921e1f321b6

Authored by yvan.ni
1 parent 83fe91ea

库存不足显示的优化

pages/goods/goodsInfo/goodsInfo.js
@@ -246,6 +246,7 @@ Page({ @@ -246,6 +246,7 @@ Page({
246 showPoster: false, 246 showPoster: false,
247 hui_condition:null, 247 hui_condition:null,
248 sto_sele_name_1:'',//分享的门店名称 248 sto_sele_name_1:'',//分享的门店名称
  249 + fir_goods:null,
249 250
250 }, 251 },
251 252
@@ -428,7 +429,7 @@ Page({ @@ -428,7 +429,7 @@ Page({
428 var ee=JSON.parse(JSON.stringify(e)); 429 var ee=JSON.parse(JSON.stringify(e));
429 //--定时器推迟一下-- 430 //--定时器推迟一下--
430 setTimeout(function () { 431 setTimeout(function () {
431 - if(th.data.data) var g_distr_type=th.data.data.distr_type; 432 + if(th.data.fir_goods) var g_distr_type=th.data.fir_goods.distr_type;
432 //--如果默认门店的配送方式不对,就不能被选择,这里不控制,如果不一样,就说明配送方式不对-- 433 //--如果默认门店的配送方式不对,就不能被选择,这里不控制,如果不一样,就说明配送方式不对--
433 if(ee.distr_type!=0 && g_distr_type!=0 && ee.distr_type!=g_distr_type ){ 434 if(ee.distr_type!=0 && g_distr_type!=0 && ee.distr_type!=g_distr_type ){
434 //th.data.fir_def_store={}; //赋值空对象 435 //th.data.fir_def_store={}; //赋值空对象
@@ -448,13 +449,15 @@ Page({ @@ -448,13 +449,15 @@ Page({
448 if (that.data.lat != null) { 449 if (that.data.lat != null) {
449 //如果经纬度有变化的话 450 //如果经纬度有变化的话
450 if( appd.lat==that.data.lat && appd.lon==that.data.lon && e.distance>0 ){ 451 if( appd.lat==that.data.lat && appd.lon==that.data.lon && e.distance>0 ){
451 - that.data.fir_def_store=e;  
452 - that.setData({  
453 - def_pick_store: e,  
454 - sto_sele_name: e.pickup_name,  
455 - sto_sele_id: e.pickup_id,  
456 - sto_sele_distr: e.distr_type  
457 - }) 452 + //that.data.fir_def_store=e;
  453 + // that.setData({
  454 + // def_pick_store: e,
  455 + // sto_sele_name: e.pickup_name,
  456 + // sto_sele_id: e.pickup_id,
  457 + // sto_sele_distr: e.distr_type
  458 + // })
  459 + that.set_def_storage(e);
  460 +
458 }else{ 461 }else{
459 //要用接口是获取距离,js的计算不准 462 //要用接口是获取距离,js的计算不准
460 getApp().request.promiseGet("/api/weshop/pickup/list",{ 463 getApp().request.promiseGet("/api/weshop/pickup/list",{
@@ -465,19 +468,19 @@ Page({ @@ -465,19 +468,19 @@ Page({
465 if (e){ 468 if (e){
466 e.is_no_dis=ee.is_no_dis; 469 e.is_no_dis=ee.is_no_dis;
467 appd.pk_store=e; 470 appd.pk_store=e;
468 - that.data.fir_def_store=e;  
469 - that.setData({  
470 - def_pick_store: e,  
471 - sto_sele_name: e.pickup_name,  
472 - sto_sele_id: e.pickup_id,  
473 - sto_sele_distr: e.distr_type  
474 - }) 471 + // that.data.fir_def_store=e;
  472 + // that.setData({
  473 + // def_pick_store: e,
  474 + // sto_sele_name: e.pickup_name,
  475 + // sto_sele_id: e.pickup_id,
  476 + // sto_sele_distr: e.distr_type
  477 + // })
  478 + that.set_def_storage(e);
475 } 479 }
476 480
477 } 481 }
478 }) 482 })
479 } 483 }
480 -  
481 //e.distance = distance; 484 //e.distance = distance;
482 appd.lat=that.data.lat; 485 appd.lat=that.data.lat;
483 appd.lon=that.data.lon; 486 appd.lon=that.data.lon;
@@ -485,21 +488,75 @@ Page({ @@ -485,21 +488,75 @@ Page({
485 }else{ 488 }else{
486 if (e) { 489 if (e) {
487 e.distance = null; 490 e.distance = null;
488 - that.data.fir_def_store=e;  
489 - that.setData({  
490 - def_pick_store: e,  
491 - sto_sele_name: e.pickup_name,  
492 - sto_sele_id: e.pickup_id,  
493 - sto_sele_distr: e.distr_type  
494 - }) 491 + // that.data.fir_def_store=e;
  492 + // that.setData({
  493 + // def_pick_store: e,
  494 + // sto_sele_name: e.pickup_name,
  495 + // sto_sele_id: e.pickup_id,
  496 + // sto_sele_distr: e.distr_type
  497 + // })
  498 + that.set_def_storage(e);
495 } 499 }
496 } 500 }
497 }, 500) 501 }, 500)
498 },700) 502 },700)
499 -  
500 - });  
501 - 503 + });
502 }, 504 },
  505 +
  506 +
  507 + //--- 设置一下默认库存的数量 ----
  508 + set_def_storage(ee){
  509 + var that=this,th=this;
  510 + getApp().getConfig2(function(e){
  511 + var sales_rules=e.sales_rules;
  512 + if(sales_rules==2){
  513 + getApp().waitfor2(that,"wait_for_user_store","fir_goods",function(){
  514 + var lock=0,plist=null;
  515 + var gd=that.data.fir_goods;
  516 + //先读取门店的lock,采用链式写法,少用await
  517 + getApp().request.promiseGet("/api/weshop/order/ware/lock/page",{
  518 + data:{store_id:os.stoid,wareId:that.data.fir_goods.goods_id,storageId:ee.pickup_id,pageSize:1000}
  519 + }).then(res=>{
  520 + if(res.data.code==0 && res.data.data.total>0){
  521 + for(var i in res.data.data.pageData)
  522 + lock+=res.data.data.pageData[i].outQty
  523 + }
  524 + //---通过接口获取门店的线下库存信息--
  525 + return getApp().request.promiseGet("/api/weshop/goods/getWareStorages",{
  526 + data:{storageNos:ee.pickup_no,wareIds:encodeURIComponent(th.data.data.erpwareid),storeId:os.stoid}
  527 + })
  528 + }).then(res=>{
  529 + if(res.data.code==0 && res.data.data.total>0){
  530 + plist=res.data.data.pageData[0];
  531 + }
  532 + if(plist && plist.CanOutQty-lock>0){
  533 + ee.CanOutQty=plist.CanOutQty-lock;
  534 + }else{
  535 + ee.CanOutQty=0;
  536 + }
  537 + //--给门店赋值线下库存--
  538 + that.data.fir_def_store=ee;
  539 + that.setData({
  540 + def_pick_store: ee,
  541 + sto_sele_name: ee.pickup_name,
  542 + sto_sele_id: ee.pickup_id,
  543 + sto_sele_distr: ee.distr_type
  544 + })
  545 + })
  546 + })
  547 + }else{
  548 + that.data.fir_def_store=ee;
  549 + that.setData({
  550 + def_pick_store: ee,
  551 + sto_sele_name: ee.pickup_name,
  552 + sto_sele_id: ee.pickup_id,
  553 + sto_sele_distr: ee.distr_type
  554 + })
  555 + }
  556 + })
  557 +
  558 + },
  559 +
503 560
504 //------------程序初始化入口------------- 561 //------------程序初始化入口-------------
505 async init(gid) { 562 async init(gid) {
@@ -709,7 +766,9 @@ Page({ @@ -709,7 +766,9 @@ Page({
709 }); 766 });
710 } 767 }
711 } 768 }
712 - 769 +
  770 + //-- 把商品的赋值 --
  771 + ee.data.fir_goods=JSON.parse(JSON.stringify(t.data.data));
713 ee.check_is_youhui(ee.data.gid); 772 ee.check_is_youhui(ee.data.gid);
714 773
715 t.data.data.on_time = ut.formatTime(t.data.data.on_time, 'yyyy-MM-dd hh:mm:ss'); 774 t.data.data.on_time = ut.formatTime(t.data.data.on_time, 'yyyy-MM-dd hh:mm:ss');
@@ -758,6 +817,7 @@ Page({ @@ -758,6 +817,7 @@ Page({
758 //获取门店 817 //获取门店
759 ee.get_sto(); 818 ee.get_sto();
760 //--等待某个值只运行---,这里有可能因为导航的时间太久,而不能计算门店库存 819 //--等待某个值只运行---,这里有可能因为导航的时间太久,而不能计算门店库存
  820 + /*---
761 getApp().waitfor2(that,"wait_for_user_store","fir_def_store",function(){ 821 getApp().waitfor2(that,"wait_for_user_store","fir_def_store",function(){
762 if(th.data.fir_def_store && th.data.fir_def_store.pickup_id ){ 822 if(th.data.fir_def_store && th.data.fir_def_store.pickup_id ){
763 var lock=0,plist=null; 823 var lock=0,plist=null;
@@ -786,7 +846,7 @@ Page({ @@ -786,7 +846,7 @@ Page({
786 th.setData({def_pick_store:that.data.fir_def_store}); 846 th.setData({def_pick_store:that.data.fir_def_store});
787 }) 847 })
788 } 848 }
789 - }) 849 + })--*/
790 }else{ 850 }else{
791 //获取门店 851 //获取门店
792 ee.get_sto(); 852 ee.get_sto();