Jelajahi Sumber

购物车接口

chao 4 tahun lalu
induk
melakukan
8f0a1c6989

+ 1 - 1
src/main/java/com/caimei/www/controller/RedirectController.java

@@ -94,7 +94,7 @@ public class RedirectController {
         return "redirect:/flea-market/list.html";
     }
     /**
-     * 二手商品列表
+     * 二手商品发布
      */
     @GetMapping("/html/maintenance/view/secondtransactions.jsp")
     public String toFleaMarketForm() {

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

@@ -1,8 +1,10 @@
 var spiServer = $("#spiServer").val();
 var isPC = ($(window).width()>768);
 var globalUserData = '';
+var REV_TOKEN_DEV = 'X-Token';
 if(localStorage.getItem('userInfo')){
     globalUserData = JSON.parse(localStorage.getItem('userInfo'));
+    REV_TOKEN_DEV = globalUserData.token;
 }
 // 头部
 var globalHead = new Vue({
@@ -340,6 +342,33 @@ function updateUrlParam(params) {
         return url;
     }
 }
+
+function tokenAjax(type, url, params, callback){
+    $.ajax({
+        type: type,
+        url: spiServer + url,
+        xhrFields: {
+            withCredentials: true
+        },
+        data: params,
+        headers:{
+            'Content-Type':'application/json;charset=utf8',
+            'X-Token':REV_TOKEN_DEV
+        },
+        success : function (res) {
+            if(res.code === -99){
+                localStorage.removeItem('userInfo');
+                window.location.href ='/login.html';
+            }else{
+                callback(res);
+            }
+        },
+        error : function (res) {
+           alertInfo("网络连接超时,请重试!")
+        }
+    });
+}
+
 function setSearchProductList(list, userId) {//处理搜索
     var productIdArr = [];
     var resultData = [];

+ 1 - 19
src/main/resources/static/js/shopping/cart.js

@@ -29,31 +29,13 @@ var shoppingCart = new Vue({
         getCartLists: function () {
             var _self = this;
             if(this.userId ===0){return;}
-            $.getJSON("/cart/list",{userId: this.userId}).done(function (r) {
+            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.totalSize = r.data.totalSize;
                     _self.totalCount = r.data.totalCount;
                     _self.totalPrice = r.data.totalPrice;
-                    var  prosPrice =0;
-                    var productIdArr = [];
-                    var newArr=[]
-                    _self.listData.forEach(function(item,index){
-				       _self.cartList=item.cartList;
-				         if(item.count==item.cartList.length){
-				               _self.totalPeice(item);
-				         }
-				        //  _self.cartList.map(function (pros) {
-                        //     // 0公开价格 1不公开价格 2仅对会员机构公开
-                        //     if (pros.priceFlag !== 1) {
-                        //         productIdArr.push(pros.id);
-                        //         newArr.push(pros)
-                        //     }
-                        // });
-			          })
-			            // setProductPrice(newArr, productIdArr.join(","), _self.userId, function () {});
-
                 }
                 _self.listLoading = false;
             });