diff --git a/packageE/pages/cart/cart2_pt/cart2_pt.js b/packageE/pages/cart/cart2_pt/cart2_pt.js index bd364bf..fc6f308 100644 --- a/packageE/pages/cart/cart2_pt/cart2_pt.js +++ b/packageE/pages/cart/cart2_pt/cart2_pt.js @@ -77,6 +77,19 @@ Page({ bconfig:null, showFold:true, template_id:[], + + //--更优惠券抵用有关,立即购买的,如果是购物车,就要把相应的值,写入cartlist数组中-- + ckeck_quan_price: 0, + check_quan_price_list: '', + check_quan_ware_list: '', + + // 设计一个数组来存放已经选择了的券编号,coupon_no是券号,money是面值,coupon_price是真正优惠的价格,数组的下标是pickid + //using_quan[11]={coupon_no:"1212121",money:"20",coupon_price:"45"} + using_quan: {}, + //如果是全场包邮了,或者是全场不包邮了,就不要选包邮券 + is_no_by: {}, + is_by: {}, + is_quan_by: {}, }, @@ -483,6 +496,10 @@ Page({ } else { + 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 + ""; + gd.prom_id=gg.prom_id; //--阶梯团很特殊,不能用总表来拿价格-- getApp().request.get("/api/weshop/teamlist/get/" + oo.stoid + "/" + gd.prom_id, { @@ -510,6 +527,15 @@ Page({ t.data.data.commission = tt.data.data.commission; + if (!tt.data.data.is_quan || pt_data.kttype == 3) { + + th.data.ckeck_quan_price = 0; + th.data.check_quan_price_list = ""; + th.data.check_quan_ware_list = ""; + gd.is_xz_yh = 1; + } + + if (pt_data.kttype == 3) { t.data.data.shop_price = tt.data.data.yf_price; //用定金来购买 @@ -566,14 +592,15 @@ Page({ } - th.setData({ - bn_goods: t.data.data, bn_pickname: gg.pick_name, - bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et - }); + th.setData({ + bn_goods: t.data.data, bn_pickname: gg.pick_name, + bn_pick: gg.pick_id, bn_t_exp_t: distr_t, bn_exp_type: et + }); - //计算价格 - th.calculatePrice2(); + //计算价格 + th.calculatePrice2(); + th.get_buy_now_quan(); } }); } @@ -631,11 +658,13 @@ Page({ this.getuser_addr(function (ie) { //更换地址回来要重新调用计算价钱的接口 - if (!th.data.user_addr || th.data.user_addr.address_id != ie.address_id) { + if (!th.data.user_addr || !ie || th.data.user_addr.address_id != ie.address_id) { th.setData({ add_back: 1,same_ok:1 }); //if (th.data.bn_goods) th.calculatePrice2(); } th.setData({ user_addr: ie,show_btn:0 }); + + th.data.isget_by_quan = {}; }) //--更新默认地址--,看一下是不是跳到地址页面 if (!getApp().globalData.is_cart_old) { @@ -764,9 +793,45 @@ Page({ var o_shipping_price = 0, goods_weight = -1, goods_piece = -1; var out_of_weight = null; //超出多少重量 + + + + //---如果有选择优惠券的情况下--- + 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) { + //如果是一件代发就不要找商品 + if (th.data.using_quan[bn_pick].isby != 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 && res.data.data && res.data.data.length > 0) { + quan_price = res.data.data[0].WareCashSum; + + allpice=allpice-quan_price; + + } + }) + } + } + //-- 判断订单优惠的叠加 -- var ord_prom=null; var o_condition=allpice; + var pickid = th.data.bn_pick; + + + if(th.data.bn_is_order_yh && th.data.kt_type != 3 ){ await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", { @@ -781,6 +846,40 @@ Page({ //-----------当地址不为空,且是物流时,计算物流费用,同时阶梯团不计算拼团价格---------- if (th.data.user_addr != null && th.data.bn_exp_type == 0 && (th.data.kt_type != 3 || th.data.bn_goods.is_normal == 1)) { + //看是不是有调用过包邮券 + if (!th.data.isget_by_quan[th.data.bn_pick] && good.is_xz_yh != 1) { + + //--判断要不要显示包邮券,链式调用接口,调取包邮券,已经是减了优惠的金额,见到优惠券的钱--- + getApp().request.promiseGet("/api/weshop/userfeemail/pageAndArea", { + data: { + store_id: os.stoid, + isuse: 0, + condition: o_condition, + user_id: getApp().globalData.user_id, + pageSize: 2000 + } + }).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) { + var no_goods_arr = item.goods_list.split(","); + if (ut.isContained(no_goods_arr, gd_arr_list)) continue; //如果是不包邮商品 + } + arr.push(item); + } + if (arr) { + th.setData({ get_by_quan_list: arr }); + } + th.data.isget_by_quan[th.data.bn_pick] = 1; + } + }) + } + if(good.is_free_shipping){ var wl_txt = "formData.shipping_price"; th.setData({ [wl_txt]: 0 }) @@ -791,6 +890,7 @@ Page({ wuliu: parseFloat(allpice).toFixed(2), store_id: os.stoid } var back_data = null; + var quan_no_goods_arr=null; if(!ord_prom || ord_prom.is_post_temp) { if (th.data.bn_is_post_temp || th.data.bn_goods.is_normal == 1) { @@ -802,108 +902,142 @@ Page({ } } - var gd_arr_list = []; - gd_arr_list.push(good); - var cut_good_weight = 0; - for (let i in gd_arr_list) { - let item = gd_arr_list[i]; - - if (back_data && back_data['is_by_all'] && (!back_data.no_free_goods || back_data.no_free_goods.indexOf(item.goods_id) == -1)) { + var is_by_quan = 0; + //如果是包邮券的时候,要看看券的情况,判断一下包邮有没有不包邮模板 + if (quan_no && th.data.using_quan[pickid].isby == 1) { + var quan = th.data.using_quan[pickid]; + if (quan.goods_list) { + quan_no_goods_arr = quan.goods_list.split(","); + } else { + is_by_quan = 1; + } + } - if (item['exp_sum_type'] == 2 && back_data.weight_free > 0) { - if (goods_weight < 0) goods_weight = 0; - cut_good_weight += item['weight'] * item['buynum']; - goods_weight += item['weight'] * item['buynum']; - } - if (back_data.weight_free > 0) { - out_of_weight = (back_data.weight_free * 1000) - cut_good_weight; - } - continue; + //如果有包邮券的不包邮商品的时候 + if (quan_no_goods_arr) { + if (back_data && back_data.no_free_goods) { + back_data['is_by_all'] = 1; + var arr3 = back_data.no_free_goods.filter(item => { + return quan_no_goods_arr.includes(item) + }) + back_data.no_free_goods = null; + if (arr3.length) { + back_data.no_free_goods = arr3; } + } + if (!back_data || !back_data.no_free_goods) { + if (!back_data) back_data = {}; + back_data['is_by_all'] = 1; + back_data['no_free_goods'] = quan_no_goods_arr; + } + } + + + if(!is_by_quan){ + var gd_arr_list = []; + gd_arr_list.push(good); + var cut_good_weight = 0; + for (let i in gd_arr_list) { + let item = gd_arr_list[i]; - switch (item['exp_sum_type']) { - case 1: - //统一运费 - o_shipping_price += item['uniform_exp_sum']; - break; - case 2: - if (goods_weight < 0) goods_weight = 0; - //累积商品重量 每种商品的重量 * 数量 - goods_weight += item['weight'] * item['buynum']; - - if (back_data && back_data.is_by_all && !back_data.no_free_goods) { + if (back_data && back_data['is_by_all'] && (!back_data.no_free_goods || back_data.no_free_goods.indexOf(item.goods_id) == -1)) { + + if (item['exp_sum_type'] == 2 && back_data.weight_free > 0) { + if (goods_weight < 0) goods_weight = 0; cut_good_weight += item['weight'] * item['buynum']; - if (back_data.weight_free > 0) { - out_of_weight = (back_data.weight_free * 1000) - cut_good_weight; - } + goods_weight += item['weight'] * item['buynum']; } - break; - case 3: - if (goods_piece < 0) goods_piece = 0; - //累积商品数量 - goods_piece += item['buynum']; - break; - } - } + if (back_data.weight_free > 0) { + out_of_weight = (back_data.weight_free * 1000) - cut_good_weight; + } + continue; + } - //如果是正值的时候 - if (out_of_weight >= 0) out_of_weight = -cut_good_weight; - else out_of_weight = -back_data.weight_free * 1000; + switch (item['exp_sum_type']) { + case 1: + //统一运费 + o_shipping_price += item['uniform_exp_sum']; + break; + case 2: + if (goods_weight < 0) goods_weight = 0; + //累积商品重量 每种商品的重量 * 数量 + goods_weight += item['weight'] * item['buynum']; + + if (back_data && back_data.is_by_all && !back_data.no_free_goods) { + cut_good_weight += item['weight'] * item['buynum']; + if (back_data.weight_free > 0) { + out_of_weight = (back_data.weight_free * 1000) - cut_good_weight; + } + } + break; + case 3: + if (goods_piece < 0) goods_piece = 0; + //累积商品数量 + goods_piece += item['buynum']; + break; + } + } + //如果是正值的时候 + if (out_of_weight >= 0) out_of_weight = -cut_good_weight; + else out_of_weight = -back_data.weight_free * 1000; - if(!th.data.wu_arr){ - wx.hideLoading(); - wx.showToast({ - title: "物流配置未启用物流公司", icon: 'none', duration: 2000 - }) - //th.setData({ show_submit:0, }); - th.setData({show_submit:1, submit: 0,same_ok:0 }) - return false; - } - var code = th.data.wu_arr[th.data.index].code; - - //--------------开始计算物流------------------ - var shipping_price = 0; - // var shipping_price = ut.calculatewuliu(code, o_shipping_price, goods_weight, out_of_weight, - // goods_piece, th.data.user_addr, back_data, rs); - - var w_data = { - store_id: os.stoid, code: code, - o_shipping_price: o_shipping_price, - goods_weight: goods_weight, - out_of_weight: out_of_weight, goods_piece: goods_piece, - user_addr_province: th.data.user_addr.province, - user_addr_city: th.data.user_addr.city, - user_addr_district: th.data.user_addr.district, - is_by_all: back_data && back_data.is_by_all ? 1 : 0, - no_free_goods: back_data && back_data.no_free_goods && back_data.no_free_goods.length > 0 ? 1 : 0, - } + if(!th.data.wu_arr){ + wx.hideLoading(); + wx.showToast({ + title: "物流配置未启用物流公司", icon: 'none', duration: 2000 + }) + //th.setData({ show_submit:0, }); + th.setData({show_submit:1, submit: 0,same_ok:0 }) + return false; + } - var is_ok = 0; - await getApp().request.promisePost('/api/weshop/order/getOrderWuLiPrice', { - data: w_data, - is_json: 1 - }).then(res => { - if (res.data.code == 0) { - shipping_price = res.data.data; - is_ok = 1; + var code = th.data.wu_arr[th.data.index].code; + + //--------------开始计算物流------------------ + var shipping_price = 0; + // var shipping_price = ut.calculatewuliu(code, o_shipping_price, goods_weight, out_of_weight, + // goods_piece, th.data.user_addr, back_data, rs); + + var w_data = { + store_id: os.stoid, code: code, + o_shipping_price: o_shipping_price, + goods_weight: goods_weight, + out_of_weight: out_of_weight, goods_piece: goods_piece, + user_addr_province: th.data.user_addr.province, + user_addr_city: th.data.user_addr.city, + user_addr_district: th.data.user_addr.district, + is_by_all: back_data && back_data.is_by_all ? 1 : 0, + no_free_goods: back_data && back_data.no_free_goods && back_data.no_free_goods.length > 0 ? 1 : 0, } - }) - if (!is_ok) { - wx.hideLoading(); - wx.showToast({ - title: "计算物流错误", icon: 'none', duration: 2000 + + var is_ok = 0; + await getApp().request.promisePost('/api/weshop/order/getOrderWuLiPrice', { + data: w_data, + is_json: 1 + }).then(res => { + if (res.data.code == 0) { + shipping_price = res.data.data; + is_ok = 1; + } }) - //th.setData({ show_submit:0 }); - th.setData({show_submit:1, submit: 0,same_ok:0 }) + if (!is_ok) { + wx.hideLoading(); + wx.showToast({ + title: "计算物流错误", icon: 'none', duration: 2000 + }) + //th.setData({ show_submit:0 }); + th.setData({show_submit:1, submit: 0,same_ok:0 }) + + return false; + } - return false; - } + shipping_price = parseFloat(shipping_price).toFixed(2); + var wl_txt = "formData.shipping_price"; + th.setData({ [wl_txt]: shipping_price, }) - shipping_price = parseFloat(shipping_price).toFixed(2); - var wl_txt = "formData.shipping_price"; - th.setData({ [wl_txt]: shipping_price, }) + } } } else if (th.data.bn_exp_type == 1) { var wl_txt = "formData.shipping_price"; @@ -1140,6 +1274,9 @@ Page({ } + + var txt3 = "formData.coupon_price"; + if (th.data.bn_use_commission) { order_m = (parseFloat(order_m) - parseFloat(th.data.bn_goods.use_commission)).toFixed(2); th.setData({ [txt4]: th.data.bn_goods.use_commission }) @@ -1148,14 +1285,14 @@ Page({ //--------------如果使用余额--------------------- if (th.data.bn_use_money == 1 && th.data.yuer > 0) { if (parseFloat(th.data.yuer) > parseFloat(order_m)) { - th.setData({ [txt]: order_m, [txt2]: 0, submit: 0, show_btn: 1 }) + th.setData({ [txt]: order_m, [txt2]: 0, [txt3]:quan_price,submit: 0, show_btn: 1 }) } else { order_m = parseFloat(order_m) - parseFloat(th.data.yuer); order_m = order_m.toFixed(2); - th.setData({ [txt]: th.data.yuer, [txt2]: order_m, submit: 0, show_btn: 1 }) + th.setData({ [txt]: th.data.yuer, [txt2]: order_m,[txt3]:quan_price, submit: 0, show_btn: 1 }) } } else { - th.setData({ [txt]: 0, [txt2]: order_m, submit: 0, show_btn: 1 }) + th.setData({ [txt]: 0, [txt2]: order_m,[txt3]:quan_price, submit: 0, show_btn: 1 }) } wx.hideLoading(); @@ -1268,6 +1405,17 @@ Page({ item['shipping_name'] = th.data.bn_exp_type == 1 ? '' : th.data.wu_arr[th.data.index].name; } + + //组装优惠券的钱 + if (parseFloat(th.data.formData.coupon_price) > 0) { + 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; + } + if (!th.data.bn_goods.is_normal) { item.is_zsorder = th.data.kt_type + 1; //开团类型 } @@ -1681,5 +1829,428 @@ Page({ buycard: function () { getApp().goto("/pages/user/plus/plus"); getApp().globalData.plus_buy_back = 1; - } + }, + + //------ 获取立即购买的购物车的劵 -------- + get_buy_now_quan: function () { + var quanlist = null, th = this, frozenQuan = null; + var good = this.data.bn_goods; + + //一件代发商品不使用优惠券 + if (good.whsle_id) return false; + if(!th.data.check_quan_ware_list) return false; + + //--如果商家后台没有限制使用优惠券,同时商品的优惠活动没有限制使用优惠券-- + if (th.data.is_close_quan != 1 && th.data.bn_goods.is_xz_yh != 1 && th.data.check_quan_ware_list) { + 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; + th.data.frozenQuan = frozenQuan; + } + app.request.time_limit_get(6, url, { + data: { + storeId: oo.stoid, + userId: app.globalData.user_id, + BuySum: th.data.ckeck_quan_price, + WareIds: encodeURIComponent(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 }) + } + } + } + }) + }) + } + }, + + //--验证是否已经冻结-- + check_is_frozenQuan: function (quanlist, frozenQuan, isby) { + console.log("券列表", quanlist); + if (!quanlist) return null; + if (!frozenQuan) return quanlist; + var arr = []; + for (var i = 0; i < quanlist.length; i++) { + 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 < frozenQuan.length; j++) { + var q_no = frozenQuan[j].cashRepNo; + if (Q_no == q_no) { + is_find = 1; + break; + } + } + if (!is_find) arr.push(item); + } + return arr; + }, + + /*----券的所有操作----*/ + open_coupon_list: function (e) { + var th = this; + var pickid = e.currentTarget.dataset.pickid; + var bn = e.currentTarget.dataset.bn; + var cindx = e.currentTarget.dataset.cind; + + if (bn == 1) { + th.setData({ open_quan: 1, selected_quan_pick: pickid, disabled: 1 }); + } else { + //---多单打开券的时候,就要判断券在其他门店是否有使用--- + var quanlist = th.data.cartlist[cindx].quan_list; + var exp_type = th.data.cartlist[cindx].exp_type; + + + //对于在其他门店已经选择了的券 要判断是否显示到界面 + var t_user = th.data.using_quan[pickid]; + + for (var i in quanlist) { + quanlist[i].is_using = th.check_in_sele(quanlist[i].CashRepNo, pickid); + if (t_user && quanlist[i].CashRepNo == t_user.coupon_no) + quanlist[i].show_red = 1; + else + quanlist[i].show_red = 0; + } + + if (get_by_quan_list_cart) { + for (var i in get_by_quan_list_cart) { + get_by_quan_list_cart[i].is_using = th.check_in_sele(get_by_quan_list_cart[i].no, pickid); + if (t_user && get_by_quan_list_cart[i].no == t_user.coupon_no) + get_by_quan_list_cart[i].show_red = 1; + else + get_by_quan_list_cart[i].show_red = 0; + } + th.setData({ by_quan_list_cart: get_by_quan_list_cart }); + } else { + th.setData({ by_quan_list_cart: null }); + } + + console.log("2222222券的列表", quanlist); + 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) { + var th = this; + th.setData({ open_quan: 0, disabled: 0 }); + }, + + /*--点击选择券--*/ + sele_quan_item: function (e) { + + var ind = e.currentTarget.dataset.ind; + 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 no_use = e.currentTarget.dataset.no, 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 }); + + }, + + /*----- 点击选择包邮券 -----*/ + 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: th.is_coupon }); + return; + } + + var pickid = th.data.selected_quan_pick; //现在选择的是哪一个门店 + 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"; + var obj = {}; + obj[txt] = 1; + this.setData(obj); + } else { + txt = "by_quan_list_cart[" + ind + "].show_red"; + quan_item = th.data.by_quan_list_cart[ind]; + var obj = {}; + obj[txt] = 1; + this.setData(obj); + th.data.get_by_quan_list_cart[pickid] = JSON.parse(JSON.stringify(th.data.by_quan_list_cart)); //要把选中的弄回数组 + } + + 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; //正在使用中的券列表 + 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); + 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 { + th.calculatePrice(); + } + th.setData({ open_quan: 0 }); + return; + } + } + }, + + //----把券插入之后的操作,同时还要重新计算价格---- + insert_into_using_quan: async function (item, using_quan, pickid, isby) { + + + var th = this; + var old_quan = null; + 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 { + if (using_quan[pickid]) old_quan = using_quan[pickid]; + 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(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 + }) + + }); + } else { + th.calculatePrice(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 + }) + }); + } + th.setData({ open_quan: 0 }); + }, + + + + }); diff --git a/packageE/pages/cart/cart2_pt/cart2_pt.wxml b/packageE/pages/cart/cart2_pt/cart2_pt.wxml index d67ded0..2cd0b09 100644 --- a/packageE/pages/cart/cart2_pt/cart2_pt.wxml +++ b/packageE/pages/cart/cart2_pt/cart2_pt.wxml @@ -1,4 +1,5 @@ +
@@ -101,6 +102,24 @@ {{order.store_prom}} + + + + @@ -186,6 +205,12 @@ 配送费用 ¥ {{formData.shipping_price}}元 + + + 使用优惠券 + - ¥ {{formData.coupon_price}}元 + + 使用预存 @@ -256,4 +281,128 @@ - \ No newline at end of file + + + + + + + + + + + + 优惠券使用 + + + × + + + + 可使用的优惠券 + 不使用优惠券 + + Γ + + + + + + + + + + + + + + + + + + + {{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):'不限'}} + + + + Γ + + + + + + + + + + + + + + + + + + + + + + 确定 + + + \ No newline at end of file diff --git a/packageE/pages/cart/cart2_pt/cart2_pt.wxss b/packageE/pages/cart/cart2_pt/cart2_pt.wxss index 24414fd..1a9f2f1 100644 --- a/packageE/pages/cart/cart2_pt/cart2_pt.wxss +++ b/packageE/pages/cart/cart2_pt/cart2_pt.wxss @@ -1,3 +1,5 @@ +/*@import "../cart2/cart2.wxss";*/ + .bdr_t-14 { border-top-left-radius: 14rpx; border-top-right-radius: 14rpx; diff --git a/packageE/pages/cart/cart_wk/cart_wk.js b/packageE/pages/cart/cart_wk/cart_wk.js index d121275..ae84794 100644 --- a/packageE/pages/cart/cart_wk/cart_wk.js +++ b/packageE/pages/cart/cart_wk/cart_wk.js @@ -1,6 +1,6 @@ // pages/cart/cart_wk/cart_wk.js var t = getApp(), - oo = t.globalData.setting, + oo = t.globalData.setting,app=t, os=oo; var ut=require("../../../../utils/util.js"); var util_pay=require("../../../../utils/pay.js"); @@ -53,8 +53,21 @@ Page({ paying:0, //支付中 same_ok:1, //同城配送的控制 formData:{ - order_prom_amount:0 - } + order_prom_amount:0, + coupon_price:0 + }, + + //--更优惠券抵用有关,立即购买的,如果是购物车,就要把相应的值,写入cartlist数组中-- + ckeck_quan_price: 0, + check_quan_price_list: '', + check_quan_ware_list: '', + + // 设计一个数组来存放已经选择了的券编号,coupon_no是券号,money是面值,coupon_price是真正优惠的价格,数组的下标是pickid + //using_quan[11]={coupon_no:"1212121",money:"20",coupon_price:"45"} + using_quan: {}, + isget_by_quan: {}, //是否调用了接口获取包邮券 + is_by:{}, + get_by_quan_list: null, //立即购买的 }, @@ -154,13 +167,8 @@ Page({ user_addr: addr, enterAddressPage: 0,same_ok:1 }); } - - if (th.data.exp_type == 0 && th.data.goods) { - th.calculate_wuliu(); - } - - if (th.data.exp_type == 2 && th.data.goods) { - th.calculate_same_city(); + if (th.data.goods) { + th.calculatePrice2(); } }) @@ -361,7 +369,7 @@ Page({ if (!goods) return false; - if(goods.is_minishop==1 && getApp().is_sp_hao()){ + if(goods.is_minishop==1 && getApp().is_sp_hao()){ if(goods.distr_type==1 || pickup.distr_type==1) { wx.showToast({ @@ -423,7 +431,6 @@ Page({ } - order.order_goods = order_goods; //-- 计算获得佣金的金额 -- @@ -446,12 +453,23 @@ Page({ } + if(teamlist.is_quan){ + let q_ch_money= parseFloat(price * order_goods.goods_num).toFixed(2); + th.data.ckeck_quan_price = q_ch_money; + th.data.check_quan_price_list = q_ch_money + ""; + th.data.check_quan_ware_list = goods.erpwareid + ""; + }else{ + goods.is_xz_yh = 1; + } + + this.setData({ order: order, distr_type: distr_type, pickup: pickup, + bn_pick: pickup.pickup_id, exp_type: exp_type, goods: goods, teamgroup: teamgroup, @@ -460,6 +478,7 @@ Page({ //--计算价格-- th.calculatePrice2(); + th.get_buy_now_quan(); }, @@ -469,6 +488,37 @@ Page({ th.setData({submit: 1}) var allpice = th.data.order.order_amount + th.data.order.user_money + th.data.order.tail_money; + + //---如果有选择优惠券的情况下--- + 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) { + //如果是一件代发就不要找商品 + if (th.data.using_quan[bn_pick].isby != 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 && res.data.data && res.data.data.length > 0) { + quan_price = res.data.data[0].WareCashSum; + allpice=allpice-quan_price; + } + }) + } + } + + var order_prom_txt3 = "formData.coupon_price"; + th.setData({[order_prom_txt3]: quan_price}) + var o_condition = allpice; var ord_prom=null; var order_prom_amount=0; @@ -487,10 +537,10 @@ Page({ //--计算物流-- if (th.data.exp_type == 0) { - th.calculate_wuliu(); + th.calculate_wuliu(allpice); return false; }else if(th.data.exp_type == 2){ - th.calculate_same_city(); + th.calculate_same_city(allpice); return false; } else { @@ -521,6 +571,7 @@ Page({ //--订单优惠的显示-- var order_prom_txt1 = "formData.order_prom_id"; var order_prom_txt2 = "formData.order_prom_amount"; + if (order_prom_id > 0) { th.setData({[order_prom_txt1]: order_prom_id, [order_prom_txt2]: order_prom_amount}) } else { @@ -565,19 +616,10 @@ Page({ exp_type: type,same_ok:1 }); //--计算物流的值-- - if (type == 0) { - th.calculate_wuliu(); - } else if(type==1){ - var allpice = parseFloat(th.data.order.order_amount) - + parseFloat(th.data.order.user_money) - + parseFloat(th.data.order.tail_money); - allpice = allpice.toFixed(2); - this.setData({ - allpice: allpice, exp_price: 0,show_submit:1,submit:0 - }); - }else{ - th.calculate_same_city(); + if (th.data.goods) { + th.calculatePrice2(); } + }, //关闭支付 @@ -632,6 +674,18 @@ Page({ tail_pay_type: ind,//0微信支付 1余额支付 }; + //组装优惠券的钱 + if (parseFloat(th.data.formData.coupon_price) > 0) { + dd.coupon_price = th.data.formData.coupon_price; + dd.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) { + dd.coupon_no = th.data.using_quan[th.data.bn_pick].coupon_no; + dd.coupon_price = 0; + } + + if (th.data.exp_type == 0 || th.data.exp_type == 2) { var index = th.data.index; dd.shipping_code = th.data.wu_arr[index].code; @@ -774,7 +828,7 @@ Page({ }, //----计算物流的钱---- - async calculate_wuliu() { + async calculate_wuliu(p_allpice) { //让按钮变灰色 this.setData({submit: 1}); var to = getApp(), th = this; @@ -791,14 +845,54 @@ Page({ var order_prom_amount=0; //--全部金额-- var allpice = th.data.order.order_amount + th.data.order.user_money + th.data.order.pt_tail_money; + if(p_allpice) allpice=p_allpice; // if(th.data.bn_use_commission){ // allpice-=th.data.goods.use_commission; // } + var pickid=th.data.bn_pick; var o_condition=allpice; + 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 (th.data.user_addr != null && th.data.exp_type == 0 && good.is_free_shipping == 0) { + //看是不是有调用过包邮券 + if (!th.data.isget_by_quan[th.data.pickid] && good.is_xz_yh != 1) { + + //--判断要不要显示包邮券,链式调用接口,调取包邮券,已经是减了优惠的金额,见到优惠券的钱--- + getApp().request.promiseGet("/api/weshop/userfeemail/pageAndArea", { + data: { + store_id: os.stoid, + isuse: 0, + condition: o_condition, + user_id: getApp().globalData.user_id, + pageSize: 2000 + } + }).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) { + var no_goods_arr = item.goods_list.split(","); + if (ut.isContained(no_goods_arr, gd_arr_list)) continue; //如果是不包邮商品 + } + arr.push(item); + } + if (arr) { + th.setData({ get_by_quan_list: arr }); + } + th.data.isget_by_quan[th.data.bn_pick] = 1; + } + }) + } + //订单促销的包邮模板 和 活动的包邮模板要一起判断 if ((!ord_prom || ord_prom.is_post_temp) && th.data.bn_is_post_temp) { var user_addr = th.data.user_addr; @@ -814,98 +908,137 @@ Page({ }); } - var cut_good_weight = 0; - for (let i in gd_arr_list) { - let item = gd_arr_list[i]; - if (back_data && back_data['is_by_all'] && (!back_data.no_free_goods || back_data.no_free_goods.indexOf(item.goods_id) == -1)) { + var is_by_quan = 0; + var quan_no_goods_arr=null; - if (item['exp_sum_type'] == 2 && back_data.weight_free > 0) { - if (goods_weight < 0) goods_weight = 0; - goods_weight += item['weight'] * item['buynum']; - cut_good_weight += item['weight'] * item['buynum']; - } - if (back_data.weight_free > 0) { - out_of_weight = (back_data.weight_free * 1000) - cut_good_weight; + //如果是包邮券的时候,要看看券的情况,判断一下包邮有没有不包邮模板 + if (quan_no && th.data.using_quan[pickid].isby == 1) { + var quan = th.data.using_quan[pickid]; + if (quan.goods_list) { + quan_no_goods_arr = quan.goods_list.split(","); + } else { + is_by_quan = 1; + } + } + + //如果有包邮券的不包邮商品的时候 + if (quan_no_goods_arr) { + if (back_data && back_data.no_free_goods) { + back_data['is_by_all'] = 1; + var arr3 = back_data.no_free_goods.filter(item => { + return quan_no_goods_arr.includes(item) + }) + back_data.no_free_goods = null; + if (arr3.length) { + back_data.no_free_goods = arr3; } - continue; } + if (!back_data || !back_data.no_free_goods) { + if (!back_data) back_data = {}; + back_data['is_by_all'] = 1; + back_data['no_free_goods'] = quan_no_goods_arr; + } + } - switch (item['exp_sum_type']) { - case 1: - //统一运费 - o_shipping_price += item['uniform_exp_sum']; - break; - case 2: - if (goods_weight < 0) goods_weight = 0; - //累积商品重量 每种商品的重量 * 数量 - goods_weight += item['weight'] * item['buynum']; + if(!is_by_quan){ + var cut_good_weight = 0; + for (let i in gd_arr_list) { + let item = gd_arr_list[i]; - if (back_data && back_data.is_by_all && !back_data.no_free_goods) { - cut_good_weight += item['weight'] * item['buynum']; + if (back_data && back_data['is_by_all'] && (!back_data.no_free_goods || back_data.no_free_goods.indexOf(item.goods_id) == -1)) { + + if (item['exp_sum_type'] == 2 && back_data.weight_free > 0) { + if (goods_weight < 0) goods_weight = 0; + goods_weight += item['weight'] * item['buynum']; + cut_good_weight += item['weight'] * item['buynum']; + } if (back_data.weight_free > 0) { out_of_weight = (back_data.weight_free * 1000) - cut_good_weight; } + continue; } - break; - case 3: - if (goods_piece < 0) goods_piece = 0; - //累积商品数量 - goods_piece += item['buynum']; - break; - } - } - //如果是正值的时候 - if (out_of_weight >= 0) out_of_weight = -cut_good_weight; - else out_of_weight = -back_data.weight_free * 1000; + switch (item['exp_sum_type']) { + case 1: + //统一运费 + o_shipping_price += item['uniform_exp_sum']; + break; + case 2: + if (goods_weight < 0) goods_weight = 0; + //累积商品重量 每种商品的重量 * 数量 + goods_weight += item['weight'] * item['buynum']; + + if (back_data && back_data.is_by_all && !back_data.no_free_goods) { + cut_good_weight += item['weight'] * item['buynum']; + if (back_data.weight_free > 0) { + out_of_weight = (back_data.weight_free * 1000) - cut_good_weight; + } + } + break; + case 3: + if (goods_piece < 0) goods_piece = 0; + //累积商品数量 + goods_piece += item['buynum']; + break; + } + } - if(!th.data.wu_arr){ - wx.hideLoading(); - wx.showToast({ - title: "物流配置未启用物流公司", icon: 'none', duration: 2000 - }) - //th.setData({ show_submit:0, }); - th.setData({show_submit:1, submit: 0,same_ok:0 }) - return false; - } - var code = th.data.wu_arr[th.data.index].code; - - //--------------开始计算物流------------------ - var shipping_price = 0; - // ut.calculatewuliu(code, o_shipping_price, goods_weight, out_of_weight, - // goods_piece, th.data.user_addr, back_data, rs); - - var w_data = { - store_id: os.stoid, code: code, - o_shipping_price: o_shipping_price, - goods_weight: goods_weight, - out_of_weight: out_of_weight, goods_piece: goods_piece, - user_addr_province: th.data.user_addr.province, - user_addr_city: th.data.user_addr.city, - user_addr_district: th.data.user_addr.district, - is_by_all: back_data && back_data.is_by_all ? 1 : 0, - no_free_goods: back_data && back_data.no_free_goods && back_data.no_free_goods.length > 0 ? 1 : 0, - } + //如果是正值的时候 + if (out_of_weight >= 0) out_of_weight = -cut_good_weight; + else out_of_weight = -back_data.weight_free * 1000; + + if (!th.data.wu_arr) { + wx.hideLoading(); + wx.showToast({ + title: "物流配置未启用物流公司", icon: 'none', duration: 2000 + }) + //th.setData({ show_submit:0, }); + th.setData({show_submit: 1, submit: 0, same_ok: 0}) + return false; + } + var code = th.data.wu_arr[th.data.index].code; + + //--------------开始计算物流------------------ + var shipping_price = 0; + // ut.calculatewuliu(code, o_shipping_price, goods_weight, out_of_weight, + // goods_piece, th.data.user_addr, back_data, rs); + + var w_data = { + store_id: os.stoid, code: code, + o_shipping_price: o_shipping_price, + goods_weight: goods_weight, + out_of_weight: out_of_weight, goods_piece: goods_piece, + user_addr_province: th.data.user_addr.province, + user_addr_city: th.data.user_addr.city, + user_addr_district: th.data.user_addr.district, + is_by_all: back_data && back_data.is_by_all ? 1 : 0, + no_free_goods: back_data && back_data.no_free_goods && back_data.no_free_goods.length > 0 ? 1 : 0, + } - var is_ok = 0; - await getApp().request.promisePost('/api/weshop/order/getOrderWuLiPrice', { - data: w_data, - is_json: 1 - }).then(res => { - if (res.data.code == 0) { - shipping_price = res.data.data; - is_ok = 1; - } else { - getApp().confirmBox("计算物流错误:" + res.data.msg); - } - }) - if (!is_ok) { - th.setData({show_submit:1, submit: 0,same_ok:0 }) - wx.hideLoading(); - return false; + var is_ok = 0; + await getApp().request.promisePost('/api/weshop/order/getOrderWuLiPrice', { + data: w_data, + is_json: 1 + }).then(res => { + if (res.data.code == 0) { + shipping_price = res.data.data; + is_ok = 1; + } else { + getApp().confirmBox("计算物流错误:" + res.data.msg); + } + }) + if (!is_ok) { + th.setData({show_submit: 1, submit: 0, same_ok: 0}) + wx.hideLoading(); + return false; + } } + + + + //-- 计算一下订单促销 -- if (ord_prom) { order_prom_id = ord_prom['id']; @@ -1026,7 +1159,7 @@ Page({ }, //----计算物流的钱--- - async calculate_same_city() { + async calculate_same_city(p_allpice) { //让按钮变灰色 this.setData({submit:1}); var th = this; @@ -1039,7 +1172,9 @@ Page({ var order_prom_amount=0; //--全部金额-- - var allpice = th.data.order.order_amount + th.data.order.user_money + th.data.order.pt_tail_money; + var allpice = p_allpice; + var o_condition=p_allpice; + //-----------当地址不为空,且是物流时,计算物流费用---------- if (th.data.user_addr != null) { @@ -1145,7 +1280,7 @@ Page({ } else { - var allpice = th.data.order.order_amount + th.data.order.user_money + th.data.order.tail_money; + //-- 计算一下订单促销 -- if (ord_prom) { @@ -1339,6 +1474,397 @@ Page({ var th = this; th.setData({bn_use_commission: !th.data.bn_use_commission}); th.calculatePrice2(); - } + }, + + //------ 获取立即购买的购物车的劵 -------- + get_buy_now_quan: function () { + var quanlist = null, th = this, frozenQuan = null; + var good = this.data.goods; + + //一件代发商品不使用优惠券 + if (good.whsle_id) return false; + if(!th.data.check_quan_ware_list) return false; + + //--如果商家后台没有限制使用优惠券,同时商品的优惠活动没有限制使用优惠券-- + if (th.data.is_close_quan != 1 && good.is_xz_yh != 1 && th.data.check_quan_ware_list) { + 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; + th.data.frozenQuan = frozenQuan; + } + app.request.time_limit_get(6, url, { + data: { + storeId: oo.stoid, + userId: app.globalData.user_id, + BuySum: th.data.ckeck_quan_price, + WareIds: encodeURIComponent(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 }) + } + } + } + }) + }) + } + }, + + //--验证是否已经冻结-- + check_is_frozenQuan: function (quanlist, frozenQuan, isby) { + console.log("券列表", quanlist); + if (!quanlist) return null; + if (!frozenQuan) return quanlist; + var arr = []; + for (var i = 0; i < quanlist.length; i++) { + 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 < frozenQuan.length; j++) { + var q_no = frozenQuan[j].cashRepNo; + if (Q_no == q_no) { + is_find = 1; + break; + } + } + if (!is_find) arr.push(item); + } + return arr; + }, + + /*----券的所有操作----*/ + open_coupon_list: function (e) { + var th = this; + var pickid = e.currentTarget.dataset.pickid; + var bn = e.currentTarget.dataset.bn; + var cindx = e.currentTarget.dataset.cind; + + if (bn == 1) { + th.setData({ open_quan: 1, selected_quan_pick: pickid, disabled: 1 }); + } else { + //---多单打开券的时候,就要判断券在其他门店是否有使用--- + var quanlist = th.data.cartlist[cindx].quan_list; + var exp_type = th.data.cartlist[cindx].exp_type; + + + //对于在其他门店已经选择了的券 要判断是否显示到界面 + var t_user = th.data.using_quan[pickid]; + + for (var i in quanlist) { + quanlist[i].is_using = th.check_in_sele(quanlist[i].CashRepNo, pickid); + if (t_user && quanlist[i].CashRepNo == t_user.coupon_no) + quanlist[i].show_red = 1; + else + quanlist[i].show_red = 0; + } + + if (get_by_quan_list_cart) { + for (var i in get_by_quan_list_cart) { + get_by_quan_list_cart[i].is_using = th.check_in_sele(get_by_quan_list_cart[i].no, pickid); + if (t_user && get_by_quan_list_cart[i].no == t_user.coupon_no) + get_by_quan_list_cart[i].show_red = 1; + else + get_by_quan_list_cart[i].show_red = 0; + } + th.setData({ by_quan_list_cart: get_by_quan_list_cart }); + } else { + th.setData({ by_quan_list_cart: null }); + } + + console.log("2222222券的列表", quanlist); + 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) { + var th = this; + th.setData({ open_quan: 0, disabled: 0 }); + }, + + /*--点击选择券--*/ + sele_quan_item: function (e) { + + var ind = e.currentTarget.dataset.ind; + 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 no_use = e.currentTarget.dataset.no, 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 }); + + }, + + /*----- 点击选择包邮券 -----*/ + 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 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 = e.currentTarget.dataset.ind; + //--如果是立即购买的部分-- + 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 }); + }, + + //--确认使用券--- + confirm_quan: 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); + 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 }); + th.calculatePrice2(); + th.setData({ open_quan: 0 }); + return; + } + } + }, + + //----把券插入之后的操作,同时还要重新计算价格---- + insert_into_using_quan: async function (item, using_quan, pickid, isby) { + + + var th = this; + var old_quan = null; + 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 { + if (using_quan[pickid]) old_quan = using_quan[pickid]; + 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 }); + + 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 + }) + + }); + + th.setData({ open_quan: 0 }); + }, + + + }) \ No newline at end of file diff --git a/packageE/pages/cart/cart_wk/cart_wk.wxml b/packageE/pages/cart/cart_wk/cart_wk.wxml index 4c07a0b..ac8000d 100644 --- a/packageE/pages/cart/cart_wk/cart_wk.wxml +++ b/packageE/pages/cart/cart_wk/cart_wk.wxml @@ -1,4 +1,5 @@ + @@ -67,6 +68,23 @@ + + + 选择物流: @@ -103,6 +121,14 @@ ¥{{order.tail_money}} + + + 使用优惠券 + + - ¥ {{formData.coupon_price}}元 + + + 配送费用 @@ -134,7 +160,7 @@ 支付合计: ¥{{filters.toFix(order.tail_money+exp_price,2)}} --> - 支付合计:¥{{filters.toFix(order.tail_money+exp_price-(bn_use_commission?goods.use_commission:0)-(formData.order_prom_amount?formData.order_prom_amount:0) ,2)}} + 支付合计:¥{{filters.toFix(order.tail_money+exp_price-formData.coupon_price-(bn_use_commission?goods.use_commission:0)-(formData.order_prom_amount?formData.order_prom_amount:0) ,2)}} 支付尾款 @@ -201,3 +227,121 @@ + + + + + + + + 优惠券使用 + + + × + + + + 可使用的优惠券 + 不使用优惠券 + + Γ + + + + + + + + + + + + + + + + + + + {{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):'不限'}} + + + + Γ + + + + + + + + + + + + + + + + + + + 确定 + + + diff --git a/packageE/pages/cart/cart_wk/cart_wk.wxss b/packageE/pages/cart/cart_wk/cart_wk.wxss index bd6b927..8b1375a 100644 --- a/packageE/pages/cart/cart_wk/cart_wk.wxss +++ b/packageE/pages/cart/cart_wk/cart_wk.wxss @@ -1,3 +1,5 @@ +@import "../cart2/cart2.wxss"; + page{ color: #333;} .bdr_t-14 { border-top-left-radius: 14rpx; diff --git a/packageE/pages/user/monthgiftbag/giftpackbuy/giftpackbuy.wxss b/packageE/pages/user/monthgiftbag/giftpackbuy/giftpackbuy.wxss index 660b7da..cd06d37 100644 --- a/packageE/pages/user/monthgiftbag/giftpackbuy/giftpackbuy.wxss +++ b/packageE/pages/user/monthgiftbag/giftpackbuy/giftpackbuy.wxss @@ -168,6 +168,7 @@ page { background: #d41c34; color: #fff; border-radius: 10rpx; + font-size:25rpx; } .foot_box { diff --git a/packageE/pages/user/monthgiftbag/giftpacklist/giftpacklist.js b/packageE/pages/user/monthgiftbag/giftpacklist/giftpacklist.js index 2b68e58..449040a 100644 --- a/packageE/pages/user/monthgiftbag/giftpacklist/giftpacklist.js +++ b/packageE/pages/user/monthgiftbag/giftpacklist/giftpacklist.js @@ -609,8 +609,9 @@ Page({ }, "put" ) - }, + + //界面跳转 goto: function (e) { var th = this; diff --git a/packageE/pages/user/monthgiftbag/giftpacklist/giftpacklist.wxml b/packageE/pages/user/monthgiftbag/giftpacklist/giftpacklist.wxml index a63526c..c1ccd4b 100644 --- a/packageE/pages/user/monthgiftbag/giftpacklist/giftpacklist.wxml +++ b/packageE/pages/user/monthgiftbag/giftpacklist/giftpacklist.wxml @@ -152,7 +152,34 @@ - + + + + + + + 无核销商品 + + + + + 兑换未开始 + + + 立即使用 + + + 商品已核销 + + + 商品兑换时间已过 + + + + + + + - - - - - 无核销商品 - - - - - 兑换未开始 - - - 立即使用 - - - 商品已核销 - - - 商品兑换时间已过 - - - - + + + diff --git a/packageE/pages/user/monthgiftbag/monthgiftbag.js b/packageE/pages/user/monthgiftbag/monthgiftbag.js index dff32bc..ab6ffa9 100644 --- a/packageE/pages/user/monthgiftbag/monthgiftbag.js +++ b/packageE/pages/user/monthgiftbag/monthgiftbag.js @@ -3,9 +3,11 @@ var e = getApp(), a = e.globalData.setting, os = a, t = e.request, - d = e.globalData; + d = e.globalData,ut=i; + Page({ data: { + url: a.url, //接口网址 iurl: a.imghost, //图片前缀网址 getDate: "", getStorageID: '', @@ -118,7 +120,8 @@ Page({ user_id: th.data.getUserID, //用户ID page: th.data.curpage, pageSize: th.data.pageSize, - pay_state:1 + pay_state:1, + isdetail:1 }; if(this.data.sear_key){ @@ -157,6 +160,44 @@ Page({ // arr2[j].virtualsales=arr2[j].virtualSales // arr2[j].lbnum=arr2[j].lbNum + + + + if(!arr2[j].receive_ordersn){ + arr2[j].is_no_rev=1; + } + + arr2[j].is_detail=0; + if(arr2[j].detaillist){ + arr2[j].is_detail=1; + }else{ + continue; + } + + + + arr2[j].lbType=0; + if(arr2[j].detaillist.iswarelbtype){ + arr2[j].lbType=1; + } + //---获取日期的时间戳--- + var t_endtime = arr2[j].detaillist.endTime; + t_endtime = t_endtime.replace(/-/g, '/'); + var t_date = new Date(t_endtime) / 1000; + var t_now = ut.gettimestamp(); + + var t_starttime = arr2[j].detaillist.starTime; + t_starttime = t_starttime.replace(/-/g, '/'); + var t_sdate = new Date(t_starttime) / 1000; + + arr2[j].c_state=0 + if (arr2[j].detaillist.goodsUseState) + arr2[j].c_state=1 + else if (t_date <= t_now) + arr2[j].c_state=2 + else if (t_sdate > t_now) + arr2[j].c_state=-1 + } @@ -260,7 +301,101 @@ Page({ input_sear(e){ let value = e.detail; this.data.sear_key=value; - } + }, + + //-- 获取核销码 --- + getcode: function (e) { + var th = this; + let codeId = e.currentTarget.dataset.codeid; + let orderSn = e.currentTarget.dataset.ordersn; + var json = { + "storeId": a.stoid, + "orderSn": orderSn, + } + if (codeId && codeId !== "") { + json.id = codeId + } + var data = JSON.stringify(json); + var url = th.data.url + "/api/weshop/marketing/gift/goods/verify/code/get"; //预约接口地址 + getApp().request.json_post(url, json, + function (res) { + if (res.data.code == 0) { + th.setData({ + code: res.data.data + }) + th.code_show(); + } else { + getApp().my_warnning(res.data.msg, 0, th); + } + }, + function (res) { + + }, + "put" + ) + }, + + //显示核销码 + code_show: function (e) { + var th = this; + //--获取成功的时候-- + var no = th.data.code; + var qc_com = th.selectComponent("#qc_com"); //组件的id + var obj = { + val: no, + content: "请将二维码展示给核销员,收货更快捷" + }; + qc_com.open(obj) + }, + + getGift(e){ + var that=this; + if (that.data.islogin) { + return + } + that.setData({ + islogin:true + }) + + var record_list_id=e.currentTarget.dataset.record_list_id; + var index=e.currentTarget.dataset.index; + + var json = { + "id":record_list_id,// "记录Id", + "storeId": that.data.getStorageID, //商家Id + "userId": that.data.getUserID, //用户ID + }; + // var url ="/api/weshop/marketing/buy/receive/gift/record/insert"; + // var url ="/api/weshop/marketing/marketingMonthgiftbagRecord/createOrder"; + var url ="/api/weshop/marketing/marketingMonthgiftbagRecord/recordReceive"; + getApp().request.json_post(url, json, + function (res) { + console.log('领取礼包'); + console.log(res); + if (res.data.code == 0 && res.data.data) { + + var txt="wareCard["+index+"]is_receive"; + that.setData({ + [txt]:1 + }) + getApp().my_warnning("领取成功!", 1, that); + + } else { + that.setData({submit:0}) + getApp().my_warnning(res.data.msg, 0, that); + } + that.setData({ + islogin:false + }) + }, + function (res) { + that.setData({submit:0}) + } + ) + }, + + + }); \ No newline at end of file diff --git a/packageE/pages/user/monthgiftbag/monthgiftbag.json b/packageE/pages/user/monthgiftbag/monthgiftbag.json index 80007bc..66bbc8e 100644 --- a/packageE/pages/user/monthgiftbag/monthgiftbag.json +++ b/packageE/pages/user/monthgiftbag/monthgiftbag.json @@ -4,6 +4,7 @@ "usingComponents": { "warn": "/components/long_warn/long_warn", "my_confirm": "/components/my_confirm/my_confirm", - "lb_sear": "/components/lb_sear/lb_sear" + "lb_sear": "/components/lb_sear/lb_sear", + "qr_code": "/components/qr_code/qr_code" } } \ No newline at end of file diff --git a/packageE/pages/user/monthgiftbag/monthgiftbag.wxml b/packageE/pages/user/monthgiftbag/monthgiftbag.wxml index 2fe4634..db5585e 100644 --- a/packageE/pages/user/monthgiftbag/monthgiftbag.wxml +++ b/packageE/pages/user/monthgiftbag/monthgiftbag.wxml @@ -103,9 +103,40 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 已退款 @@ -134,4 +165,6 @@ - \ No newline at end of file + + + \ No newline at end of file diff --git a/packageE/pages/user/monthgiftbag/monthgiftbag.wxss b/packageE/pages/user/monthgiftbag/monthgiftbag.wxss index f82a934..7949b9b 100644 --- a/packageE/pages/user/monthgiftbag/monthgiftbag.wxss +++ b/packageE/pages/user/monthgiftbag/monthgiftbag.wxss @@ -184,8 +184,18 @@ background: #d41c34; color: #fff; line-height: 50rpx; + border-radius:10rpx; } + +.content_box_button button.white { + + background: #fff; + color: #666; + +} + + .foot_box { -webkit-align-content: center; align-content: center; @@ -251,3 +261,8 @@ page { .After_all .end { margin: 0rpx 15rpx; } + + +.content_box_button button.overdue{ + background: rgb(153,153,153); +} \ No newline at end of file