diff --git a/packageE/pages/cart/cart_wk/cart_wk.js b/packageE/pages/cart/cart_wk/cart_wk.js index 5db1d14..e3a9b59 100644 --- a/packageE/pages/cart/cart_wk/cart_wk.js +++ b/packageE/pages/cart/cart_wk/cart_wk.js @@ -68,7 +68,11 @@ Page({ isget_by_quan: {}, //是否调用了接口获取包邮券 is_by:{}, get_by_quan_list: null, //立即购买的 - + first_entry: 0,//进入次数,如果是第一次进入,进行判断是否进行优惠券是否直接使用 + def_coupon1: null,//购物车优惠券列表 + def_coupon2: null,//直接购买优惠券列表 + def_coupon3: null,//购物车包邮券列表 + def_coupon4: null,//直接购买包邮券列表 }, /** @@ -616,6 +620,7 @@ Page({ allpice = allpice.toFixed(2); th.setData({exp_price: 0, allpice: allpice, submit: 0, show_submit: 1}) + th.def_coupon_fn() wx.hideLoading(); } }, @@ -643,7 +648,7 @@ Page({ set_wuliu: function (e) { var type = e.currentTarget.dataset.type, th = this; this.setData({ - exp_type: type,same_ok:1 + exp_type: type,same_ok:1,first_entry:0 }); //--计算物流的值-- if (th.data.goods) { @@ -916,7 +921,7 @@ Page({ arr.push(item); } if (arr) { - th.setData({ get_by_quan_list: arr }); + th.setData({ get_by_quan_list: arr,def_coupon3: arr }); } th.data.isget_by_quan[th.data.bn_pick] = 1; } @@ -1182,7 +1187,7 @@ Page({ allpice = allpice.toFixed(2); th.setData({exp_price: 0, allpice: allpice, submit: 0, show_submit: 1}) } - + th.def_coupon_fn() wx.hideLoading(); //}); @@ -1350,7 +1355,7 @@ Page({ allpice = allpice.toFixed(2); th.setData({ exp_price: 0, allpice: allpice,submit:0,show_submit:1}) } - + th.def_coupon_fn() wx.hideLoading(); @@ -1537,7 +1542,7 @@ Page({ quanlist = res.data.data.pageData; if (quanlist) { quanlist = th.check_is_frozenQuan(quanlist, frozenQuan); - th.setData({ selected_quan_list: quanlist }) + th.setData({ selected_quan_list: quanlist,def_coupon2: quanlist }) } } } @@ -1624,6 +1629,111 @@ Page({ th.setData({ open_quan: 0, disabled: 0 }); }, + /*--点击选择券--*/ + sele_quan_item_befor: function (e) { + + var ind = 0; + var quan_item = this.data.selected_quan_list[ind]; + var pickid = this.data.selected_quan_pick; //现在选择的是哪一个门店 + //--如果券是单品使用的时候-- + if (quan_item && quan_item.UseObjectType && quan_item.UseObjectType == "20") { + //---只有多件购买的时候才要计算,//购物车购买和搭配勾的时候--- + var gg = getApp().get_b_now(); + if (this.data.is_b_now == 0 || gg.prom_type == 5) { + var arr = this.data.order_prom_list_cart; + var t_pk_item = null; + for (var ii in arr) { + var ep = arr[ii]; + if (pickid == ep.pickup_id) { + t_pk_item = ep; + break; + } + } + //--寻找券指定的商品-- + var gd = null; + if (t_pk_item) { + var goods = t_pk_item.goods; + for (var gid in goods) { + if (quan_item.UseObjectID == goods[gid].erpwareid) { + gd = goods[gid]; + } + } + } + if (!gd) { + // getApp().my_warnning("未找到指定商品使用", 0, this, 600); + return false; + } + //计算价格,如果有平摊的实收要计算实收的金额 + var item_price = gd.goods_price * gd.goods_num; + //-- 如果有平摊下去,有实收价格的时候,就要用account_fir来计算价格 -- + if (gd.account_fir != null && gd.account_fir != undefined) { + item_price = gd.account_fir * gd.goods_num; + } + + if (item_price < parseFloat(quan_item.BuySum)) { + // getApp().my_warnning("该单品金额没有大于等于" + quan_item.BuySum + "元时不能使用优惠券", 0, this, 600); + return false; + } + } + } + + var quanlist = this.data.selected_quan_list; + //---所有的券的显示红色选择都清理一遍--- + for (var i in quanlist) { + quanlist[i].show_red = 0; + } + this.setData({ selected_quan_list: quanlist }); + var by_quanlist = this.data.get_by_quan_list; + if (by_quanlist) { + //---所有的券的显示红色选择都清理一遍--- + for (var inb in by_quanlist) { + by_quanlist[inb].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 inc in by_cart_list) { + by_cart_list[inc].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); + // 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: th.is_coupon }); + // return; + // } + + + var txt = "selected_quan_list[" + ind + "].show_red"; + var obj = {}; + obj[txt] = 1; + if (quan_item.show_red) { + obj[txt] = 0; + } + this.setData(obj); + console.log(this.data.selected_quan_list, "选中的券的下标", quan_item, "数据都在这里", txt); + 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 }); + return true + }, /*--点击选择券--*/ sele_quan_item: function (e) { @@ -1731,6 +1841,66 @@ Page({ }, /*----- 点击选择包邮券 -----*/ + sele_quan_item_by_befor: 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 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: th.is_coupon }); + // return; + // } + + var pickid = th.data.selected_quan_pick; //现在选择的是哪一个门店 + var ind = 0; + //--如果是立即购买的部分-- + var txt = ""; + var txt1 = ""; + var quan_item = null; + + quan_item = this.data.get_by_quan_list[ind]; + txt = "get_by_quan_list[" + ind + "].show_red"; + var obj = {}; + obj[txt] = 1; + 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 }); + }, + + /*----- 点击选择包邮券 -----*/ sele_quan_item_by: function (e) { var no_use = e.currentTarget.dataset.no; //立即购买的包邮券 @@ -1791,6 +1961,71 @@ Page({ }, //--确认使用券--- + confirm_quan_befor: function () { + var using_quan = this.data.using_quan; //正在使用中的券列表 + var pickid = this.data.selected_quan_pick; //选中的门店ID + 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; + + //循环普通的券 + for (var i in selected_quan_list) { + var item = selected_quan_list[i]; + if (item.show_red) { + th.insert_into_using_quan(item, using_quan, pickid,0,false); + 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,false); + 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,false); + 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 }); + th.calculatePrice2(); + th.setData({ open_quan: 0 }); + return; + } + } + }, + //--确认使用券--- confirm_quan: function () { var using_quan = this.data.using_quan; //正在使用中的券列表 var pickid = this.data.selected_quan_pick; //选中的门店ID @@ -1855,9 +2090,99 @@ Page({ } } }, + //默认选择优惠券 + def_coupon_fn() { + // setTimeout(() => { + // this.def_coupon_fn_aft() + // }, 100); + try { + setTimeout(() => { + this.def_coupon_fn_aft() + }, 1000); + } catch (error) { } + +}, + //默认选择优惠券 + def_coupon_fn_aft() { + console.error('进入默认优惠券选择'); + let th = this; + let first_entry = th.data.first_entry; + console.error(first_entry); + if (first_entry > 0) { + return + } + first_entry += 1; + th.setData({ + first_entry + }) + let length1 = th.data.def_coupon1 ? th.data.def_coupon1.length : 0 + let length2 = th.data.def_coupon2 ? th.data.def_coupon2.length : 0 + let length3 = th.data.def_coupon3 ? th.data.def_coupon3.length : 0 + let length4 = th.data.def_coupon4 ? th.data.def_coupon4.length : 0 + let length = length1 + length2 + if (th.data.exp_type==0) { + length+= length3 + length4 + } + console.error(length); + if (length != 1) { + return + } + if (length1 == 1) { + console.error('优惠券1'); + let first_entry = th.data.first_entry; + let quan_list = th.data.def_coupon1 + if (quan_list && quan_list.length == 1 && first_entry == 1) { + // first_entry += 1; + th.setData({ + sele_cart_ind: 0, + sele_exp_type: th.data.cartlist[0].exp_type, + selected_quan_pick: th.data.cartlist[0].pickup_id, + selected_quan_list: th.data.cartlist[0].quan_list, + // first_entry + }) + let quan_off = th.sele_quan_item_befor(); + if (quan_off) { + th.confirm_quan_befor() + } + } + } + if (length2 == 1) { + console.error('优惠券2'); + let first_entry = th.data.first_entry; + let quanlist = th.data.def_coupon2 + if (quanlist && quanlist.length == 1 && first_entry == 1) { + // first_entry += 1; + th.setData({ + selected_quan_pick: th.data.bn_pick, + // first_entry + }) + let quan_off = th.sele_quan_item_befor(); + if (quan_off) { + th.confirm_quan_befor() + } + } + } + if (length3 == 1 && th.data.exp_type == 0) { + console.error('优惠券3'); + let first_entry = th.data.first_entry; + let quanlist = th.data.def_coupon3 + if (quanlist && quanlist.length == 1 && first_entry == 1) { + // first_entry += 1; + th.setData({ + selected_quan_pick: th.data.bn_pick, + // first_entry + }) + + th.sele_quan_item_by_befor(); + th.confirm_quan_befor() + + } + } + + }, //----把券插入之后的操作,同时还要重新计算价格---- - insert_into_using_quan: async function (item, using_quan, pickid, isby) { + insert_into_using_quan: async function (item, using_quan, pickid, isby, showToast = true) { var th = this; @@ -1880,14 +2205,14 @@ Page({ th.calculatePrice2(function () { - if (old_quan) using_quan[pickid] = old_quan; - else using_quan[pickid] = null; - th.setData({ using_quan: using_quan, submit: 0 }); - wx.showToast({ - title: "不能使用优惠券,同城起送价不足", - icon: 'none', - duration: 2000 - }) + // if (old_quan) using_quan[pickid] = old_quan; + // else using_quan[pickid] = null; + // th.setData({ using_quan: using_quan, submit: 0 }); + // wx.showToast({ + // title: "不能使用优惠券,同城起送价不足", + // icon: 'none', + // duration: 2000 + // }) });