diff --git a/pages/cart/cart2/cart2.js b/pages/cart/cart2/cart2.js index e0fb47c..4d499d8 100644 --- a/pages/cart/cart2/cart2.js +++ b/pages/cart/cart2/cart2.js @@ -113,11 +113,7 @@ Page({ onShow: function() { var th=this; if (th.data.isclose==0){ - /*--- - wx.navigateTo({ - url: "/pages/user/index/index" - //url: "/pages/index/index/index" - })---*/ + wx.switchTab({ url: "/pages/index/index/index" }) @@ -131,7 +127,7 @@ Page({ th.setData({user_addr: ie }); var going=0; - //使用计算器,避免空现象 + //使用计时器,避免空现象 var jishi= setInterval(function () { if (th.data.is_b_now == 1 && going==0) { if(th.data.bn_goods) { @@ -243,7 +239,7 @@ Page({ data: { user_id: to.globalData.user_id, selected:1, store_id: oo.stoid, pageSize: 600 }, - success: async function (su) { + success:function (su) { //按门店分类的数组 var arr = new Array(); var carr = su.data.data.pageData; @@ -305,74 +301,13 @@ Page({ arr.push(ie); } } - - //------------开始计算使用优惠券相关------------ - for(var ind in arr){ - var ep=arr[ind]; - var goodlist=ep.goods; - - //--更优惠券抵用有关,立即购买的,如果是购物车,如果有等级价还有考虑等级价的东西 - //就要把相应的值,写入cartlist数组中-- - var ckeck_quan_price=0, - check_quan_price_list='', - check_quan_ware_list=''; - - for(var i in goodlist){ - var gd=goodlist[i]; - //--如果是秒杀就跳出-- - if(gd.prom_type==1){ continue; } - var item_price=gd.goods_price*gd.goods_num; - ckeck_quan_price+=item_price; - - //--组装价格list-- - if (check_quan_price_list) { - check_quan_price_list += "," +item_price; - } else { - check_quan_price_list = item_price; - } - //--组装商品的线下erpwareid-- - if (check_quan_ware_list) { - check_quan_ware_list += "," +gd['erpwareid']; - } else { - check_quan_ware_list = gd['erpwareid']; - } - } - - arr[ind].ckeck_quan_price=ckeck_quan_price; - arr[ind].check_quan_ware_list=check_quan_ware_list; - arr[ind].check_quan_price_list=check_quan_price_list; - - //是否关闭使用优惠券 - if (th.data.is_close_quan != 1) { - //调用接口,获取优惠券的列表 - var url="/api/weshop/couponList/getUseCouponList"; - await app.request.promiseGet(url,{ - data:{storeId:oo.stoid,userId:app.globalData.user_id,BuySum:ckeck_quan_price,WareIds:check_quan_ware_list,pageSize:100} - }).then(res=>{ - if(res.data.code==0) - arr[ind].quan_list=res.data.data.pageData; - }) - - var frozenQuan=null; - var url0="/api/weshop/users/frozenQuan/listFrozenQuan/"+app.globalData.user_id; - await app.request.promiseGet(url0,{1:1}).then(res=>{ - if(res.data.code==0){ - frozenQuan=res.data.data; - } - }) - - if (frozenQuan && arr[ind].quan_list){ - arr[ind].quan_list=th.check_is_frozenQuan(arr[ind].quan_list,frozenQuan); - } - - } - } - th.setData({ cartlist: arr, }), th.calculatePrice(); + //--- 获取一下看有没有优惠券 ---- + th.get_cart_quan(); } }); }, @@ -381,7 +316,6 @@ Page({ get_buy_goods: function (e){ var th=this; var gg = to.get_b_now(); - //--------如果goods_id一样,就是要立即购买----- if(e==gg.goods_id){ a.get("/api/weshop/goods/get/" + oo.stoid+"/"+e, { @@ -408,7 +342,6 @@ Page({ } } - switch (gd.prom_type){ case 0: case 2: @@ -419,46 +352,21 @@ Page({ //--此时开始计算商品的使用券相关,如果有等级价还要计算和等级价相关的, // 如果有优惠促销,还要把促销的部分计算在内,因为促销还有不能使用优惠券-- t.data.data.shop_price=gg.goods_price; - th.data.ckeck_quan_price=t.data.data.shop_price*gg.goods_num; th.data.check_quan_price_list=t.data.data.shop_price*gg.goods_num+""; th.data.check_quan_ware_list=t.data.data.erpwareid+""; - var quanlist=null; - - if (th.data.is_close_quan != 1) { - var url="/api/weshop/couponList/getUseCouponList"; - await app.request.promiseGet(url,{ - data:{storeId:oo.stoid,userId:app.globalData.user_id,BuySum:th.data.ckeck_quan_price,WareIds:th.data.check_quan_ware_list,pageSize:100} - }).then(res=>{ - if(res.data.code==0) - quanlist=res.data.data.pageData; - - - }) - } - - var frozenQuan=null; - var url0="/api/weshop/users/frozenQuan/listFrozenQuan/"+app.globalData.user_id; - await app.request.promiseGet(url0,{1:1}).then(res=>{ - if(res.data.code==0){ - frozenQuan=res.data.data; - } - }) - - if (frozenQuan && quanlist){ - quanlist=th.check_is_frozenQuan(quanlist,frozenQuan); - } - t.data.data.prom_id = 0; t.data.data.prom_type = 0; th.setData({ bn_goods: t.data.data, bn_pickname: gg.pick_name, bn_exp_type: et,index:m_wind, - bn_pick: gg.pick_id, bn_t_exp_t: distr_t,selected_quan_list:quanlist + bn_pick: gg.pick_id, bn_t_exp_t: distr_t }); //计算价格 th.calculatePrice2(); + //获取优惠券 + th.get_buy_now_quan(); break; case 1: //---秒杀----- @@ -474,37 +382,16 @@ Page({ th.data.ckeck_quan_price=t.data.data.shop_price*gg.goods_num; th.data.check_quan_price_list=t.data.data.shop_price*gg.goods_num+""; th.data.check_quan_ware_list=t.data.data.erpwareid+""; - - if (th.data.is_close_quan != 1) { - - var url="/api/weshop/couponList/getUseCouponList"; - await app.request.promiseGet(url,{ - data:{storeId:oo.stoid,userId:app.globalData.user_id,BuySum:th.data.ckeck_quan_price,WareIds:th.data.check_quan_ware_list,pageSize:100} - }).then(res=>{ - if(res.data.code==0) - quanlist=res.data.data.pageData; - }) - - var frozenQuan=null; - var url0="/api/weshop/users/frozenQuan/listFrozenQuan/"+app.globalData.user_id; - await app.request.promiseGet(url0,{1:1}).then(res=>{ - if(res.data.code==0){ - frozenQuan=res.data.data; - } - }) - - if (frozenQuan && quanlist){ - quanlist=th.check_is_frozenQuan(quanlist,frozenQuan); - } - } } th.setData({ bn_goods: t.data.data, bn_pickname: gg.pick_name, bn_exp_type: et,index:m_wind, - bn_pick: gg.pick_id, bn_t_exp_t: distr_t,selected_quan_list:quanlist + bn_pick: gg.pick_id, bn_t_exp_t: distr_t }); //计算价格 th.calculatePrice2(); + //获取优惠券 + th.get_buy_now_quan(); } }); @@ -1397,7 +1284,9 @@ Page({ //--验证是否已经冻结-- check_is_frozenQuan:function(quanlist,frozenQuan){ - console.log("券列表",quanlist); + console.log("券列表",quanlist); + if(!quanlist) return null; + if(!frozenQuan) return quanlist; var arr=[]; for(var i=0;i{ + if(res.data.code==0){ frozenQuan=res.data.data; } + //--调用接口,获取优惠券的列表,3秒钟内控制接口请求-- + var url="/api/weshop/couponList/getUseCouponList"; + app.request.time_limit_get(6,url,{ + data:{storeId:oo.stoid,userId:app.globalData.user_id,BuySum:ckeck_quan_price,WareIds:check_quan_ware_list,pageSize:100}, + success:function (res) { + if (res.data.code == 0) { + arr[ind].quan_list = res.data.data.pageData; + arr[ind].quan_list = th.check_is_frozenQuan(arr[ind].quan_list, frozenQuan); + th.setData({cartlist:arr }) + } + } + }) + }) + } + } + }, + //------ 获取立即购买的购物车的劵 -------- + get_buy_now_quan:function () { + var quanlist=null,th=this,frozenQuan = null; + if(th.data.is_close_quan != 1) + { + var url0 = "/api/weshop/users/frozenQuan/listFrozenQuan/" + app.globalData.user_id; + var url="/api/weshop/couponList/getUseCouponList"; + app.request.promiseGet(url0, {1: 1}).then(res => { + if (res.data.code == 0) { + frozenQuan = res.data.data; + } + app.request.time_limit_get(6, url, { + data: { + storeId: oo.stoid, + userId: app.globalData.user_id, + BuySum: th.data.ckeck_quan_price, + WareIds: th.data.check_quan_ware_list, + pageSize: 100 + }, + success: function (res) { + if (res.data.code == 0) { + quanlist = res.data.data.pageData; + if (quanlist) { + quanlist = th.check_is_frozenQuan(quanlist, frozenQuan); + th.setData({selected_quan_list:quanlist }) + } + } + } + + }) + }) + + } + } }); diff --git a/utils/request.js b/utils/request.js index affbf49..8fd3bab 100644 --- a/utils/request.js +++ b/utils/request.js @@ -8,7 +8,8 @@ module.exports = { //"content-type": "application/texts" }, s = "GET" != (e = e.toUpperCase()) && o.data ? t.json2Form(o.data) : o.data; i = this.modifyUrl(i, o), o.isShowLoading = void 0 === o.isShowLoading || o.isShowLoading, - o.isShowLoading && this.showLoading(), console.log("app.request", i, o), wx.request(Object.assign({}, o, { + o.isShowLoading && this.showLoading(); + var req=wx.request(Object.assign({}, o, { url: i, method: e, data: s, @@ -20,9 +21,10 @@ module.exports = { o.isShowLoading && n.hideLoading(), n.doFail(o, t); } })); + return req; }, get: function (t, e) { - this.request("GET", t, e); + return this.request("GET", t, e); }, post: function (t, e) { this.request("POST", t, e); @@ -202,6 +204,13 @@ module.exports = { fail(err) { data.isShowLoading && th.hideLoading(); reject(err); } }) }) + }, + //--------具有时间限制的读取接口---------- + time_limit_get(time,url,data){ + var req=this.get(url,data); + setTimeout(function () { + req.abort(); + },time*1000) } }; \ No newline at end of file