|
@@ -8,6 +8,8 @@ var shoppingCart = new Vue({
|
|
|
listData: [],
|
|
|
invalidData: [],
|
|
|
promotionsList: [],
|
|
|
+ totalCouponList:[], // 优惠券算列表
|
|
|
+ eligibleCoupons:[], // 最终需要用到优惠券
|
|
|
kindCount: 0,
|
|
|
totalCount: 0,
|
|
|
totalPrice: 0,
|
|
@@ -16,89 +18,20 @@ var shoppingCart = new Vue({
|
|
|
allChecked: true,
|
|
|
submitIds: [],//去结算商品Ids
|
|
|
isShowPopup:false,
|
|
|
- currentTab:0,
|
|
|
- dataList:[
|
|
|
- {
|
|
|
- maxMoney:5000,
|
|
|
- minMoney:1000,
|
|
|
- couponType:1,
|
|
|
- couponTime:'2021.06.28~2021.07.28',
|
|
|
- couponText:'华熙生物技术有限公司',
|
|
|
- useType:1,
|
|
|
- couponBtnType:0,
|
|
|
- status:0,
|
|
|
- },
|
|
|
- {
|
|
|
- maxMoney:2000,
|
|
|
- minMoney:200,
|
|
|
- couponType:2,
|
|
|
- couponTime:'2021.06.28~2021.07.28',
|
|
|
- couponText:'华熙生物技术有限公司',
|
|
|
- useType:2,
|
|
|
- couponBtnType:0,
|
|
|
- status:1,
|
|
|
- },
|
|
|
- {
|
|
|
- maxMoney:4000,
|
|
|
- minMoney:800,
|
|
|
- couponType:3,
|
|
|
- couponTime:'2021.06.28~2021.07.28',
|
|
|
- couponText:'华熙生物技术有限公司',
|
|
|
- useType:3,
|
|
|
- couponBtnType:0,
|
|
|
- status:2,
|
|
|
- },
|
|
|
- {
|
|
|
- maxMoney:6000,
|
|
|
- minMoney:1000,
|
|
|
- couponType:4,
|
|
|
- couponTime:'2021.06.28~2021.07.28',
|
|
|
- couponText:'华熙生物技术有限公司',
|
|
|
- useType:1,
|
|
|
- couponBtnType:0,
|
|
|
- status:0,
|
|
|
- },
|
|
|
- {
|
|
|
- maxMoney:6000,
|
|
|
- minMoney:1000,
|
|
|
- couponType:4,
|
|
|
- couponTime:'2021.06.28~2021.07.28',
|
|
|
- couponText:'华熙生物技术有限公司',
|
|
|
- useType:1,
|
|
|
- couponBtnType:0,
|
|
|
- status:0,
|
|
|
- },
|
|
|
- {
|
|
|
- maxMoney:6000,
|
|
|
- minMoney:1000,
|
|
|
- couponType:4,
|
|
|
- couponTime:'2021.06.28~2021.07.28',
|
|
|
- couponText:'华熙生物技术有限公司',
|
|
|
- useType:1,
|
|
|
- couponBtnType:0,
|
|
|
- status:1,
|
|
|
- },
|
|
|
- {
|
|
|
- maxMoney:6000,
|
|
|
- minMoney:1000,
|
|
|
- couponType:4,
|
|
|
- couponTime:'2021.06.28~2021.07.28',
|
|
|
- couponText:'华熙生物技术有限公司',
|
|
|
- useType:1,
|
|
|
- couponBtnType:0,
|
|
|
- status:2,
|
|
|
- },
|
|
|
- {
|
|
|
- maxMoney:6000,
|
|
|
- minMoney:1000,
|
|
|
- couponType:5,
|
|
|
- couponTime:'2021.06.28~2021.07.28',
|
|
|
- couponText:'华熙生物技术有限公司',
|
|
|
- useType:2,
|
|
|
- couponBtnType:0,
|
|
|
- status:1,
|
|
|
- }
|
|
|
- ],
|
|
|
+ currentTab:1,
|
|
|
+ couponParam:{// 获取弹窗优惠券领取参数
|
|
|
+ userId:0,
|
|
|
+ shopId:0,
|
|
|
+ status:1,
|
|
|
+ source:1
|
|
|
+ },
|
|
|
+ isCouponEmpty:false,
|
|
|
+ productCoupon:[], // 优惠券
|
|
|
+ productCouponList:[], // 优惠券弹窗列表
|
|
|
+ couponPrice:0, // 优惠金额
|
|
|
+ totalDiscountAmount:0, // 总共减去金额
|
|
|
+ isDiscount:false, // 控制显示优惠明细
|
|
|
+
|
|
|
},
|
|
|
watch:{
|
|
|
listData: {
|
|
@@ -115,49 +48,38 @@ var shoppingCart = new Vue({
|
|
|
},
|
|
|
TypeFormat:function(value) {
|
|
|
switch (value) {
|
|
|
- case 1:
|
|
|
+ case 0:
|
|
|
return '活动券';
|
|
|
break;
|
|
|
- case 2:
|
|
|
+ case 1:
|
|
|
return '品类券';
|
|
|
break;
|
|
|
+ case 2:
|
|
|
+ return '用户专享券';
|
|
|
+ break;
|
|
|
case 3:
|
|
|
return '店铺券';
|
|
|
break;
|
|
|
case 4:
|
|
|
- return '专享券';
|
|
|
- break;
|
|
|
- case 5:
|
|
|
return '新用户券';
|
|
|
break;
|
|
|
}
|
|
|
- },
|
|
|
- TypeFormatText:function(value) {
|
|
|
- switch (value) {
|
|
|
- case 1:
|
|
|
- return '全商城商品通用';
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- return '仅限购买仪器类商品';
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- return '仅可购买店铺';
|
|
|
- break;
|
|
|
- }
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
getCartLists: function () {
|
|
|
var _self = this;
|
|
|
if(this.userId ===0){return;}
|
|
|
- tokenAjax("get", "/shoppingCart/list", {userId: this.userId},function (r) {
|
|
|
- if (r.code === 0 && r.data) {
|
|
|
- _self.listData = r.data.list;
|
|
|
- _self.invalidData = r.data.invalid;
|
|
|
- _self.kindCount = r.data.kindCount;
|
|
|
- _self.totalCount = r.data.totalCount;
|
|
|
- _self.totalPrice = r.data.totalPrice;
|
|
|
- _self.promotionsList = r.data.promotions;
|
|
|
+ ShoppingApi.QueryShoppingCartList({userId: this.userId},function(response){
|
|
|
+ if(response.code === 0){
|
|
|
+ var data = response.data;
|
|
|
+ _self.listData = data.list;
|
|
|
+ _self.invalidData = data.invalid;
|
|
|
+ _self.kindCount = data.kindCount;
|
|
|
+ _self.totalCount = data.totalCount;
|
|
|
+ _self.totalPrice = data.totalPrice;
|
|
|
+ _self.promotionsList = data.promotions;
|
|
|
+ _self.totalCouponList = data.couponList
|
|
|
// 默认全选
|
|
|
_self.listData.forEach(function(supplier){
|
|
|
supplier.checked = true;
|
|
@@ -169,9 +91,11 @@ var shoppingCart = new Vue({
|
|
|
});
|
|
|
_self.allChecked = true;
|
|
|
_self.computedPrice();
|
|
|
+ _self.listLoading = false;
|
|
|
+ }else{
|
|
|
+ CAIMEI.Alert(response.msg,'确定',true, function(){});
|
|
|
}
|
|
|
- _self.listLoading = false;
|
|
|
- });
|
|
|
+ })
|
|
|
},
|
|
|
toggleThisLadder: function(event){
|
|
|
var el = event.currentTarget;
|
|
@@ -318,7 +242,77 @@ var shoppingCart = new Vue({
|
|
|
_self.originalPrice = originalPrice;
|
|
|
_self.kindCount = kindCount;
|
|
|
_self.totalCount = totalCount;
|
|
|
+ // 计算优惠券
|
|
|
+ if(_self.totalCouponList.length>0){
|
|
|
+ _self.calculationCoupon();
|
|
|
+ }
|
|
|
+ // 最后满减金额 = 店铺减去金额 + 单品减去金额 + 凑单减去金额
|
|
|
+ _self.totalDiscountAmount = _self.reducedPrice + _self.couponPrice;
|
|
|
+ console.log('totalDiscountAmount',_self.totalDiscountAmount);
|
|
|
+ // 控制显示优惠明细
|
|
|
+ if(_self.totalDiscountAmount > 0 ){
|
|
|
+ _self.isDiscount = true;
|
|
|
+ }else{
|
|
|
+ _self.isDiscount = false;
|
|
|
+ }
|
|
|
});
|
|
|
+
|
|
|
+ },
|
|
|
+ calculationCoupon:function(){// 优惠券计算
|
|
|
+ var _self = this;
|
|
|
+ var eligibleCoupons = [];
|
|
|
+ _self.listData.forEach(function(shop,index){
|
|
|
+ shop.cartList.forEach(function(pros){
|
|
|
+ if(_self.submitIds.includes(pros.productId*1)){
|
|
|
+ _self.totalCouponList.map(function (coupon,index){//循环优惠券
|
|
|
+ var couponType = coupon.couponType;
|
|
|
+ if(couponType == 0){// 活动券
|
|
|
+ if(coupon.productType == 1){// 活动券-全商城商品
|
|
|
+ if(_self.totalPrice>=coupon.touchPrice){
|
|
|
+ eligibleCoupons.push(coupon)
|
|
|
+ eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
+ }
|
|
|
+ }else if(coupon.productType == 2){// 活动券-指定商品
|
|
|
+ if(coupon.productIds && coupon.productIds.includes(pros.productId)){
|
|
|
+ if(_self.totalPrice>=coupon.touchPrice){
|
|
|
+ eligibleCoupons.push(coupon)
|
|
|
+ eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 品类券适用于产品或者仪器,购买产品类或仪器类的商品,商品金额达到优惠标准即可使用优惠券
|
|
|
+ }else if(couponType == 1){// 品类券 categoryType(commodityType) : 1 产品 2 仪器
|
|
|
+ if( coupon.categoryType && coupon.categoryType == pros.commodityType){
|
|
|
+ if(_self.totalPrice>=coupon.touchPrice){
|
|
|
+ eligibleCoupons.push(coupon)
|
|
|
+ eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 适用于商城全部商品
|
|
|
+ }else if(couponType == 2 || couponType == 4){// 用户专享券和新用户券
|
|
|
+ if(_self.totalPrice>=coupon.touchPrice){
|
|
|
+ eligibleCoupons.push(coupon)
|
|
|
+ eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
+ }
|
|
|
+ // 店铺券适用于某个供应商的全部商品
|
|
|
+ }else if(couponType == 3){// 店铺券 supplierId
|
|
|
+ if(coupon.shopId && pros.supplierId == coupon.shopId){
|
|
|
+ if(_self.totalPrice>=coupon.touchPrice){
|
|
|
+ eligibleCoupons.push(coupon)
|
|
|
+ eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ if(eligibleCoupons.length>0){
|
|
|
+ _self.eligibleCoupons.push(eligibleCoupons[0])
|
|
|
+ _self.couponPrice = _self.eligibleCoupons.sort((a,b)=> b.couponAmount - a.couponAmount)[0].couponAmount
|
|
|
+ }
|
|
|
},
|
|
|
cartNumberSub: function(cart){
|
|
|
cart.number -= cart.step;
|
|
@@ -358,13 +352,13 @@ var shoppingCart = new Vue({
|
|
|
});
|
|
|
},
|
|
|
updateCart: function(cart){
|
|
|
- tokenAjax("post", "/shoppingCart/update", {
|
|
|
- userID: this.userId,
|
|
|
- productID: cart.productId,
|
|
|
- productCount: cart.number
|
|
|
- },function (res) {
|
|
|
- console.log(res);
|
|
|
- });
|
|
|
+ ShoppingApi.ShoppingCartUpdate({userID:_self.userId,productID: cart.productId,productCount: cart.number},function(response){
|
|
|
+ if(response.code === 0){
|
|
|
+ console.log('更新购物车商品数量成功');
|
|
|
+ }else{
|
|
|
+ CAIMEI.Alert(response.msg,'确定',true, function(){});
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
deleteCart: function(productIds){
|
|
|
var _self = this;
|
|
@@ -413,12 +407,51 @@ var shoppingCart = new Vue({
|
|
|
window.location.href = '/shopping/confirm.html?type=1';
|
|
|
}
|
|
|
},
|
|
|
+ queryPopupCoupons:function(){// 获取弹窗优惠券列表
|
|
|
+ var _self = this;
|
|
|
+ ShoppingApi.ShoppingCartGetCoupon(_self.couponParam, function (response) {
|
|
|
+ if(response.code == 0){
|
|
|
+ var data = response.data;
|
|
|
+ if(data.couponList && data.couponList.length >0){
|
|
|
+ _self.productCouponList = data.couponList;
|
|
|
+ _self.isCouponEmpty = false;
|
|
|
+ console.log('有优惠券')
|
|
|
+ console.log(_self.productCouponList)
|
|
|
+ }else{
|
|
|
+ console.log('没有优惠券')
|
|
|
+ _self.isCouponEmpty = true;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ console.log('获取优惠券列表失败')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ receiveCoupon:function(coupon){// 点击领取优惠券
|
|
|
+ var _self = this;
|
|
|
+ ProductApi.ReceiveCoupon({userId:_self.couponParam.userId, couponId:coupon.couponId, source:1}, function (response) {
|
|
|
+ if(response.code == 0){
|
|
|
+ CAIMEI.dialog('领取成功',true,function () {
|
|
|
+ _self.currentTab = 2;
|
|
|
+ _self.couponParam.status = 2;
|
|
|
+ _self.queryPopupCoupons();
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ CAIMEI.Alert(response.msg, '确定', false);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
queryCouponTabs:function (value){
|
|
|
var _self = this;
|
|
|
- _self.currentTab = value;
|
|
|
+ _self.currentTab = _self.couponParam.status = value;
|
|
|
+ _self.queryPopupCoupons();
|
|
|
},
|
|
|
- showPopup:function(){// 显示优惠券弹窗
|
|
|
+ showPopup:function(shop){// 显示优惠券弹窗
|
|
|
var _self = this;
|
|
|
+ _self.productCouponList = [];
|
|
|
+ _self.currentTab = 1;
|
|
|
+ _self.couponParam.status = 1;
|
|
|
+ _self.couponParam.shopId = shop.id
|
|
|
+ _self.queryPopupCoupons();
|
|
|
_self.isShowPopup = true;
|
|
|
},
|
|
|
hidePopup:function(){// 隐藏优惠券弹窗
|
|
@@ -428,7 +461,7 @@ var shoppingCart = new Vue({
|
|
|
},
|
|
|
created: function () {
|
|
|
if(globalUserData){
|
|
|
- this.userId = globalUserData.userId;
|
|
|
+ this.userId = this.couponParam.userId = globalUserData.userId;
|
|
|
this.userIdentity = globalUserData.identity;
|
|
|
this.userToken = globalUserData.token;
|
|
|
}
|