diff --git a/pages/cart/cart2/cart2.js b/pages/cart/cart2/cart2.js index 4351297..bb6d5f7 100644 --- a/pages/cart/cart2/cart2.js +++ b/pages/cart/cart2/cart2.js @@ -1,5 +1,5 @@ var t = getApp(),app=t, a = t.request, e = require("../../../utils/common.js"), - s = require("../../../utils/util.js"), o = require("../../../utils/md5.js"), to = getApp(); + s = require("../../../utils/util.js"),ut=s, o = require("../../../utils/md5.js"), to = getApp(); var oo=t.globalData.setting,os=oo; var regeneratorRuntime = require('../../../utils/runtime.js'); var util_pay = require("../../../utils/pay.js"); @@ -85,8 +85,17 @@ Page({ is_shipping_code:"",//插入用户默认地址 wu_arr_txt:"", //要更新的物流的字段 - sales_rules:1, //默认是显示线上库存 - + sales_rules:1, //默认是显示线上库存 + isget_by_quan:{}, //是否调用了接口获取包邮券 + get_by_quan_list:null, //立即购买的 + get_by_quan_list_cart:{}, //购物车的 + by_quan_list_cart:null, //点击选择的包邮列表 + + //如果是全场包邮了,或者是全场不包邮了,就不要选包邮券 + is_no_by:{}, + is_by:{}, + is_quan_by:{}, + }, onLoad: function(t) { @@ -111,6 +120,13 @@ Page({ }, onUnload: function () { this.setData({ isclose: 1 })}, + onHide: function () { + this.setData({ + isget_by_quan:{}, + is_no_by:{}, + is_by:{} + }) + }, //----------子页返回父页触发---------- onShow: function() { @@ -454,11 +470,26 @@ Page({ var umoney = th.data.userinfo.user_money - th.data.txmon - th.data.userinfo.frozen_money; var freight_free = ee.freight_free; //全场满多少包邮 - var c_arr=th.data.cartlist; + var no_ex_id=ee.no_ex_id; + var no_ex_good=null; + var by_qc={}; + + if(no_ex_id && freight_free>0){ + //-----------获取不包邮区域,不包邮商品------- + await getApp().request.promiseGet("/api/weshop/areaFeemail/getAreaGoods",{ + data:{store_id:os.stoid,id:no_ex_id} + }).then(res=>{ + if(res.data.code==0){ + by_qc=res.data.data[0]; + } + }) + } + var c_arr=th.data.cartlist; //---循环购物车--- for(var i=0;i0 && o_price>freight_free && c_arr[i].exp_type == 0 && (by_qc.region_list || by_qc.goods_list) ){ + //如果有设置不包邮区域的时候 + if(by_qc.region_list){ + if(th.check_by_area(by_qc.region_list)){ + freight_free=0; + th.data.is_no_by[pickid]=1; } } + //如果有设置不包邮区商品 + if(by_qc.goods_list && freight_free){ + no_ex_good=res.data.data.goods_list; + } + } + + //--如果是物流,且选择了地址,就要开始显示包邮券-- + if (c_arr[i].exp_type == 0 && th.data.user_addr != null) { + //看是不是有调用过包邮券 + if(!th.data.isget_by_quan[pickid]){ + //--判断要不要显示包邮券,链式调用接口--- + getApp().request.promiseGet("/api/weshop/userfeemail/pageAndArea",{ + data:{store_id:os.stoid,isuse:0,condition:o_price,user_id:getApp().globalData.user_id} + }).then(res=>{ + if(res.data.code==0 && res.data.data.total>0){ + //此时要循环判断包邮的地区,不包邮商品是不是符合 + var arr=[],quanlist=res.data.data.pageData; + quanlist = th.check_is_frozenQuan(quanlist, th.data.frozenQuan,1); + for(var i in quanlist){ + var item=quanlist[i]; + var goods=cart_item.goods; + var g_arr=[]; + for(var ii in goods){ + g_arr.push(goods[ii].goods_id); + } + + if(item.region_list && th.check_by_area(item.region_list)) continue; //如果是不包邮区域 + if(item.goods_list){ + var no_goods_arr=item.goods_list.split(","); + if(ut.isContained(no_goods_arr,g_arr)) continue; //如果是不包邮商品 + } + arr.push(item); + } + if(arr){ + th.data.get_by_quan_list_cart[pickid]=arr; + th.setData({get_by_quan_list_cart:th.data.get_by_quan_list_cart}); + } + th.data.isget_by_quan[pickid]=1; + } + }) + } + } + + var quan_no=null; + if(th.data.using_quan[pickid])quan_no=th.data.using_quan[pickid].coupon_no; + //如果是包邮券的时候,要看看券的情况 + if(quan_no && th.data.using_quan[pickid].isby==1){ + var quan=th.data.using_quan[pickid]; + if(!quan.goods_list){ + th.data.is_quan_by[pickid]=1; //专门给券的判断用的 + }else{ + th.data.is_quan_by[pickid]=0; + //看有没有模板的包邮 + if(no_ex_good){ + var arr=no_ex_good.split(","); + var arr2=quan.goods_list.split(","); + if(ut.isContained(arr,arr2)){ + getApp().my_warnning("全场不包邮商品和包邮券的重复",0,th); + return false; + } + var n_arr=ut.mergeArray(arr,arr2); + no_ex_good=n_arr.join(","); + }else{ + no_ex_good=quan.goods_list; + } + } + }else{ + th.data.is_quan_by[pickid]=0; //专门给券的判断用的 } + //--------循环计算总价----------- + for(var j=0;jfreight_free && freight_free>0 && !is_good_no_by && th.data.is_no_by[pickid]!=1) continue; + //--如果是包邮券使用的情况下,如果商品是包邮的,那么就不进行计算-- + if(th.data.using_quan[pickid] && th.data.using_quan[pickid].isby==1 && !is_good_no_by) continue; + + //----------------如果是选择了物流--------------------- + if (c_arr[i].exp_type == 0 && item[j].is_free_shipping==0){ + //如果地址不为空 + if (th.data.user_addr!=null){ + switch (item[j]['exp_sum_type']) { + case 1: + //统一运费 + o_shipping_price += item[j]['uniform_exp_sum'];break; + case 2: + if (goods_weight < 0) goods_weight = 0; + //累积商品重量 每种商品的重量 * 数量 + goods_weight += item[j]['weight'] * item[j]['goods_num']; break; + case 3: + if (goods_piece < 0) goods_piece = 0; + //累积商品数量 + goods_piece += item[j]['goods_num'];break; + } + } + } + } + + //计算物流价格 if (c_arr[i].exp_type == 0) { var code = th.data.wu_arr[c_arr[i].wind].code; th.data.cartlist[i].shipping_price = th.calculatewuliu(code, o_shipping_price, goods_weight, goods_piece,th.data.user_addr, freight_free, o_price, rs); + + if(!th.data.using_quan[pickid] || th.data.using_quan[pickid].isby!=1){ + if( th.data.cartlist[i].shipping_price ==0) th.data.is_by[pickid]=0; //已经全场包邮,就不要选择券了 + } }else{ th.data.cartlist[i].shipping_price=0; } @@ -504,26 +636,33 @@ Page({ th.data.cartlist[i].shipping_price=th.data.cartlist[i].shipping_price.toFixed(2); //---如果有选择优惠券的情况下--- var quan_price=0; - var coupon_price=0,bn_pick=th.data.bn_pick,pickid=cart_item.pickup_id; - console.log("calculatePrice--quan"); + var coupon_price=0; var quan_no= null; if(th.data.using_quan[pickid]!=null && th.data.using_quan[pickid]!=undefined) quan_no=th.data.using_quan[pickid].coupon_no; if(quan_no){ - //---获取优惠券优惠--- - await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice",{ - data:{storeId:oo.stoid,CashRepNo:quan_no, WaresSum:cart_item.check_quan_price_list, WareIds:cart_item.check_quan_ware_list} - }).then(res=>{ - if(res.data.code==0 && res.data.data.length>0){ - var q_data=res.data.data; + //如果不是包邮券的时候 + if(th.data.using_quan[pickid] && th.data.using_quan[pickid].isby!=1) { + //---获取优惠券优惠--- + await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice", { + data: { + storeId: oo.stoid, + CashRepNo: quan_no, + WaresSum: cart_item.check_quan_price_list, + WareIds: cart_item.check_quan_ware_list + } + }).then(res => { + if (res.data.code == 0 && res.data.data.length > 0) { + var q_data = res.data.data; //--存储商品优惠的内容-- - th.data.cartlist[i].quan_youhui_list=q_data; - for(var k in q_data ) - quan_price+=q_data[k].WareCashSum; - } - }) + th.data.cartlist[i].quan_youhui_list = q_data; + for (var k in q_data) + quan_price += q_data[k].WareCashSum; + } + }) + } } //总价计算,总价不包含运费 @@ -559,6 +698,8 @@ Page({ if (coupon_price>0) th.data.cartlist[i].coupon_price=coupon_price.toFixed(2); else th.data.cartlist[i].coupon_price = coupon_price + if(quan_no) th.data.cartlist[i].quan_no = quan_no; + th.data.cartlist[i].goods_price = o_price.toFixed(2); th.data.cartlist[i].order_amount= th.data.cartlist[i].order_amount- th.data.cartlist[i].user_money; //会员使用余额 @@ -591,13 +732,10 @@ Page({ th.setData({ [atxt]: all_total_m, [atxt1]: all_order_m, [atxt2]: all_price, [atxt3]: all_user_m, [atxt4]: all_shipping_m, [atxt5]: all_coupon_price_m }) - console.log('formData',th.data.formData); - console.log("------------------------"); }); }); }, - //---------计算立即购买---------- calculatePrice2: function () { @@ -615,6 +753,31 @@ Page({ var o_shipping_price = 0, goods_weight = -1, goods_piece = -1; //-----------当地址不为空,且是物流时,计算物流费用---------- if (th.data.user_addr != null && th.data.bn_exp_type == 0 && good.is_free_shipping == 0 ){ + + //看是不是有调用过包邮券 + if(!th.data.isget_by_quan[th.data.bn_pick]){ + //--判断要不要显示包邮券,链式调用接口--- + getApp().request.promiseGet("/api/weshop/userfeemail/pageAndArea",{ + data:{store_id:os.stoid,isuse:0,condition:allpice,user_id:getApp().globalData.user_id} + }).then(res=>{ + if(res.data.code==0 && res.data.data.total>0){ + //此时要循环判断包邮的地区,不包邮商品是不是符合 + var arr=[],quanlist=res.data.data.pageData; + quanlist = th.check_is_frozenQuan(quanlist, th.data.frozenQuan,1); + for(var i in quanlist){ + var item=quanlist[i]; + if(item.region_list && th.check_by_area(item.region_list)) continue; //如果是不包邮区域 + if(item.goods_list && th.check_by_goods(item.goods_list)) continue; //如果是不包邮商品 + arr.push(item); + } + if(arr){ + th.setData({get_by_quan_list:arr}); + } + th.data.isget_by_quan[th.data.bn_pick]=1; + } + }) + } + switch (good['exp_sum_type']) { case 1: //统一运费 @@ -630,36 +793,74 @@ Page({ } var code = th.data.wu_arr[th.data.index].code; - var freight_free = ee.freight_free; //全场满多少包邮 + var freight_free = ee.freight_free; //全场满多少包邮 + var no_ex_id=ee.no_ex_id; + th.data.is_no_by[th.data.bn_pick]=0; + + //有不包邮区域,且不免运费 + if(no_ex_id && freight_free>0 && freight_free<=allpice){ + //-----------获取不包邮区域,不包邮商品------- + await getApp().request.promiseGet("/api/weshop/areaFeemail/getAreaGoods",{ + data:{store_id:os.stoid,id:no_ex_id} + }).then(res=>{ + if(res.data.code==0){ + //如果有设置不包邮区域的时候 + if(res.data.data[0].region_list){ + if(th.check_by_area(res.data.data[0].region_list)){ + freight_free=0; + th.data.is_no_by[th.data.bn_pick]=1; + } + } + //如果有设置不包邮商品 + if(res.data.data[0].goods_list && freight_free){ + if(th.check_by_goods(res.data.data[0].goods_list)){ + freight_free=0; + th.data.is_no_by[th.data.bn_pick]=1; + } + } + } + }) + } + + th.data.is_by[th.data.bn_pick]=0; + //--------------开始计算物流------------------ var shipping_price= th.calculatewuliu(code, o_shipping_price, goods_weight, goods_piece, th.data.user_addr, freight_free, allpice, rs); + if(shipping_price<=0){ + th.data.is_by[th.data.bn_pick]=1; //已经是包邮了,就不要选择包邮券 + } shipping_price = parseFloat(shipping_price).toFixed(2); var wl_txt = "formData.shipping_price"; th.setData({ [wl_txt]: shipping_price, }) - + }else{ var wl_txt = "formData.shipping_price"; th.setData({ [wl_txt]: 0, }) } - //---如果有选择优惠券的情况下--- var quan_price=0,bn_pick=th.data.bn_pick; - var quan_no=null; if(th.data.using_quan[bn_pick]!=null && th.data.using_quan[bn_pick]!=undefined) quan_no=th.data.using_quan[bn_pick].coupon_no; if(quan_no){ var aa=1; - //---获取优惠券优惠--- - await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice",{ - data:{storeId:oo.stoid,CashRepNo:quan_no, WaresSum:th.data.ckeck_quan_price, WareIds:th.data.check_quan_ware_list} - }).then(res=>{ - if(res.data.code==0){ - quan_price=res.data.data[0].WareCashSum; - } - }) + if(th.data.using_quan[bn_pick].isby==1){ + shipping_price=0; + var wl_txt = "formData.shipping_price"; + th.setData({ [wl_txt]: 0, }) + }else{ + //---获取优惠券优惠--- + await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice",{ + data:{storeId:oo.stoid,CashRepNo:quan_no, WaresSum:th.data.ckeck_quan_price, WareIds:th.data.check_quan_ware_list} + }).then(res=>{ + if(res.data.code==0){ + quan_price=res.data.data[0].WareCashSum; + } + }) + } + } //-----------------支付价,优惠券不减物流----------------- var total_m = (parseFloat(allpice)).toFixed(2); @@ -676,11 +877,9 @@ Page({ var atxt= "formData.total_amount"; th.setData({ [atxt]: total_m, }) - var txt = "formData.user_money"; var txt2 = "formData.order_amount"; var txt3="formData.coupon_price"; - var amoney = parseFloat(th.data.userinfo.user_money - th.data.txmon - th.data.userinfo.frozen_money); //--------------如果使用余额--------------------- if (th.data.bn_use_money == 1) { @@ -755,13 +954,15 @@ Page({ 'exp_type': th.data.bn_exp_type, //配送方式 'order_goods':new Array(), }; - //组装优惠券的钱 if(th.data.formData.coupon_price){ item.coupon_price=th.data.formData.coupon_price; item.coupon_no=th.data.using_quan[th.data.bn_pick].coupon_no; } - + if(th.data.using_quan[th.data.bn_pick] && th.data.using_quan[th.data.bn_pick].coupon_no && th.data.using_quan[th.data.bn_pick].isby){ + item.coupon_no=th.data.using_quan[th.data.bn_pick].coupon_no; + item.coupon_price=0; + } var gg = to.get_b_now(); var goods={ 'goods_id': gg.goods_id, @@ -847,9 +1048,13 @@ Page({ }; //组装优惠券的钱 - if(t_item.coupon_price){ - item.coupon_price=t_item.coupon_price; - item.coupon_no=th.data.using_quan[t_item.pickup_id].coupon_no; + if(t_item.coupon_price) { + item.coupon_price = t_item.coupon_price; + item.coupon_no = th.data.using_quan[t_item.pickup_id].coupon_no; + } + if(t_item.quan_no) { + item.coupon_no = t_item.quan_no; + item.coupon_price = 0; } //-------------让商品添加到商品列表-------------------- @@ -1005,7 +1210,6 @@ Page({ }) }, - //---确认线下门店的数量足不足--- async check_store_num(goods_id,pick,goods_num,func){ var lock=0,pick_no,plist,erpwareid; @@ -1048,7 +1252,6 @@ Page({ } func(isok); }, - useCoupon: function() { if (this.data.order.couponNum <= 0) { @@ -1065,6 +1268,7 @@ Page({ }, enterAddressPage: function() { getApp().globalData.is_cart_old=1; + this.data.isget_by_quan={}; this.data.enterAddressPage = !0, wx.navigateTo({ url: "/pages/user/address_list/address_list" }); @@ -1089,6 +1293,14 @@ Page({ } th.setData({ is_all_zt: iszt }); + + + + if(th.data.using_quan[th.data.bn_pick] && th.data.using_quan[th.data.bn_pick].isby==1){ + th.setData({using_quan:{}}); + } + + } //判断有没有默认的物流地址值 if (def_exp_code != "" && def_exp_code != null && def_exp_code !=undefined) { @@ -1113,9 +1325,18 @@ Page({ th.setData({ bn_exp_type:ty}); //当物流为空的时候。 if (ty == 0 && th.data.wu_arr==null){ + th.data.isget_by_quan={}; return th.get_wuliu(th.calculatePrice2()); } + //--自提就要把包邮券清理掉-- + if(ty==1){ + th.data.isget_by_quan={}; + if(th.data.using_quan[th.data.bn_pick] && th.data.using_quan[th.data.bn_pick].isby==1){ + th.setData({using_quan:{}}); + } + } + //判断有没有默认的物流地址值 if (def_exp_code != "" && def_exp_code != null && def_exp_code !=undefined) { var wu_arr=this.data.wu_arr; @@ -1218,6 +1439,7 @@ Page({ var pickid=e.currentTarget.dataset.pickid; var bn=e.currentTarget.dataset.bn; var cindx=e.currentTarget.dataset.cind; + var get_by_quan_list_cart=th.data.get_by_quan_list_cart[pickid]; if(bn==1){ @@ -1225,13 +1447,25 @@ Page({ }else{ //---多单打开券的时候,就要判断券在其他门店是否有使用--- var quanlist=th.data.cartlist[cindx].quan_list; + var exp_type=th.data.cartlist[cindx].exp_type; + + //对于在其他门店已经选择了的券 要判断是否显示到界面 for(var i in quanlist){ var is_using= th.check_in_sele(quanlist[i].CashRepNo,pickid); if(is_using) quanlist[i].is_using=1; } + + if(get_by_quan_list_cart){ + for(var i in get_by_quan_list_cart){ + var is_using= th.check_in_sele(get_by_quan_list_cart[i].no,pickid); + if(is_using) quanlist[i].is_using=1; + } + th.setData({by_quan_list_cart:get_by_quan_list_cart}); + } + console.log("2222222券的列表", quanlist); - th.setData({open_quan:1,selected_quan_pick:pickid,selected_quan_list:quanlist,disabled:1}); + th.setData({ sele_cart_ind:cindx,sele_exp_type:exp_type,open_quan:1,selected_quan_pick:pickid,selected_quan_list:quanlist,disabled:1}); } }, close_coupon:function (e) { @@ -1262,18 +1496,36 @@ Page({ quanlist[ind].show_red=0; } this.setData({selected_quan_list:quanlist}); + var by_quanlist=this.data.get_by_quan_list; + if(by_quanlist){ + //---所有的券的显示红色选择都清理一遍--- + for(var ind in by_quanlist){ + by_quanlist[ind].show_red=0; + } + this.setData({get_by_quan_list:by_quanlist}); + } + + var by_cart_list=this.data.by_quan_list_cart; + if(by_cart_list){ + //---所有的券的显示红色选择都清理一遍--- + for(var ind in by_cart_list){ + by_cart_list[ind].show_red=0; + } + this.setData({by_quan_list_cart:by_cart_list}); + } + var using_quan=this.data.using_quan; var th=this; //---如果是不使用优惠券--- if(no_use==1){ - console.log("有进来吗券", no_use); + console.log("有进来吗券", no_use); if(using_quan[th.data.selected_quan_pick]){ using_quan[th.data.selected_quan_pick].is_nouse_red=1; } else{ using_quan[th.data.selected_quan_pick] ={is_nouse_red:1}; } - this.setData({ using_quan: using_quan, is_coupon:2222}); + this.setData({ using_quan: using_quan, is_coupon:2222}); return; } @@ -1299,31 +1551,142 @@ Page({ }, + + /*----- 点击选择包邮券 -----*/ + sele_quan_item_by:function(e) { + var no_use=e.currentTarget.dataset.no; + //立即购买的包邮券 + var by_quanlist=this.data.get_by_quan_list; + if(by_quanlist) { + //---所有的券的显示红色选择都清理一遍--- + for (var ind in by_quanlist) { + by_quanlist[ind].show_red = 0; + } + this.setData({get_by_quan_list: by_quanlist}); + } + + //--购物车过来的包邮券-- + var by_cart_list=this.data.by_quan_list_cart; + if(by_cart_list){ + //---所有的券的显示红色选择都清理一遍--- + for(var ind in by_cart_list){ + by_cart_list[ind].show_red=0; + } + this.setData({by_quan_list_cart:by_cart_list}); + } + //普通券 + var quanlist=this.data.selected_quan_list; + if(quanlist){ + //---所有的券的显示红色选择都清理一遍--- + for(var ind in quanlist){ + quanlist[ind].show_red=0; + } + this.setData({selected_quan_list:quanlist}); + } + + var th=this; + var using_quan=this.data.using_quan; + //---如果是不使用优惠券--- + if(no_use==1){ + if(using_quan[th.data.selected_quan_pick]){ + using_quan[th.data.selected_quan_pick].is_nouse_red=1; + } + else{ + using_quan[th.data.selected_quan_pick] ={is_nouse_red:1}; + } + this.setData({ using_quan: using_quan, is_coupon:2222}); + return; + } + + var ind = e.currentTarget.dataset.ind; + //--如果是立即购买的部分-- + var txt="";var txt1=""; var quan_item=null; + if(th.data.is_b_now){ + quan_item = this.data.get_by_quan_list[ind]; + txt = "get_by_quan_list[" + ind + "].show_red"; + }else{ + txt = "by_quan_list_cart[" + ind + "].show_red"; + quan_item = th.data.by_quan_list_cart[ind] + + } + var obj = {}; obj[txt] = 1; + if (quan_item.show_red) { + obj[txt] = 0; + } + + //购物车购买过来的商品 + if(txt1){ + obj[txt1] = 1; + if (quan_item.show_red) { + obj[txt1] = 0; + } + } + + this.setData(obj); + if(using_quan[th.data.selected_quan_pick]){ + using_quan[th.data.selected_quan_pick].is_nouse_red=0; + } + else{ + using_quan[th.data.selected_quan_pick] ={is_nouse_red:0}; + } + this.setData({using_quan:using_quan}); + }, + //--确认使用券--- confirm_quan:function () { - - var using_quan=this.data.using_quan,pickid=this.data.selected_quan_pick; - var th=this,selected_quan_list=this.data.selected_quan_list; + var using_quan=this.data.using_quan + var pickid=this.data.selected_quan_pick; + var th=this; + var selected_quan_list=this.data.selected_quan_list; + var get_by_quan_list=this.data.get_by_quan_list; + var by_quan_list_cart=this.data.by_quan_list_cart; //选择了的券 var sele_quan=null; - console.log(selected_quan_list, "确认使用券"); + + //循环普通的券 for(var i in selected_quan_list){ - var item=selected_quan_list[i]; - console.log(item, "确认使用券",item.show_red); if(item.show_red) { - console.log(item.show_red, "确定的券7"); th.insert_into_using_quan(item,using_quan,pickid); return; } } + //循环包邮的券,立即购买的 + for(var i in get_by_quan_list){ + var item=get_by_quan_list[i]; + if(item.show_red) { + if(th.data.is_no_by[pickid]==1){ + getApp().my_warnning("已全场不能包邮,不能选择包邮券",0,th);return false; + } + if(th.data.is_by[pickid]==1){ + getApp().my_warnning("已全场包邮,不能选择包邮券",0,th);return false; + } - //选择了的券,看是不是点击了不使用券 + th.insert_into_using_quan(item,using_quan,pickid,1); + return; + } + } + + //循环包邮的券 + for(var i in by_quan_list_cart){ + var item=by_quan_list_cart[i]; + if(item.show_red) { + if(th.data.is_no_by[pickid]==1){ + getApp().my_warnning("已全场不能包邮,不能选择包邮券",0,th);return false; + } + if(th.data.is_by[pickid]==1){ + getApp().my_warnning("已全场包邮,不能选择包邮券",0,th);return false; + } + th.insert_into_using_quan(item,using_quan,pickid,1); + return; + } + } + + //选择了的券,看是不是点击了不使用券,点击了不使用优惠券 if(using_quan[pickid]){ if(using_quan[pickid].is_nouse_red==1){ using_quan[pickid] ={is_nouse_red:1}; th.setData({using_quan:using_quan}); - if(th.data.is_b_now==1){ th.calculatePrice2(); }else{ @@ -1336,11 +1699,16 @@ Page({ }, //----把券插入之后的操作,同时还要重新计算价格---- - insert_into_using_quan:function (item,using_quan,pickid) { + insert_into_using_quan:function (item,using_quan,pickid,isby) { var th=this; - using_quan[pickid]={coupon_no:item.CashRepNo,money:item.Sum,is_nouse_red:0}; + if(isby==1){ + using_quan[pickid]={coupon_no:item.no,money:0,is_nouse_red:0,region_list:item.region_list,goods_list:item.goods_list}; + using_quan[pickid].isby=1; + }else{ + using_quan[pickid]={coupon_no:item.CashRepNo,money:item.Sum,is_nouse_red:0}; + using_quan[pickid].isby=0; + } this.setData({using_quan:using_quan}); - if(th.data.is_b_now==1){ th.calculatePrice2(); }else{ @@ -1355,9 +1723,8 @@ Page({ ob[txt] = this.data.imgUrl + "/miniapp/images/default_g_img.gif"; this.setData(ob); }, - //--验证是否已经冻结-- - check_is_frozenQuan:function(quanlist,frozenQuan){ + check_is_frozenQuan:function(quanlist,frozenQuan,isby){ console.log("券列表",quanlist); if(!quanlist) return null; if(!frozenQuan) return quanlist; @@ -1366,6 +1733,7 @@ Page({ var item=quanlist[i]; var is_find=0; var Q_no=quanlist[i].CashRepNo; + if(isby) Q_no=quanlist[i].no; for(var j=0;j{ - if(res.data.code==0){ frozenQuan=res.data.data; } + if(res.data.code==0){ frozenQuan=res.data.data; th.data.frozenQuan=frozenQuan; } //--调用接口,获取优惠券的列表,3秒钟内控制接口请求-- var url="/api/weshop/couponList/getUseCouponList"; app.request.time_limit_get(6,url,{ @@ -1552,7 +1929,7 @@ Page({ var url="/api/weshop/couponList/getUseCouponList"; app.request.promiseGet(url0, {1: 1}).then(res => { if (res.data.code == 0) { - frozenQuan = res.data.data; + frozenQuan = res.data.data;th.data.frozenQuan=frozenQuan; } app.request.time_limit_get(6, url, { data: { @@ -1571,10 +1948,43 @@ Page({ } } } - }) }) } + }, + //检查区域是不是包邮 + check_area:function(arr){ + var user_addr=this.data.user_addr; + for(var i in arr){ + var item=arr[i]; + if(user_addr.twon==item || user_addr.district==item + || user_addr.city==item|| user_addr.province==item ){ + return 0; + } + } + return 1; + }, + + //检查立即购买的商品是不是不包邮 + check_good:function(arr,goods_id){ + if(!goods_id) goods_id=this.data.bn_goods.goods_id; + for(var i in arr){ + var item=arr[i]; + if(goods_id==item) return 0; + } + return 1; + }, + check_by_area:function(region_list){ + var arr=region_list.split(","); + var check=this.check_area(arr); + return !check; + }, + check_by_goods:function(goods_list,goods_id){ + var arr=goods_list.split(","); + var check=this.check_good(arr,goods_id); + return !check; } + + }); diff --git a/pages/cart/cart2/cart2.wxml b/pages/cart/cart2/cart2.wxml index c8dba07..844c990 100644 --- a/pages/cart/cart2/cart2.wxml +++ b/pages/cart/cart2/cart2.wxml @@ -78,6 +78,7 @@ 不使用 ¥{{using_quan[item.pickup_id].money}}元优惠券 + 包邮券 @@ -91,7 +92,7 @@ - + @@ -103,10 +104,10 @@ - 门店自提 + 门店自提 - + @@ -116,7 +117,7 @@ - 快递邮寄 @@ -203,7 +204,10 @@ 不使用 - ¥{{using_quan[bn_pick].money}}元优惠券 + + ¥{{using_quan[bn_pick].money}}元优惠券 + 包邮券 + @@ -284,153 +288,143 @@ - - + + - - - 优惠券使用 - - - - × - + 优惠券使用 + × - - - 可使用的优惠券 - - 不使用优惠券 - - - Γ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + 可使用的优惠券 + 不使用优惠券 + Γ + + + + + + + + + + + + + + + {{item.Sum}} + 满{{item.BuySum}}元可用 + 满0元可用 + + + + + + + + + {{filter.get_type_card(item.UseObjectType)}} + {{item.Sum}}元优惠券 + + {{filters.replace_time2(item.BeginDate)}}至{{item.ValidDate?filters.replace_time2(item.ValidDate):'不限'}} + + + Γ + + + + + + + + + + + + + + + + + + + + 包邮券 + 满{{item.condition}}元可用 + 满0元可用 + + + + + + + + + {{filter.get_type_card(0)}} + 包邮券 + + {{filters.format_time(item.use_start_time)}}至{{item.use_end_time?filters.format_time(item.use_end_time):'不限'}} + + + Γ + + + + + + + + + + - - - - - - - {{item.Sum}} - - - - - - 满{{item.BuySum}}元可用 - - - 满0元可用 - - - - - - - - - - - - - {{filter.get_type_card(item.UseObjectType)}} - - {{item.Sum}}元优惠券 - - - {{filters.replace_time2(item.BeginDate)}}至{{item.ValidDate?filters.replace_time2(item.ValidDate):'不限'}} - - - - - - Γ - - - + + + + + + + + + + + 包邮券 + 满{{item.condition}}元可用 + 满0元可用 + + + + + + + + + {{filter.get_type_card(0)}} + 包邮券 + + {{filters.format_time(item.use_start_time)}}至{{item.use_end_time?filters.format_time(item.use_end_time):'不限'}} + + + Γ + + + + + + + + + - - - - - - 优惠券使用说明 - - - - - - - - - - - {{util.format(item.Remark)}} - - 仅{{item.UseObjectName}}使用 - 全场通用 - - + + + + 确定 - - - - - - - - - - - 确定 - - - diff --git a/pages/cart/cart2/juchi_part.wxml b/pages/cart/cart2/juchi_part.wxml new file mode 100644 index 0000000..8dcad6b --- /dev/null +++ b/pages/cart/cart2/juchi_part.wxml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pages/cart/cart2/remark_click_part.wxml b/pages/cart/cart2/remark_click_part.wxml new file mode 100644 index 0000000..dc2dd78 --- /dev/null +++ b/pages/cart/cart2/remark_click_part.wxml @@ -0,0 +1,4 @@ + + + 优惠券使用说明 + \ No newline at end of file diff --git a/pages/cart/cart2/remark_click_part2.wxml b/pages/cart/cart2/remark_click_part2.wxml new file mode 100644 index 0000000..eabab2e --- /dev/null +++ b/pages/cart/cart2/remark_click_part2.wxml @@ -0,0 +1,4 @@ + + + 优惠券使用说明 + \ No newline at end of file diff --git a/pages/cart/cart2/remark_part.wxml b/pages/cart/cart2/remark_part.wxml new file mode 100644 index 0000000..a818031 --- /dev/null +++ b/pages/cart/cart2/remark_part.wxml @@ -0,0 +1,9 @@ + + + {{util.format(item.Remark)}} + + 仅{{item.UseObjectName}}使用 + 全场通用 + + + \ No newline at end of file diff --git a/pages/user/order_list/order_list.js b/pages/user/order_list/order_list.js index 25ed2f6..63f0b68 100644 --- a/pages/user/order_list/order_list.js +++ b/pages/user/order_list/order_list.js @@ -56,10 +56,10 @@ Page({ th.setData({conf: e }); //--- 看后台是不是有开通等级卡 --- if(e.switch_list){ - var s_list=JSON.parse(e.switch_list); - //如果后台有开启等级价的功能 - if(parseInt(s_list.rank_switch)==2){ - var user=getApp().globalData.userInfo; + var s_list=JSON.parse(e.switch_list); + var user=getApp().globalData.userInfo; + //如果后台有开启等级价的功能 + if(parseInt(s_list.rank_switch)==2 && user['card_expiredate']){ var str = user['card_expiredate'].replace(/-/g, '/'); var end = new Date(str); end = Date.parse(end) / 1000; diff --git a/utils/util.js b/utils/util.js index 9d8771e..d946b24 100644 --- a/utils/util.js +++ b/utils/util.js @@ -343,11 +343,36 @@ function draw_circle(ctx,x,y,r,img,color,unit){ ctx.restore(); } - function null_promise(){ var promise=new Promise(function(resolve, reject){ var ob={code:-1,data:null}; resolve(ob); }); return promise; } +//---合并数组去掉重复项--- +function mergeArray(arr1, arr2){ + for (var i = 0 ; i < arr1.length ; i ++ ){ + for(var j = 0 ; j < arr2.length ; j ++ ){ + if (arr1[i] === arr2[j]){ + arr1.splice(i,1); //利用splice函数删除元素,从第i个位置,截取长度为1的元素 + } + } + } + //alert(arr1.length) + for(var i = 0; i