diff --git a/pages/goods/goodsInfo/goodsInfo.js b/pages/goods/goodsInfo/goodsInfo.js index 2495fe8..b407211 100644 --- a/pages/goods/goodsInfo/goodsInfo.js +++ b/pages/goods/goodsInfo/goodsInfo.js @@ -246,6 +246,7 @@ Page({ showPoster: false, hui_condition:null, sto_sele_name_1:'',//分享的门店名称 + fir_goods:null, }, @@ -428,7 +429,7 @@ Page({ var ee=JSON.parse(JSON.stringify(e)); //--定时器推迟一下-- setTimeout(function () { - if(th.data.data) var g_distr_type=th.data.data.distr_type; + if(th.data.fir_goods) var g_distr_type=th.data.fir_goods.distr_type; //--如果默认门店的配送方式不对,就不能被选择,这里不控制,如果不一样,就说明配送方式不对-- if(ee.distr_type!=0 && g_distr_type!=0 && ee.distr_type!=g_distr_type ){ //th.data.fir_def_store={}; //赋值空对象 @@ -448,13 +449,15 @@ Page({ if (that.data.lat != null) { //如果经纬度有变化的话 if( appd.lat==that.data.lat && appd.lon==that.data.lon && e.distance>0 ){ - that.data.fir_def_store=e; - that.setData({ - def_pick_store: e, - sto_sele_name: e.pickup_name, - sto_sele_id: e.pickup_id, - sto_sele_distr: e.distr_type - }) + //that.data.fir_def_store=e; + // that.setData({ + // def_pick_store: e, + // sto_sele_name: e.pickup_name, + // sto_sele_id: e.pickup_id, + // sto_sele_distr: e.distr_type + // }) + that.set_def_storage(e); + }else{ //要用接口是获取距离,js的计算不准 getApp().request.promiseGet("/api/weshop/pickup/list",{ @@ -465,19 +468,19 @@ Page({ if (e){ e.is_no_dis=ee.is_no_dis; appd.pk_store=e; - that.data.fir_def_store=e; - that.setData({ - def_pick_store: e, - sto_sele_name: e.pickup_name, - sto_sele_id: e.pickup_id, - sto_sele_distr: e.distr_type - }) + // that.data.fir_def_store=e; + // that.setData({ + // def_pick_store: e, + // sto_sele_name: e.pickup_name, + // sto_sele_id: e.pickup_id, + // sto_sele_distr: e.distr_type + // }) + that.set_def_storage(e); } } }) } - //e.distance = distance; appd.lat=that.data.lat; appd.lon=that.data.lon; @@ -485,21 +488,75 @@ Page({ }else{ if (e) { e.distance = null; - that.data.fir_def_store=e; - that.setData({ - def_pick_store: e, - sto_sele_name: e.pickup_name, - sto_sele_id: e.pickup_id, - sto_sele_distr: e.distr_type - }) + // that.data.fir_def_store=e; + // that.setData({ + // def_pick_store: e, + // sto_sele_name: e.pickup_name, + // sto_sele_id: e.pickup_id, + // sto_sele_distr: e.distr_type + // }) + that.set_def_storage(e); } } }, 500) },700) - - }); - + }); }, + + + //--- 设置一下默认库存的数量 ---- + set_def_storage(ee){ + var that=this,th=this; + getApp().getConfig2(function(e){ + var sales_rules=e.sales_rules; + if(sales_rules==2){ + getApp().waitfor2(that,"wait_for_user_store","fir_goods",function(){ + var lock=0,plist=null; + var gd=that.data.fir_goods; + //先读取门店的lock,采用链式写法,少用await + getApp().request.promiseGet("/api/weshop/order/ware/lock/page",{ + data:{store_id:os.stoid,wareId:that.data.fir_goods.goods_id,storageId:ee.pickup_id,pageSize:1000} + }).then(res=>{ + if(res.data.code==0 && res.data.data.total>0){ + for(var i in res.data.data.pageData) + lock+=res.data.data.pageData[i].outQty + } + //---通过接口获取门店的线下库存信息-- + return getApp().request.promiseGet("/api/weshop/goods/getWareStorages",{ + data:{storageNos:ee.pickup_no,wareIds:encodeURIComponent(th.data.data.erpwareid),storeId:os.stoid} + }) + }).then(res=>{ + if(res.data.code==0 && res.data.data.total>0){ + plist=res.data.data.pageData[0]; + } + if(plist && plist.CanOutQty-lock>0){ + ee.CanOutQty=plist.CanOutQty-lock; + }else{ + ee.CanOutQty=0; + } + //--给门店赋值线下库存-- + that.data.fir_def_store=ee; + that.setData({ + def_pick_store: ee, + sto_sele_name: ee.pickup_name, + sto_sele_id: ee.pickup_id, + sto_sele_distr: ee.distr_type + }) + }) + }) + }else{ + that.data.fir_def_store=ee; + that.setData({ + def_pick_store: ee, + sto_sele_name: ee.pickup_name, + sto_sele_id: ee.pickup_id, + sto_sele_distr: ee.distr_type + }) + } + }) + + }, + //------------程序初始化入口------------- async init(gid) { @@ -709,7 +766,9 @@ Page({ }); } } - + + //-- 把商品的赋值 -- + ee.data.fir_goods=JSON.parse(JSON.stringify(t.data.data)); ee.check_is_youhui(ee.data.gid); t.data.data.on_time = ut.formatTime(t.data.data.on_time, 'yyyy-MM-dd hh:mm:ss'); @@ -758,6 +817,7 @@ Page({ //获取门店 ee.get_sto(); //--等待某个值只运行---,这里有可能因为导航的时间太久,而不能计算门店库存 + /*--- getApp().waitfor2(that,"wait_for_user_store","fir_def_store",function(){ if(th.data.fir_def_store && th.data.fir_def_store.pickup_id ){ var lock=0,plist=null; @@ -786,7 +846,7 @@ Page({ th.setData({def_pick_store:that.data.fir_def_store}); }) } - }) + })--*/ }else{ //获取门店 ee.get_sto();