chao 4 лет назад
Родитель
Сommit
bbda9a5bca

+ 40 - 0
src/main/resources/static/js/base.js

@@ -552,3 +552,43 @@ function dialog(txt,callback) {
         }
     });
 }
+
+// 加入购物车
+function addShoppingCart(userId, productId, count){
+    tokenAjax("post", "/shoppingCart/addCart", {
+        userID: userId,
+        productID: productId,
+        productCount: count
+    },function (res) {
+        if(res && res.code*1 === 0){
+            globalHead.getHeadCart(userId);
+            $.confirm({
+                useBootstrap: false,
+                boxWidth: (isPC?'338px':'74.6vw'),
+                title: false,
+                content:'<div class="cartAlert"><h6>商品已成功加入购物车!</h6><p>当前购物车共'+res.data+'种商品去结算继续购物</p></div>',
+                closeIcon: true,
+                animation: 'opacity',
+                closeAnimation: 'opacity',
+                animateFromElement: false,
+                scrollToPreviousElement: false,
+                buttons: {
+                    login: {
+                        text: '去结算',
+                        btnClass: 'btn-to-cart',
+                        action: function(){
+                            window.location.href = '/shopping/cart.html';
+                        }
+                    },
+                    close: {
+                        text: '继续购物',
+                        btnClass: 'btn-cancel'
+                    }
+                }
+            });
+        } else {
+            dialog("加入购物车失败!");
+        }
+    });
+}
+

+ 1 - 8
src/main/resources/static/js/product/detail.js

@@ -174,14 +174,7 @@ var productDetail = new Vue({
 				}
 			},
 		addShopCart:function(){ //加入购物车
-			var _this = this;
-            tokenAjax("post", "/shoppingCart/addCart", {
-                userID: this.userId,
-                productID: this.productId,
-                productCount: this.number
-            },function (res) {
-                alertInfo(res.msg);
-            });
+		    addShoppingCart(this.userId, this.productId, this.number);
 		},
 		Continueshop:function(){ //继续购物
             var _this = this;